From 344bb0c6c10b369e39283056de43c09d521aafce Mon Sep 17 00:00:00 2001 From: Quoc Hung Date: Tue, 26 Nov 2024 11:59:31 +0700 Subject: [PATCH] Bump version to v1.4.5 * Update examples * Update watchdog --- .vscode/settings.json | 3 +- .../Realtek_PlugNPlay/Realtek_PlugNPlay.ino | 72 ++++++- .../Realtek_WiFi_Basic/Realtek_WiFi_Basic.ino | 68 +++++++ .../Realtek_WiFi_SSL/Realtek_WiFi_SSL.ino | 68 +++++++ library.json | 2 +- library.properties | 2 +- linux/main.py | 6 +- src/ERa.hpp | 8 +- src/ERa/ERaVersion.hpp | 4 +- src/Modbus/ERaModbusTransp.hpp | 2 +- src/PnP/ERaPnPArduino.hpp | 178 +++++++++++++++++- src/PnP/ERaPnPEsp32.hpp | 11 +- src/PnP/ERaPnPEsp8266.hpp | 11 +- src/PnP/ERaPnPTiny.hpp | 11 +- src/Utility/ERaUtility.cpp | 12 +- 15 files changed, 424 insertions(+), 34 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4832bc5..81b589d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -48,6 +48,7 @@ "stdexcept": "cpp", "streambuf": "cpp", "cinttypes": "cpp", - "typeinfo": "cpp" + "typeinfo": "cpp", + "*.tpp": "cpp" } } \ No newline at end of file diff --git a/examples/Realtek/Realtek_PlugNPlay/Realtek_PlugNPlay.ino b/examples/Realtek/Realtek_PlugNPlay/Realtek_PlugNPlay.ino index 11e9324..f514860 100644 --- a/examples/Realtek/Realtek_PlugNPlay/Realtek_PlugNPlay.ino +++ b/examples/Realtek/Realtek_PlugNPlay/Realtek_PlugNPlay.ino @@ -18,8 +18,61 @@ #define ERA_LOCATION_VN // #define ERA_LOCATION_SG +/* Define setting button */ +// #define BUTTON_PIN 0 + +#if defined(BUTTON_PIN) + // Active low (false), Active high (true) + #define BUTTON_INVERT false + #define BUTTON_HOLD_TIMEOUT 5000UL + + // This directive is used to specify whether the configuration should be erased. + // If it's set to true, the configuration will be erased. + #define ERA_ERASE_CONFIG true +#endif + #include -#include +#include +#if defined(BUTTON_PIN) + #include + #include +#endif + +WiFiClient mbTcpClient; + +#if defined(BUTTON_PIN) + ERaButton button; + const uint32_t timerIdButton {0}; + + static void handlerButton(uint32_t data) { + button.run(); + (void)data; + } + +#if ERA_VERSION_NUMBER >= ERA_VERSION_VAL(1, 2, 0) + static void eventButton(uint8_t pin, ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + (void)pin; + } +#else + static void eventButton(ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + } +#endif + + void initButton() { + pinMode(BUTTON_PIN, INPUT); + button.setButton(BUTTON_PIN, digitalReadArduino, eventButton, + BUTTON_INVERT).onHold(BUTTON_HOLD_TIMEOUT); + GTimer.begin(timerIdButton, (100 * 1000), handlerButton); + } +#endif /* This function will run every time ERa is connected */ ERA_CONNECTED() { @@ -42,8 +95,25 @@ void setup() { Serial.begin(115200); #endif +#if defined(BUTTON_PIN) + /* Initializing button. */ + initButton(); +#endif + /* Set board id */ // ERa.setBoardID("Board_1"); + + /* Setup Client for Modbus TCP/IP */ + ERa.setModbusClient(mbTcpClient); + + /* White labeling App (use this ONLY if you have a branded ERa App) */ + // ERa.setVendorName("MyORG"); + // ERa.setVendorPrefix("MyPrefix"); + + /* Set scan WiFi. If activated, the board will + check WiFi before connect. */ + ERa.setScanWiFi(true); + /* Initializing the ERa library. */ ERa.begin(); diff --git a/examples/Realtek/Realtek_WiFi_Basic/Realtek_WiFi_Basic.ino b/examples/Realtek/Realtek_WiFi_Basic/Realtek_WiFi_Basic.ino index 0a335b9..0fdd80e 100644 --- a/examples/Realtek/Realtek_WiFi_Basic/Realtek_WiFi_Basic.ino +++ b/examples/Realtek/Realtek_WiFi_Basic/Realtek_WiFi_Basic.ino @@ -21,12 +21,65 @@ // You should get Auth Token in the ERa App or ERa Dashboard #define ERA_AUTH_TOKEN "ERA2706" +/* Define setting button */ +// #define BUTTON_PIN 0 + +#if defined(BUTTON_PIN) + // Active low (false), Active high (true) + #define BUTTON_INVERT false + #define BUTTON_HOLD_TIMEOUT 5000UL + + // This directive is used to specify whether the configuration should be erased. + // If it's set to true, the configuration will be erased. + #define ERA_ERASE_CONFIG false +#endif + #include #include +#if defined(BUTTON_PIN) + #include + #include +#endif const char ssid[] = "YOUR_SSID"; const char pass[] = "YOUR_PASSWORD"; +WiFiClient mbTcpClient; + +#if defined(BUTTON_PIN) + ERaButton button; + const uint32_t timerIdButton {0}; + + static void handlerButton(uint32_t data) { + button.run(); + (void)data; + } + +#if ERA_VERSION_NUMBER >= ERA_VERSION_VAL(1, 2, 0) + static void eventButton(uint8_t pin, ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + (void)pin; + } +#else + static void eventButton(ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + } +#endif + + void initButton() { + pinMode(BUTTON_PIN, INPUT); + button.setButton(BUTTON_PIN, digitalReadArduino, eventButton, + BUTTON_INVERT).onHold(BUTTON_HOLD_TIMEOUT); + GTimer.begin(timerIdButton, (100 * 1000), handlerButton); + } +#endif + /* This function will run every time ERa is connected */ ERA_CONNECTED() { ERA_LOG("ERa", "ERa connected!"); @@ -48,8 +101,23 @@ void setup() { Serial.begin(115200); #endif +#if defined(BUTTON_PIN) + /* Initializing button. */ + initButton(); + /* Enable read/write WiFi credentials */ + ERa.setPersistent(true); +#endif + /* Set board id */ // ERa.setBoardID("Board_1"); + + /* Setup Client for Modbus TCP/IP */ + ERa.setModbusClient(mbTcpClient); + + /* Set scan WiFi. If activated, the board will + check WiFi before connect. */ + ERa.setScanWiFi(true); + /* Initializing the ERa library. */ ERa.begin(ssid, pass); diff --git a/examples/Realtek/Realtek_WiFi_SSL/Realtek_WiFi_SSL.ino b/examples/Realtek/Realtek_WiFi_SSL/Realtek_WiFi_SSL.ino index 1c90e84..c02c185 100644 --- a/examples/Realtek/Realtek_WiFi_SSL/Realtek_WiFi_SSL.ino +++ b/examples/Realtek/Realtek_WiFi_SSL/Realtek_WiFi_SSL.ino @@ -22,12 +22,65 @@ #define ERA_AUTH_TOKEN "ERA2706" #define ERA_USE_SSL +/* Define setting button */ +// #define BUTTON_PIN 0 + +#if defined(BUTTON_PIN) + // Active low (false), Active high (true) + #define BUTTON_INVERT false + #define BUTTON_HOLD_TIMEOUT 5000UL + + // This directive is used to specify whether the configuration should be erased. + // If it's set to true, the configuration will be erased. + #define ERA_ERASE_CONFIG false +#endif + #include #include +#if defined(BUTTON_PIN) + #include + #include +#endif const char ssid[] = "YOUR_SSID"; const char pass[] = "YOUR_PASSWORD"; +WiFiClient mbTcpClient; + +#if defined(BUTTON_PIN) + ERaButton button; + const uint32_t timerIdButton {0}; + + static void handlerButton(uint32_t data) { + button.run(); + (void)data; + } + +#if ERA_VERSION_NUMBER >= ERA_VERSION_VAL(1, 2, 0) + static void eventButton(uint8_t pin, ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + (void)pin; + } +#else + static void eventButton(ButtonEventT event) { + if (event != ButtonEventT::BUTTON_ON_HOLD) { + return; + } + ERa.switchToConfig(ERA_ERASE_CONFIG); + } +#endif + + void initButton() { + pinMode(BUTTON_PIN, INPUT); + button.setButton(BUTTON_PIN, digitalReadArduino, eventButton, + BUTTON_INVERT).onHold(BUTTON_HOLD_TIMEOUT); + GTimer.begin(timerIdButton, (100 * 1000), handlerButton); + } +#endif + /* This function will run every time ERa is connected */ ERA_CONNECTED() { ERA_LOG("ERa", "ERa connected!"); @@ -49,8 +102,23 @@ void setup() { Serial.begin(115200); #endif +#if defined(BUTTON_PIN) + /* Initializing button. */ + initButton(); + /* Enable read/write WiFi credentials */ + ERa.setPersistent(true); +#endif + /* Set board id */ // ERa.setBoardID("Board_1"); + + /* Setup Client for Modbus TCP/IP */ + ERa.setModbusClient(mbTcpClient); + + /* Set scan WiFi. If activated, the board will + check WiFi before connect. */ + ERa.setScanWiFi(true); + /* Initializing the ERa library. */ ERa.begin(ssid, pass); diff --git a/library.json b/library.json index 56ea7a4..dab2879 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ERa", - "version": "1.4.4", + "version": "1.4.5", "description": "E-Ra by EoH. An IoT Market Enabler! It supports WiFi, Ethernet, Zigbee, Modbus, Serial. Works with boards like Arduino, ESP8266, ESP32, STM32, Raspberry Pi...", "keywords": "ERa, E-Ra, esp8266, esp32, stm32, raspberry-pi, http, mqtt, zigbee, modbus, sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, wifi, ethernet, serial", "authors": diff --git a/library.properties b/library.properties index a34eb99..27a008d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ERa -version=1.4.4 +version=1.4.5 author=EoH Ltd license=MIT maintainer=EoH Ltd diff --git a/linux/main.py b/linux/main.py index de40c75..e1b1d6f 100644 --- a/linux/main.py +++ b/linux/main.py @@ -19,9 +19,9 @@ ERA_MAJOR = 1 ERA_MINOR = 4 -ERA_PATCH = 4 -ERA_VERSION = "1.4.4" -ERA_FIRMWARE_VERSION = "1.4.4" +ERA_PATCH = 5 +ERA_VERSION = "1.4.5" +ERA_FIRMWARE_VERSION = "1.4.5" BUTTON_GPIO = 16 diff --git a/src/ERa.hpp b/src/ERa.hpp index d45d932..6f415c8 100644 --- a/src/ERa.hpp +++ b/src/ERa.hpp @@ -3,9 +3,9 @@ #if defined(ARDUINO) && defined(ESP32) #if defined(ERA_USE_SSL) - #include + #include #else - #include + #include #endif #elif defined(ARDUINO) && defined(ESP8266) #if defined(ERA_USE_SSL) @@ -16,9 +16,9 @@ #elif defined(ARDUINO) && \ (defined(RTL8722DM) || defined(ARDUINO_AMEBA)) #if defined(ERA_USE_SSL) - #include + #include #else - #include + #include #endif #elif defined(ARDUINO) && defined(ARDUINO_ARCH_STM32) #include diff --git a/src/ERa/ERaVersion.hpp b/src/ERa/ERaVersion.hpp index 895b9f2..6faa117 100644 --- a/src/ERa/ERaVersion.hpp +++ b/src/ERa/ERaVersion.hpp @@ -3,7 +3,7 @@ #define ERA_MAJOR 1 #define ERA_MINOR 4 -#define ERA_PATCH 4 +#define ERA_PATCH 5 #define ERA_VERSION_TO_STR_2(val) # val #define ERA_VERSION_TO_STR(val) ERA_VERSION_TO_STR_2(val) @@ -17,7 +17,7 @@ #define ERA_VERSION ERA_VERSION_TO_STR(ERA_MAJOR) "." \ ERA_VERSION_TO_STR(ERA_MINOR) "." \ ERA_VERSION_TO_STR(ERA_PATCH) -#define ERA_VERSION_1_4_4 +#define ERA_VERSION_1_4_5 #if !defined(ERA_FIRMWARE_VERSION) #define ERA_FIRMWARE_VERSION ERA_VERSION diff --git a/src/Modbus/ERaModbusTransp.hpp b/src/Modbus/ERaModbusTransp.hpp index d956f49..63059b0 100644 --- a/src/Modbus/ERaModbusTransp.hpp +++ b/src/Modbus/ERaModbusTransp.hpp @@ -892,7 +892,7 @@ class ERaModbusTransp } } ERA_FORCE_UNUSED(param); - ERA_FORCE_UNUSED(skip); + ERA_FORCE_UNUSED(processWrite); ERA_FORCE_UNUSED(skip); return status; } diff --git a/src/PnP/ERaPnPArduino.hpp b/src/PnP/ERaPnPArduino.hpp index 3c80e07..94db41d 100644 --- a/src/PnP/ERaPnPArduino.hpp +++ b/src/PnP/ERaPnPArduino.hpp @@ -39,6 +39,7 @@ #define WIFI_SCAN_MAX 15 #define WIFI_SCAN_TIMEOUT 20000 +#define WIFI_SCAN_CHANNEL_TIMEOUT 150 #define WIFI_NET_CONNECT_TIMEOUT 60000 #define WIFI_CLOUD_CONNECT_TIMEOUT 60000 #define WIFI_NET_CHECK_TIMEOUT (WIFI_NET_CONNECT_TIMEOUT * 3) @@ -72,6 +73,9 @@ typedef struct __ERaConfig_t { bool connected; bool forceSave; + int32_t channel; + uint8_t bssid[6]; + void setFlag(uint8_t mask, bool value) { if (value) { flags |= mask; @@ -266,7 +270,9 @@ class ERaPnP ERaPnP(Transport& _transp, ERaFlash& _flash) : Base(_transp, _flash) , authToken(nullptr) + , scanWiFiConnect(false) , persistent(false) + , scanWiFiRetry(1UL) , server(80) , newWiFi {} , prevMillis(0UL) @@ -352,18 +358,28 @@ class ERaPnP ERA_MQTT_USERNAME, ERA_MQTT_PASSWORD); } + void setScanWiFi(bool enable, unsigned long retry = 2UL) { + this->scanWiFiConnect = enable; + if (retry) { + this->scanWiFiRetry = retry; + } + } + void setPersistent(bool enable) { this->persistent = enable; } - void switchToConfig(bool erase = false) { + void switchToConfig(bool erase = false, bool execute = false) { ERaConfig.connected = false; ERaConfig.setFlag(ConfigFlagT::CONFIG_FLAG_API, true); - if (erase) { - ERaState::set(StateT::STATE_RESET_CONFIG); + if (!erase) { + ERaState::set(StateT::STATE_SWITCH_TO_AP); + } + else if (execute) { + this->configReset(); } else { - ERaState::set(StateT::STATE_SWITCH_TO_AP); + ERaState::set(StateT::STATE_RESET_CONFIG); } ERA_LOG(TAG, ERA_PSTR("Switch to config mode!")); } @@ -383,6 +399,8 @@ class ERaPnP void waitHandle(String& networks, unsigned long ms); void runServer(String& networks); String scanNetworks(); + bool scanNetwork(const char* ssid); + bool scanNetworks(const char* ssid); cJSON* scanNetworksJson(int nets, bool compact = false); void addEncryptionType(uint8_t networkItem, cJSON* const item); String urlDecode(const String& text); @@ -424,7 +442,9 @@ class ERaPnP const char* authToken; const char channelAP[2] = "1"; + bool scanWiFiConnect; bool persistent; + unsigned long scanWiFiRetry; WiFiServer server; WiFiConfig_t newWiFi; @@ -1109,6 +1129,122 @@ String ERaPnP::scanNetworks() { return content; } +template +bool ERaPnP::scanNetwork(const char* ssid) { + if (!this->scanWiFiConnect) { + return true; + } + if (!strlen(ssid)) { + return false; + } + +#if defined(ESP32) || \ + defined(ESP8266) + + ERA_LOG(TAG, ERA_PSTR("WiFi scan SSID: %s"), ssid); + + bool found {false}; + +#if defined(ESP32) + int nets = WiFi.scanNetworks(true, true, false, + WIFI_SCAN_CHANNEL_TIMEOUT); +#elif defined(ESP8266) + int nets = WiFi.scanNetworks(true, true); +#else + int nets = WiFi.scanNetworks(); + ERaWatchdogFeed(); +#endif + + MillisTime_t tick = ERaMillis(); + while ((nets < 0) && ERaRemainingTime(tick, WIFI_SCAN_TIMEOUT)) { + ERaDelay(100); + ERaWatchdogFeed(); + Base::appLoop(); + ERaWatchdogFeed(); + nets = WiFi.scanComplete(); + } + if (nets <= 0) { + WiFi.scanDelete(); + WiFi.disconnect(); + ERA_LOG_WARNING(TAG, ERA_PSTR("Not found any SSID")); + return false; + } + + int32_t rssi {-9999}; + for (int i = 0; i < nets; ++i) { + if (::getSSID(i) == ssid) { + found = true; + ERA_LOG(TAG, ERA_PSTR("Found SSID: %s, BSSID: %s, RSSI: %d, Channel: %d"), + ::getSSID(i).c_str(), ::getBSSID(i).c_str(), WiFi.RSSI(i), + WiFi.channel(i)); + if (rssi > WiFi.RSSI(i)) { + continue; + } + rssi = WiFi.RSSI(i); + ERaConfig.channel = WiFi.channel(i); + const uint8_t* pbssid = WiFi.BSSID(i); + if (pbssid != nullptr) { + CopyToArray(*pbssid, ERaConfig.bssid); + } + } + } + if (found) { + char mac[20] {0}; + FormatString(mac, "%02X:%02X:%02X:%02X:%02X:%02X", ERaConfig.bssid[0], ERaConfig.bssid[1], + ERaConfig.bssid[2], ERaConfig.bssid[3], + ERaConfig.bssid[4], ERaConfig.bssid[5]); + ERA_LOG(TAG, ERA_PSTR("Connecting SSID: %s, BSSID: %s, RSSI: %d, Channel: %d"), + ssid, mac, rssi, ERaConfig.channel); + } + else { + ERA_LOG_WARNING(TAG, ERA_PSTR("Not Found SSID: %s"), ssid); + } + WiFi.scanDelete(); + + return found; + +#else + + ERA_LOG(TAG, ERA_PSTR("WiFi scan SSID: %s"), ssid); + + bool found {false}; + + int nets = WiFi.scanNetworks(); + ERaWatchdogFeed(); + + if (nets <= 0) { + ERA_LOG_WARNING(TAG, ERA_PSTR("Not found any SSID")); + return false; + } + + for (int i = 0; i < nets; ++i) { + if (::getSSID(i) == ssid) { + found = true; + break; + } + } + if (found) { + ERA_LOG(TAG, ERA_PSTR("Connecting SSID: %s"), ssid); + } + else { + ERA_LOG_WARNING(TAG, ERA_PSTR("Not Found SSID: %s"), ssid); + } + + return found; + +#endif +} + +template +bool ERaPnP::scanNetworks(const char* ssid) { + for (unsigned long i = 0; i < this->scanWiFiRetry; ++i) { + if (this->scanNetwork(ssid)) { + return true; + } + } + return false; +} + template cJSON* ERaPnP::scanNetworksJson(int nets, bool compact) { if (nets <= 0) { @@ -1383,6 +1519,9 @@ void ERaPnP::connectWiFi(const char* ssid, const char* pass) { if (!strlen(ssid)) { return; } + if (!this->scanNetworks(ssid)) { + return; + } int status = WiFi.status(); @@ -1395,17 +1534,42 @@ void ERaPnP::connectWiFi(const char* ssid, const char* pass) { ERaWatchdogFeed(); ERA_LOG(TAG, ERA_PSTR("Connecting to %s..."), ssid); + +#if defined(ESP32) || \ + defined(ESP8266) + + if (this->scanWiFiConnect) { + if (pass && strlen(pass)) { + WiFi.begin(ssid, pass, ERaConfig.channel, ERaConfig.bssid); + } + else { + WiFi.begin(ssid, nullptr, ERaConfig.channel, ERaConfig.bssid); + } + } + else { + if (pass && strlen(pass)) { + WiFi.begin(ssid, pass); + } + else { + WiFi.begin(ssid); + } + } + +#else + if (pass && strlen(pass)) { WiFi.begin((char*)ssid, (char*)pass); } else { -#if defined(ARDUINO_MBED_HAS_WIFI) + #if defined(ARDUINO_MBED_HAS_WIFI) WiFi.begin((char*)ssid, (char*)""); -#else + #else WiFi.begin((char*)ssid); -#endif + #endif } +#endif + ERaWatchdogFeed(); MillisTime_t startMillis = ERaMillis(); diff --git a/src/PnP/ERaPnPEsp32.hpp b/src/PnP/ERaPnPEsp32.hpp index 8a7a84e..acc18ba 100644 --- a/src/PnP/ERaPnPEsp32.hpp +++ b/src/PnP/ERaPnPEsp32.hpp @@ -274,14 +274,17 @@ class ERaPnP this->persistent = enable; } - void switchToConfig(bool erase = false) { + void switchToConfig(bool erase = false, bool execute = false) { ERaConfig.connected = false; ERaConfig.setFlag(ConfigFlagT::CONFIG_FLAG_API, true); - if (erase) { - ERaState::set(StateT::STATE_RESET_CONFIG); + if (!erase) { + ERaState::set(StateT::STATE_SWITCH_TO_AP); + } + else if (execute) { + this->configReset(); } else { - ERaState::set(StateT::STATE_SWITCH_TO_AP); + ERaState::set(StateT::STATE_RESET_CONFIG); } ERA_LOG(TAG, ERA_PSTR("Switch to config mode!")); } diff --git a/src/PnP/ERaPnPEsp8266.hpp b/src/PnP/ERaPnPEsp8266.hpp index 7ca3bbc..a49e8e5 100644 --- a/src/PnP/ERaPnPEsp8266.hpp +++ b/src/PnP/ERaPnPEsp8266.hpp @@ -245,14 +245,17 @@ class ERaPnP this->persistent = enable; } - void switchToConfig(bool erase = false) { + void switchToConfig(bool erase = false, bool execute = false) { ERaConfig.connected = false; ERaConfig.setFlag(ConfigFlagT::CONFIG_FLAG_API, true); - if (erase) { - ERaState::set(StateT::STATE_RESET_CONFIG); + if (!erase) { + ERaState::set(StateT::STATE_SWITCH_TO_AP); + } + else if (execute) { + this->configReset(); } else { - ERaState::set(StateT::STATE_SWITCH_TO_AP); + ERaState::set(StateT::STATE_RESET_CONFIG); } ERA_LOG(TAG, ERA_PSTR("Switch to config mode!")); } diff --git a/src/PnP/ERaPnPTiny.hpp b/src/PnP/ERaPnPTiny.hpp index 68643d6..09de129 100644 --- a/src/PnP/ERaPnPTiny.hpp +++ b/src/PnP/ERaPnPTiny.hpp @@ -357,14 +357,17 @@ class ERaPnP this->persistent = enable; } - void switchToConfig(bool erase = false) { + void switchToConfig(bool erase = false, bool execute = false) { ERaConfig.connected = false; ERaConfig.setFlag(ConfigFlagT::CONFIG_FLAG_API, true); - if (erase) { - ERaState::set(StateT::STATE_RESET_CONFIG); + if (!erase) { + ERaState::set(StateT::STATE_SWITCH_TO_AP); + } + else if (execute) { + this->configReset(); } else { - ERaState::set(StateT::STATE_SWITCH_TO_AP); + ERaState::set(StateT::STATE_RESET_CONFIG); } ERA_LOG(TAG, ERA_PSTR("Switch to config mode!")); } diff --git a/src/Utility/ERaUtility.cpp b/src/Utility/ERaUtility.cpp index f90534b..7792beb 100644 --- a/src/Utility/ERaUtility.cpp +++ b/src/Utility/ERaUtility.cpp @@ -121,12 +121,22 @@ } esp_task_wdt_config_t twdt_config = { .timeout_ms = timeout, - .idle_core_mask = ((1 << portNUM_PROCESSORS) - 1), + .idle_core_mask = 0, .trigger_panic = true }; + #if !CONFIG_ESP_TASK_WDT_INIT + twdt_config.idle_core_mask |= ((1 << portNUM_PROCESSORS) - 1); + esp_task_wdt_init(&twdt_config); #else + #if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 + twdt_config.idle_core_mask |= (1 << 0); + #endif + #if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 + twdt_config.idle_core_mask |= (1 << 1); + #endif + esp_task_wdt_reconfigure(&twdt_config); #endif esp_task_wdt_add(NULL);