From 1c4f1c9f8df2cc569e87f57a583d77961113dc72 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 25 Apr 2017 21:06:09 +0200 Subject: [PATCH] Add wifi buttons --- src/wifi.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/wifi.cpp b/src/wifi.cpp index db7900b..ebfe861 100644 --- a/src/wifi.cpp +++ b/src/wifi.cpp @@ -13,6 +13,7 @@ // ToDo: check if https://github.com/me-no-dev/ESPAsyncWebServer/ becomes available #include "hardware.h" +#include "sound.h" #include "wifi.h" @@ -93,17 +94,42 @@ void Wifi::loop() { client.flush(); String s; - if (req == "/") - { + if (req == "/") { IPAddress ip = WiFi.localIP(); String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]); - s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\nHello from ESP32 at "; - s += ipStr; - s += "\r\n\r\n"; + s = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "\r\n" + "\r\n"; + s += "

Hello from ESP32 at " + ipStr + "

\r\n"; + s += "

" + "" + "

" + "

" + "" + "

" + "

" + "" + "

" + "\r\n" + "\r\n"; Serial.println("Sending 200"); - } - else - { + } else if (req == "/test") { + Serial.println("/test"); + s = "HTTP/1.1 200 OK\r\n\r\n"; + } else if (req.startsWith("/sound/")) { + Serial.print("/sound/"); + int n = req.substring(7).toInt(); + Serial.println(n); + if (0<=n<=9) { + Sound* sound = Sound::getInstance(); + char filename[25]; + sprintf(filename, "/T%d.wav", n); + if (sound != NULL) sound->play(filename); + } + s = "HTTP/1.1 200 OK\r\n\r\n"; + } else { s = "HTTP/1.1 404 Not Found\r\n\r\n"; Serial.println("Sending 404"); }