2018-11-19 17:00:52 +01:00
|
|
|
#include <WiFi.h>
|
|
|
|
#include <WiFiClient.h>
|
|
|
|
#include <WebServer.h>
|
|
|
|
#include <ESPmDNS.h>
|
|
|
|
|
2020-01-20 14:21:01 +01:00
|
|
|
#include <uri/UriBraces.h>
|
|
|
|
#include <uri/UriRegex.h>
|
|
|
|
|
2018-11-19 17:00:52 +01:00
|
|
|
const char *ssid = "........";
|
|
|
|
const char *password = "........";
|
|
|
|
|
|
|
|
WebServer server(80);
|
|
|
|
|
|
|
|
void setup(void) {
|
|
|
|
Serial.begin(9600);
|
|
|
|
WiFi.mode(WIFI_STA);
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
// Wait for connection
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
Serial.print("Connected to ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
Serial.print("IP address: ");
|
|
|
|
Serial.println(WiFi.localIP());
|
|
|
|
|
|
|
|
if (MDNS.begin("esp32")) {
|
|
|
|
Serial.println("MDNS responder started");
|
|
|
|
}
|
|
|
|
|
2020-10-19 16:20:49 +02:00
|
|
|
server.on(F("/"), []() {
|
2018-11-19 17:00:52 +01:00
|
|
|
server.send(200, "text/plain", "hello from esp32!");
|
|
|
|
});
|
|
|
|
|
2020-01-20 14:21:01 +01:00
|
|
|
server.on(UriBraces("/users/{}"), []() {
|
2018-11-19 17:00:52 +01:00
|
|
|
String user = server.pathArg(0);
|
|
|
|
server.send(200, "text/plain", "User: '" + user + "'");
|
|
|
|
});
|
|
|
|
|
2020-01-20 14:21:01 +01:00
|
|
|
server.on(UriRegex("^\\/users\\/([0-9]+)\\/devices\\/([0-9]+)$"), []() {
|
2018-11-19 17:00:52 +01:00
|
|
|
String user = server.pathArg(0);
|
|
|
|
String device = server.pathArg(1);
|
|
|
|
server.send(200, "text/plain", "User: '" + user + "' and Device: '" + device + "'");
|
|
|
|
});
|
|
|
|
|
|
|
|
server.begin();
|
|
|
|
Serial.println("HTTP server started");
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop(void) {
|
|
|
|
server.handleClient();
|
|
|
|
}
|