Skip to content

Commit

Permalink
Improve reset mechanism when MQTT is not connected
Browse files Browse the repository at this point in the history
This enables to wait less for the reset to trigger
  • Loading branch information
1technophile committed Nov 30, 2022
1 parent 8ee1c4e commit 33a5b3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/use/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ The pre-built binaries for **rfbridge** and **avatto-bakeey-ir** have the above
The gateway can support up to 3 LED to display its operating state:
* LED_INFO
switched ON when network and MQTT connection are OK
5s ON, 5s OFF when WIFI is disconnected
1s ON, 4s OFF when MQTT is disconnected
5s ON, 5s OFF when MQTT is disconnected
2s ON, 2s OFF when NETWORK is disconnected

* LED_RECEIVE
Blink for `TimeLedON` 1s when the gateway receive a signal from one of its module so as to send to MQTT
Expand Down
2 changes: 1 addition & 1 deletion main/ZsensorGPIOInput.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -417,14 +416,15 @@ 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
#else
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));
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 33a5b3a

Please sign in to comment.