websocket
This commit is contained in:
parent
ff14910c89
commit
0e93eafb7e
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
|
AsyncWebSocket ws("/ws");
|
||||||
|
|
||||||
void httpIndex(AsyncWebServerRequest *request) {
|
void httpIndex(AsyncWebServerRequest *request) {
|
||||||
info(request->url().c_str());
|
info(request->url().c_str());
|
||||||
request->send(LittleFS, "/index.html", "text/html");
|
request->send(LittleFS, "/index.html", "text/html");
|
||||||
@ -54,6 +56,32 @@ void httpActionConfirm(AsyncWebServerRequest *request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void httpSetup() {
|
void httpSetup() {
|
||||||
|
ws.onEvent([](AsyncWebSocket *socket, AsyncWebSocketClient *client, AwsEventType type, void *arg, unsigned char *message, unsigned length) {
|
||||||
|
const char *t;
|
||||||
|
switch (type) {
|
||||||
|
case WS_EVT_CONNECT:
|
||||||
|
t = "CONNECT";
|
||||||
|
break;
|
||||||
|
case WS_EVT_DISCONNECT:
|
||||||
|
t = "DISCONNECT";
|
||||||
|
break;
|
||||||
|
case WS_EVT_PONG:
|
||||||
|
t = "PONG";
|
||||||
|
break;
|
||||||
|
case WS_EVT_ERROR:
|
||||||
|
t = "ERROR";
|
||||||
|
break;
|
||||||
|
case WS_EVT_DATA:
|
||||||
|
t = "DATA";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
t = "[???]";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
debug("%s: %s (%d bytes)", client->remoteIP().toString().c_str(), t, length);
|
||||||
|
});
|
||||||
|
server.addHandler(&ws);
|
||||||
|
|
||||||
server.on("/", HTTP_GET, httpIndex);
|
server.on("/", HTTP_GET, httpIndex);
|
||||||
server.on("/action/left", HTTP_GET, httpActionLeft);
|
server.on("/action/left", HTTP_GET, httpActionLeft);
|
||||||
server.on("/action/up", HTTP_GET, httpActionUp);
|
server.on("/action/up", HTTP_GET, httpActionUp);
|
||||||
@ -63,3 +91,7 @@ void httpSetup() {
|
|||||||
server.on("/action/confirm", HTTP_GET, httpActionConfirm);
|
server.on("/action/confirm", HTTP_GET, httpActionConfirm);
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void httpLoop() {
|
||||||
|
ws.cleanupClients();
|
||||||
|
}
|
||||||
|
|||||||
@ -3,4 +3,6 @@
|
|||||||
|
|
||||||
void httpSetup();
|
void httpSetup();
|
||||||
|
|
||||||
|
void httpLoop();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -18,4 +18,5 @@ void loop() {
|
|||||||
logLoop();
|
logLoop();
|
||||||
wifiLoop();
|
wifiLoop();
|
||||||
appLoop();
|
appLoop();
|
||||||
|
httpLoop();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user