diff --git a/README.md b/README.md index 8003aa3..5ffae16 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ ESP32 libraries: - [WiFi.h](https://github.com/espressif/arduino-esp32/tree/master/libraries/WiFi) External libraries: -- [AsyncTCP](https://github.com/me-no-dev/AsyncTCP). Async TCP Library for ESP32. - [ArduinoJson](https://arduinojson.org). JSON library for embedded C++. +- [AsyncTCP](https://github.com/me-no-dev/AsyncTCP). Async TCP Library for ESP32. - [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer). Async HTTP and WebSocket Server. ## Usage diff --git a/src/webserver.ino b/src/webserver.ino index 7b54fc0..684c4d8 100644 --- a/src/webserver.ino +++ b/src/webserver.ino @@ -28,18 +28,7 @@ AsyncWebSocket g_ws("/ws"); static unsigned long g_lastUpdate = millis(); -void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){ - if(type == WS_EVT_CONNECT) - { - Serial.println("Websocket client connection received"); - } - else if(type == WS_EVT_DISCONNECT) - { - Serial.println("Client disconnected"); - } - else if(type == WS_EVT_DATA) - Serial.println("Data received: "); -} +void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len); void setup() { @@ -64,6 +53,7 @@ void setup() /** * @brief Server setup. */ + g_server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", MAIN_page); }); @@ -105,4 +95,25 @@ void loop() g_ws.cleanupClients(); } -} \ No newline at end of file +} + +void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) +{ + if(type == WS_EVT_CONNECT) + { + Serial.println("Websocket client connection received"); + } + else if(type == WS_EVT_DISCONNECT) + { + Serial.println("Client disconnected"); + } + else if(type == WS_EVT_DATA) + { + Serial.println("Data received: "); + for(int i=0; i < len; i++) + { + Serial.print((char) data[i]); + } + Serial.println(); + } +}