diff --git a/ConfigSettings.cpp b/ConfigSettings.cpp index 1e52b3e..fce16ba 100644 --- a/ConfigSettings.cpp +++ b/ConfigSettings.cpp @@ -58,9 +58,8 @@ void ConfigSettings::print() { this->NTP.print(); this->WIFI.print(); } -void ConfigSettings::emitSockets() { - -} +void ConfigSettings::emitSockets() {} +void ConfigSettings::emitSockets(uint8_t num) {} bool MQTTSettings::begin() { this->load(); return true; diff --git a/ConfigSettings.h b/ConfigSettings.h index d77358a..26ef6e0 100644 --- a/ConfigSettings.h +++ b/ConfigSettings.h @@ -2,7 +2,7 @@ #ifndef configsettings_h #define configsettings_h -#define FW_VERSION "v1.0.9" +#define FW_VERSION "v1.1.0" enum DeviceStatus { DS_OK = 0, DS_ERROR = 1, @@ -78,6 +78,7 @@ class ConfigSettings: BaseSettings { bool load(); void print(); void emitSockets(); + void emitSockets(uint8_t num); bool toJSON(DynamicJsonDocument &doc); }; diff --git a/Network.cpp b/Network.cpp index f855179..8fff7ea 100644 --- a/Network.cpp +++ b/Network.cpp @@ -58,7 +58,17 @@ void Network::emitSockets() { } else sockEmit.sendToClients("wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}"); - +} +void Network::emitSockets(uint8_t num) { + if(WiFi.status() == WL_CONNECTED) { + char buf[128]; + snprintf(buf, sizeof(buf), "{\"ssid\":\"%s\",\"strength\":%d,\"channel\":%d}", WiFi.SSID(), WiFi.RSSI(), WiFi.channel()); + sockEmit.sendToClient(num, "wifiStrength", buf); + this->lastRSSI = WiFi.RSSI(); + this->lastChannel = WiFi.channel(); + } + else + sockEmit.sendToClient(num, "wifiStrength", "{\"ssid\":\"\", \"strength\":-100,\"channel\":-1}"); } void Network::setConnected() { WiFi.hostname(settings.WIFI.hostname); diff --git a/Network.h b/Network.h index cb7d1b6..37bb1de 100644 --- a/Network.h +++ b/Network.h @@ -25,6 +25,7 @@ class Network { void loop(); void end(); void emitSockets(); + void emitSockets(uint8_t num); uint32_t getChipId(); }; #endif diff --git a/Sockets.cpp b/Sockets.cpp index 2b35aad..d070d04 100644 --- a/Sockets.cpp +++ b/Sockets.cpp @@ -4,9 +4,11 @@ #include "Sockets.h" #include "ConfigSettings.h" #include "Somfy.h" +#include "Network.h" extern ConfigSettings settings; +extern Network net; extern SomfyShadeController somfy; WebSocketsServer sockServer = WebSocketsServer(8080); @@ -28,6 +30,7 @@ void SocketEmitter::startup() { } void SocketEmitter::begin() { sockServer.begin(); + sockServer.enableHeartbeat(20000, 10000, 3); sockServer.onEvent(this->wsEvent); } void SocketEmitter::loop() { @@ -57,8 +60,17 @@ void SocketEmitter::end() { sockServer.close(); } void SocketEmitter::disconnect() { sockServer.disconnect(); } void SocketEmitter::wsEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length) { switch(type) { + case WStype_ERROR: + if(length > 0) + Serial.printf("Socket Error: %s\n", payload); + else + Serial.println("Socket Error: \n"); + break; case WStype_DISCONNECTED: - Serial.printf("Socket [%u] Disconnected!\n", num); + if(length > 0) + Serial.printf("Socket [%u] Disconnected!\n [%s]", num, payload); + else + Serial.printf("Socket [%u] Disconnected!\n", num); break; case WStype_CONNECTED: { @@ -66,8 +78,9 @@ void SocketEmitter::wsEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t Serial.printf("Socket [%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); // Send all the current shade settings to the client. sockServer.sendTXT(num, "Connected"); - settings.emitSockets(); + settings.emitSockets(num); somfy.emitState(num); + net.emitSockets(num); } break; case WStype_TEXT: @@ -86,8 +99,11 @@ void SocketEmitter::wsEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t // send message to client // sockServer.sendBIN(num, payload, length); break; + case WStype_PONG: + //Serial.printf("Pong from %u\n", num); + break; case WStype_PING: - Serial.printf("Ping from %u\n", num); + //Serial.printf("Ping from %u\n", num); break; } diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 11f4815..4da0e73 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/SomfyController.littlefs.bin b/SomfyController.littlefs.bin index 6ed296c..1693477 100644 Binary files a/SomfyController.littlefs.bin and b/SomfyController.littlefs.bin differ diff --git a/data/index.html b/data/index.html index 43705be..cb937a6 100644 --- a/data/index.html +++ b/data/index.html @@ -6,39 +6,8 @@ -
+

ESPSomfy RTS