diff --git a/PrepareProject.py b/PrepareProject.py index d746f2f6..8a1c3635 100644 --- a/PrepareProject.py +++ b/PrepareProject.py @@ -134,7 +134,8 @@ else: deviceType = 'esp32*' if not 'esp32' in deviceName: deviceType = 'esp82*' - +if 'bk72' in deviceName: + deviceType = 'bk72*' # генерируем файлы проекта на основе подготовленного профиля # заполняем конфигурационный файл прошивки параметрами из профиля with open("data_svelte/settings.json", "r", encoding='utf-8') as read_file: diff --git a/data_full/build/bundle.js.gz b/data_full/build/bundle.js.gz index 24f6ab8b..105e6deb 100644 Binary files a/data_full/build/bundle.js.gz and b/data_full/build/bundle.js.gz differ diff --git a/data_svelte/build/bundle.js.gz b/data_svelte/build/bundle.js.gz index 24f6ab8b..105e6deb 100644 Binary files a/data_svelte/build/bundle.js.gz and b/data_svelte/build/bundle.js.gz differ diff --git a/include/Const.h b/include/Const.h index 1be5c5b6..bc84800d 100644 --- a/include/Const.h +++ b/include/Const.h @@ -103,6 +103,7 @@ enum TimerTask_t { TIMES, // периодические секундные проверки PTASK, ST, + PiWS, END }; diff --git a/include/Global.h b/include/Global.h index 9d5f36a5..d4a79336 100644 --- a/include/Global.h +++ b/include/Global.h @@ -162,6 +162,8 @@ extern Time_t _time_local; extern Time_t _time_utc; extern bool _time_isTrust; +#define WEBSOCKETS_CLIENT_MAX 5 +extern int8_t ws_clients[WEBSOCKETS_CLIENT_MAX]; // extern unsigned long loopPeriod; // extern DynamicJsonDocument settingsFlashJsonDoc; diff --git a/include/WsServer.h b/include/WsServer.h index eed0ac78..804bde27 100644 --- a/include/WsServer.h +++ b/include/WsServer.h @@ -19,6 +19,6 @@ void periodicWsSend(); void sendFileToWsByFrames(const String& filename, const String& header, const String& json, int client_id, size_t frameSize); void sendStringToWs(const String& header, String& payload, int client_id); - +void disconnectWSClient(uint8_t client_id); void sendDeviceList(uint8_t num); int getNumWSClients(); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 1dbb02b8..80839aa4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -381,14 +381,14 @@ build_src_filter = + ${env:esp32_16mb_fromitems.build_src_filter} -[env:tiny] +[env:bk7231n] extra_scripts = pre:tools/lt_fsbuildscript.py lib_compat_mode = off lib_deps = LT_WebSockets https://github.com/Mit4el/ESPAsyncUDP#master ${common_env_data.lib_deps_external} - ${env:tiny_fromitems.lib_deps} + ${env:bk7231n_fromitems.lib_deps} lib_ignore = EspSoftwareSerial, HTTPUpdate, WebSockets platform = https://github.com/Mit4el/libretiny#master framework = arduino @@ -411,7 +411,7 @@ build_src_filter = + + + - ${env:tiny_fromitems.build_src_filter} + ${env:bk7231n_fromitems.build_src_filter} [env:esp8266_1mb_ota_fromitems] lib_deps = @@ -882,9 +882,8 @@ build_src_filter = + + -[env:tiny_fromitems] +[env:bk7231n_fromitems] lib_deps = - plerup/EspSoftwareSerial build_src_filter = + + @@ -894,10 +893,6 @@ build_src_filter = + + + - + + - + - + - + - + + + diff --git a/src/Global.cpp b/src/Global.cpp index 7145d956..afbb6e0f 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -83,7 +83,7 @@ String prevDate = ""; bool firstTimeInit = true; // unsigned long loopPeriod; - +int8_t ws_clients[WEBSOCKETS_CLIENT_MAX]; bool isTimeSynch = false; Time_t _time_local; Time_t _time_utc; diff --git a/src/Main.cpp b/src/Main.cpp index f3c0e942..223f1470 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -110,7 +110,7 @@ void setup() { #endif // RESTART_DEBUG_INFO // Печать или оправка отладочной информации printDebugTrace(); - //startWatchDog(); + startWatchDog(); Serial.println(); Serial.println(F("--------------started----------------")); @@ -157,6 +157,19 @@ void setup() { SerialPrint("i", "i2c", F("i2c pins overriding done")); } #if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb) + esp_reset_reason_t esp_reason = esp_reset_reason(); + if (esp_reason == ESP_RST_UNKNOWN || esp_reason == ESP_RST_POWERON) + bootloop_panic_count = 0; +/* else if (bootloop_panic_count == 3 || bootloop_panic_count == 0 ) bootloop_panic_count = 1; + else if (bootloop_panic_count == 2) bootloop_panic_count = 3; + else if (bootloop_panic_count == 1) bootloop_panic_count = 2; + else bootloop_panic_count = 0; */ + Serial.println("bootloop_panic_count " + String(bootloop_panic_count)); + if (bootloop_panic_count >3 ) + { + //resetSettingsFlashByPanic(); + bootloop_panic_count = 0; + } if (bootloop_panic_count >= 3) { resetSettingsFlashByPanic(); @@ -167,7 +180,7 @@ void setup() { SerialPrint("E", "CORE", F("CONFIG and SCENARIO reset !!!")); bootloop_panic_count = 0; ESP.restart(); - } + } #endif // RESTART_DEBUG_INFO // настраиваем микроконтроллер configure("/config.json"); @@ -254,6 +267,25 @@ void setup() { }, nullptr, true); + // ловим пинги от WS (5сек) и дисконнектим если их нет (20сек) + ts.add( + PiWS, 6000, [&](void*) { + if (isNetworkActive()) { + for (size_t i = 0; i < WEBSOCKETS_CLIENT_MAX; i++) + { + if (ws_clients[i] == 0) { + disconnectWSClient(i); + ws_clients[i]=-1; + } + if (ws_clients[i] > 0) { + ws_clients[i]=0; + } + + } + } + }, + nullptr, true); + // test Serial.println("-------test start--------"); Serial.println("--------test end---------"); diff --git a/src/WsServer.cpp b/src/WsServer.cpp index a80ed967..18cfe1e4 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -7,6 +7,10 @@ void standWebSocketsInit() { standWebSocket.begin(); standWebSocket.onEvent(webSocketEvent); SerialPrint("i", "WS", "WS server initialized"); + for (size_t i = 0; i < WEBSOCKETS_CLIENT_MAX; i++) + { + ws_clients[i] = -1; + } } void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) { @@ -17,6 +21,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) case WStype_DISCONNECTED: { Serial.printf("[%u] Disconnected!\n", num); + standWebSocket.disconnect(num); } break; case WStype_CONNECTED: { @@ -54,7 +59,11 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) //----------------------------------------------------------------------// // Страница веб интерфейса dashboard //----------------------------------------------------------------------// - + if (headerStr == "p|") { + standWebSocket.sendTXT(num, "p|"); + Serial.printf("Ping client: %u\n", num); + ws_clients[num]=1; + } // публикация всех виджетов if (headerStr == "/|") { sendFileToWsByFrames("/layout.json", "layout", "", num, WEB_SOCKETS_FRAME_SIZE); @@ -490,7 +499,14 @@ void sendStringToWs(const String& header, String& payload, int client_id) { #endif } -void sendDeviceList(uint8_t num) { +void disconnectWSClient(uint8_t client_id) +{ + standWebSocket.disconnect(client_id); + Serial.printf("[WS] Client %u -disconnected\n", client_id); +} + +void sendDeviceList(uint8_t num) +{ if (jsonReadInt(settingsFlashJson, F("udps")) != 0) { // если включен автопоиск то отдаем список из оперативной памяти SerialPrint("i", "FS", "heap list"); diff --git a/src/modules/exec/AnalogBtn/modinfo.json b/src/modules/exec/AnalogBtn/modinfo.json index ca3d11d2..3b5c7940 100644 --- a/src/modules/exec/AnalogBtn/modinfo.json +++ b/src/modules/exec/AnalogBtn/modinfo.json @@ -38,6 +38,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/exec/ButtonIn/modinfo.json b/src/modules/exec/ButtonIn/modinfo.json index 07fcc87c..e9c11793 100644 --- a/src/modules/exec/ButtonIn/modinfo.json +++ b/src/modules/exec/ButtonIn/modinfo.json @@ -46,6 +46,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/exec/ButtonOut/modinfo.json b/src/modules/exec/ButtonOut/modinfo.json index d655bed9..7a033c18 100644 --- a/src/modules/exec/ButtonOut/modinfo.json +++ b/src/modules/exec/ButtonOut/modinfo.json @@ -50,6 +50,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/exec/TelegramLT/TelegramLT.cpp b/src/modules/exec/TelegramLT/TelegramLT.cpp index 44a7828d..517fa6d4 100644 --- a/src/modules/exec/TelegramLT/TelegramLT.cpp +++ b/src/modules/exec/TelegramLT/TelegramLT.cpp @@ -41,7 +41,7 @@ class TelegramLT : public IoTItem { if (param.size() == 1) { String strTmp; if (param[0].isDecimal && param[0].valS == "") - strTmp = param[0].valD; + strTmp = String(param[0].valD); else strTmp = param[0].valS; diff --git a/src/modules/exec/TelegramLT/modinfo.json b/src/modules/exec/TelegramLT/modinfo.json index b8cf7ba5..a0d79d33 100644 --- a/src/modules/exec/TelegramLT/modinfo.json +++ b/src/modules/exec/TelegramLT/modinfo.json @@ -52,6 +52,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/sensors/AnalogAdc/modinfo.json b/src/modules/sensors/AnalogAdc/modinfo.json index ee41ed63..67102aa2 100644 --- a/src/modules/sensors/AnalogAdc/modinfo.json +++ b/src/modules/sensors/AnalogAdc/modinfo.json @@ -42,6 +42,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/sensors/BL0937/modinfo.json b/src/modules/sensors/BL0937/modinfo.json index b458c34b..f6dea0d2 100644 --- a/src/modules/sensors/BL0937/modinfo.json +++ b/src/modules/sensors/BL0937/modinfo.json @@ -132,6 +132,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/Cron/modinfo.json b/src/modules/virtual/Cron/modinfo.json index 26f9fbab..b061e458 100644 --- a/src/modules/virtual/Cron/modinfo.json +++ b/src/modules/virtual/Cron/modinfo.json @@ -50,6 +50,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/DiscoveryHA/modinfo.json b/src/modules/virtual/DiscoveryHA/modinfo.json index e06f37f9..300a8f90 100644 --- a/src/modules/virtual/DiscoveryHA/modinfo.json +++ b/src/modules/virtual/DiscoveryHA/modinfo.json @@ -34,6 +34,7 @@ "defActive": false, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/DiscoveryHomeD/modinfo.json b/src/modules/virtual/DiscoveryHomeD/modinfo.json index 1f66c25a..800a7816 100644 --- a/src/modules/virtual/DiscoveryHomeD/modinfo.json +++ b/src/modules/virtual/DiscoveryHomeD/modinfo.json @@ -34,6 +34,7 @@ "defActive": false, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/Math/modinfo.json b/src/modules/virtual/Math/modinfo.json index 6ae5c83a..e0cf20a9 100644 --- a/src/modules/virtual/Math/modinfo.json +++ b/src/modules/virtual/Math/modinfo.json @@ -56,6 +56,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } diff --git a/src/modules/virtual/Timer/modinfo.json b/src/modules/virtual/Timer/modinfo.json index 7e3ee204..941235a2 100644 --- a/src/modules/virtual/Timer/modinfo.json +++ b/src/modules/virtual/Timer/modinfo.json @@ -74,6 +74,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/VButton/modinfo.json b/src/modules/virtual/VButton/modinfo.json index 8a61b2d1..68824a83 100644 --- a/src/modules/virtual/VButton/modinfo.json +++ b/src/modules/virtual/VButton/modinfo.json @@ -36,6 +36,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/Variable/modinfo.json b/src/modules/virtual/Variable/modinfo.json index bf91bb7a..77ed8a83 100644 --- a/src/modules/virtual/Variable/modinfo.json +++ b/src/modules/virtual/Variable/modinfo.json @@ -96,6 +96,7 @@ "defActive": true, "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } } \ No newline at end of file diff --git a/src/modules/virtual/owmWeather/modinfo.json b/src/modules/virtual/owmWeather/modinfo.json index 5940d5db..46502d0d 100644 --- a/src/modules/virtual/owmWeather/modinfo.json +++ b/src/modules/virtual/owmWeather/modinfo.json @@ -88,6 +88,7 @@ "usedLibs": { "esp32*": [], - "esp82*": [] + "esp82*": [], + "bk72*": [] } }