tiny->bk7231, WS ping? fix clear config

This commit is contained in:
Mit4el
2024-11-20 21:11:50 +03:00
parent 8136d47cbd
commit d6e4ac232f
25 changed files with 93 additions and 32 deletions

View File

@@ -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;

View File

@@ -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---------");

View File

@@ -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");

View File

@@ -38,6 +38,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -46,6 +46,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -50,6 +50,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -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;

View File

@@ -52,6 +52,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -42,6 +42,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -132,6 +132,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -50,6 +50,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -34,6 +34,7 @@
"defActive": false,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -34,6 +34,7 @@
"defActive": false,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -56,6 +56,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -74,6 +74,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -36,6 +36,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -96,6 +96,7 @@
"defActive": true,
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}

View File

@@ -88,6 +88,7 @@
"usedLibs": {
"esp32*": [],
"esp82*": []
"esp82*": [],
"bk72*": []
}
}