From 26c0cca614529c86bf8729455e26c64a201c403d Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 9 Feb 2023 15:19:09 -0600 Subject: [PATCH] [LPM] - Fix reboot loop when low power is used (#1444) By not deinitializing BLE at the start, if it has not been initialized. Setting the time between waking up from the macro rather than the config interval. This one does not have a value at the start. --- docs/use/boards.md | 2 ++ main/ZgatewayBT.ino | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/use/boards.md b/docs/use/boards.md index 40a11aa..db80b36 100644 --- a/docs/use/boards.md +++ b/docs/use/boards.md @@ -24,6 +24,8 @@ OpenMQTTGateway support a low power mode for ESP32, this mode can be set by MQTT `mosquitto_pub -t "home/OpenMQTTGateway/commands/MQTTtoBT/config" -m '{"lowpowermode":2}'` +The interval between the ESP32 wake up is defined at build time by the macro `TimeBtwRead`, a change of the `interval` through MQTT will not impact the time between wake up. + ::: tip When coming back from mode 2 to mode 0 you may publish the command with a retain flag so as to enable the gateway to retrieve it when reconnecting. A low power mode switch is automatically created by discovery with Home Assistant, you may experience a delay between the command and the state update due to the fact that the update is published every 2 minutes. diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 1dd5e6b..80cb71f 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -760,8 +760,8 @@ void coreTask(void* pvParameters) { } void lowPowerESP32() { // low power mode - Log.trace(F("Going to deep sleep for: %l s" CR), (BTConfig.BLEinterval / 1000)); - deepSleep(BTConfig.BLEinterval * 1000); + Log.trace(F("Going to deep sleep for: %l s" CR), (TimeBtwRead / 1000)); + deepSleep(TimeBtwRead * 1000); } void deepSleep(uint64_t time_in_us) { @@ -771,7 +771,7 @@ void deepSleep(uint64_t time_in_us) { # endif Log.trace(F("Deactivating ESP32 components" CR)); - BLEDevice::deinit(true); + if (BLEDevice::getInitialized()) BLEDevice::deinit(true); esp_bt_mem_release(ESP_BT_MODE_BTDM); // Ignore the deprecated warning, this call is necessary here. # pragma GCC diagnostic push