Browse Source

Add wifi buttons

main
Hendrik Langer 8 years ago
parent
commit
1c4f1c9f8d
  1. 42
      src/wifi.cpp

42
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<!DOCTYPE HTML>\r\n<html>Hello from ESP32 at ";
s += ipStr;
s += "</html>\r\n\r\n";
s = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<!DOCTYPE HTML>\r\n"
"<html>\r\n";
s += "<h1>Hello from ESP32 at " + ipStr + "</h1>\r\n";
s += "<p><a href=\"sound/1\"><button>1</button></a>"
"<a href=\"sound/2\"><button>2</button></a>"
"<a href=\"sound/3\"><button>3</button></a></p>"
"<p><a href=\"sound/4\"><button>4</button></a>"
"<a href=\"sound/5\"><button>5</button></a>"
"<a href=\"sound/6\"><button>6</button></a></p>"
"<p><a href=\"sound/7\"><button>7</button></a>"
"<a href=\"sound/8\"><button>8</button></a>"
"<a href=\"sound/9\"><button>9</button></a></p>"
"</html>\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");
}

Loading…
Cancel
Save