diff --git a/MQTT.cpp b/MQTT.cpp index af87378..55f693a 100644 --- a/MQTT.cpp +++ b/MQTT.cpp @@ -37,13 +37,14 @@ void MQTTClass::reset() { bool MQTTClass::loop() { if(settings.MQTT.enabled && !rebootDelay.reboot && !this->suspended && !mqttClient.connected()) { esp_task_wdt_reset(); - if(!net.connected()) this->connect(); + if(!this->connected() && net.connected()) this->connect(); } esp_task_wdt_reset(); if(settings.MQTT.enabled) mqttClient.loop(); return true; } void MQTTClass::receive(const char *topic, byte*payload, uint32_t length) { + esp_task_wdt_reset(); // Make sure we do not reboot here. Serial.print("MQTT Topic:"); Serial.print(topic); Serial.print(" payload:"); @@ -182,8 +183,10 @@ void MQTTClass::receive(const char *topic, byte*payload, uint32_t length) { } } } + esp_task_wdt_reset(); // Make sure we do not reboot here. } bool MQTTClass::connect() { + esp_task_wdt_reset(); // Make sure we do not reboot here. if(mqttClient.connected()) { if(!settings.MQTT.enabled || this->suspended) return this->disconnect(); @@ -278,6 +281,7 @@ bool MQTTClass::unsubscribe(const char *topic) { } bool MQTTClass::subscribe(const char *topic) { if(mqttClient.connected()) { + esp_task_wdt_reset(); // Make sure we do not reboot here. char top[128]; if(strlen(settings.MQTT.rootTopic) > 0) snprintf(top, sizeof(top), "%s/%s", settings.MQTT.rootTopic, topic); @@ -296,6 +300,7 @@ bool MQTTClass::publish(const char *topic, const char *payload, bool retain) { snprintf(top, sizeof(top), "%s/%s", settings.MQTT.rootTopic, topic); else strlcpy(top, topic, sizeof(top)); + esp_task_wdt_reset(); // Make sure we do not reboot here. mqttClient.publish(top, payload, retain); return true; } @@ -312,6 +317,7 @@ bool MQTTClass::unpublish(const char *topic) { snprintf(top, sizeof(top), "%s/%s", settings.MQTT.rootTopic, topic); else strlcpy(top, topic, sizeof(top)); + esp_task_wdt_reset(); // Make sure we do not reboot here. mqttClient.publish(top, (const uint8_t *)"", 0, true); return true; } @@ -326,6 +332,7 @@ bool MQTTClass::publishBuffer(const char *topic, uint8_t *data, uint16_t len, bo uint16_t offset = 0; uint16_t to_write = len; uint16_t buff_len; + esp_task_wdt_reset(); // Make sure we do not reboot here. mqttClient.beginPublish(topic, len, retain); do { buff_len = to_write; diff --git a/SomfyController.ino b/SomfyController.ino index 46dfc8d..464d179 100644 --- a/SomfyController.ino +++ b/SomfyController.ino @@ -49,7 +49,9 @@ void loop() { Serial.print("Rebooting after "); Serial.print(rebootDelay.rebootTime); Serial.println("ms"); + net.end(); ESP.restart(); + return; } uint32_t timing = millis(); diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 79d65de..8629793 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/SomfyController.ino.esp32s3.bin b/SomfyController.ino.esp32s3.bin index fce66a2..4bc4c33 100644 Binary files a/SomfyController.ino.esp32s3.bin and b/SomfyController.ino.esp32s3.bin differ