Improve reset mechanism when MQTT is not connected (#1338)

This enables to wait less for the reset to trigger
This commit is contained in:
Florian authored and GitHub committed 2022-11-30 14:27:27 -06:00
1 parent 8ee1c4e524
commit dee3ef4de5
3 files changed
+11 -6

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ void MeasureGPIOInput() {
if (reading == LOW) {
if (resetTime == 0) {
resetTime = millis();
} else if ((millis() - resetTime) > 10000) {
} else if ((millis() - resetTime) > 3000) {
Log.trace(F("Button Held" CR));
Log.notice(F("Erasing ESP Config, restarting" CR));
setup_wifimanager(true);
+8 -3
View File
@@ -328,7 +328,6 @@ void pub(const char* topicori, JsonObject& data) {
String dataAsString = "";
serializeJson(data, dataAsString);
Log.notice(F("Send on %s msg %s" CR), topicori, dataAsString.c_str());
SendReceiveIndicatorON();
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
#if valueAsATopic
# ifdef ZgatewayPilight
@@ -417,6 +416,7 @@ void pubMQTT(const char* topic, const char* payload) {
*/
void pubMQTT(const char* topic, const char* payload, bool retainFlag) {
if (client.connected()) {
SendReceiveIndicatorON();
Log.trace(F("[ OMG->MQTT ] topic: %s msg: %s " CR), topic, payload);
#if AWS_IOT
client.publish(topic, payload); // AWS IOT doesn't support retain flag for the moment
@@ -424,7 +424,7 @@ void pubMQTT(const char* topic, const char* payload, bool retainFlag) {
client.publish(topic, payload, retainFlag);
#endif
} else {
Log.warning(F("Client not connected, aborting thes publication" CR));
Log.warning(F("Client not connected, aborting the publication" CR));
}
}
@@ -526,6 +526,11 @@ void delayWithOTA(long waitMillis) {
#if defined(ESP8266) || defined(ESP32)
long waitStep = 100;
for (long waitedMillis = 0; waitedMillis < waitMillis; waitedMillis += waitStep) {
# ifndef ESPWifiManualSetup
# if defined(ESP8266) || defined(ESP32)
checkButton(); // check if a reset of wifi/mqtt settings is asked
# endif
# endif
ArduinoOTA.handle();
delay(waitStep);
}
@@ -589,7 +594,7 @@ void connectMQTT() {
Log.warning(F("failed, ssl error code=%d" CR), ((WiFiClientSecure*)eClient)->getLastSSLError());
#endif
ErrorIndicatorON();
delayWithOTA(2000);
delayWithOTA(5000);
ErrorIndicatorOFF();
delayWithOTA(5000);
if (failure_number_mqtt > maxRetryWatchDog) {