Implement error LED and status codes. (#1006)

Merges LED_RECEIVE/LED_SEND into LED_SEND_RECEIVE pin definition.

Adds LED_ERROR to display error status based on blink times as follows:

Disconnected from Wifi: 2 seconds on 2 seconds off.
Disconnected from broker: 2 seconds on 5 seconds off.

Other status LED indications added:
WifiManager configuration web portal active: LED_INFO and LED_SEND_RECEIVE = ON.
OTA Update in progress: LED_SEND_RECIEVE and LED_ERROR = ON.
This commit is contained in:
h2zero authored and GitHub committed 2021-07-01 13:24:20 -05:00
1 parent 76f880dc15
commit 05dddf42de
2 files changed
+48 -34

No files matched your search

+14 -14
View File
@@ -334,33 +334,33 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#endif #endif
/*-------------DEFINE PINs FOR STATUS LEDs----------------*/ /*-------------DEFINE PINs FOR STATUS LEDs----------------*/
#ifndef LED_RECEIVE #ifndef LED_SEND_RECEIVE
# ifdef ESP8266 # ifdef ESP8266
# define LED_RECEIVE 40 # define LED_SEND_RECEIVE 40
# elif ESP32 # elif ESP32
# define LED_RECEIVE 40 # define LED_SEND_RECEIVE 40
# elif __AVR_ATmega2560__ //arduino mega # elif __AVR_ATmega2560__ //arduino mega
# define LED_RECEIVE 40 # define LED_SEND_RECEIVE 40
# else //arduino uno/nano # else //arduino uno/nano
# define LED_RECEIVE 40 # define LED_SEND_RECEIVE 40
# endif # endif
#endif #endif
#ifndef LED_RECEIVE_ON #ifndef LED_SEND_RECEIVE_ON
# define LED_RECEIVE_ON HIGH # define LED_SEND_RECEIVE_ON HIGH
#endif #endif
#ifndef LED_SEND #ifndef LED_ERROR
# ifdef ESP8266 # ifdef ESP8266
# define LED_SEND 42 # define LED_ERROR 42
# elif ESP32 # elif ESP32
# define LED_SEND 42 # define LED_ERROR 42
# elif __AVR_ATmega2560__ //arduino mega # elif __AVR_ATmega2560__ //arduino mega
# define LED_SEND 42 # define LED_ERROR 42
# else //arduino uno/nano # else //arduino uno/nano
# define LED_SEND 42 # define LED_ERROR 42
# endif # endif
#endif #endif
#ifndef LED_SEND_ON #ifndef LED_ERROR_ON
# define LED_SEND_ON HIGH # define LED_ERROR_ON HIGH
#endif #endif
#ifndef LED_INFO #ifndef LED_INFO
# ifdef ESP8266 # ifdef ESP8266
+34 -20
View File
@@ -287,7 +287,7 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {
void pub(const char* topicori, JsonObject& data) { void pub(const char* topicori, JsonObject& data) {
Log.notice(F("Subject: %s" CR), topicori); Log.notice(F("Subject: %s" CR), topicori);
digitalWrite(LED_RECEIVE, LED_RECEIVE_ON); digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
logJson(data); logJson(data);
if (client.connected()) { if (client.connected()) {
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori); String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
@@ -528,10 +528,10 @@ void connectMQTT() {
#elif defined(ESP8266) #elif defined(ESP8266)
Log.warning(F("failed, ssl error code=%d" CR), ((WiFiClientSecure*)eClient)->getLastSSLError()); Log.warning(F("failed, ssl error code=%d" CR), ((WiFiClientSecure*)eClient)->getLastSSLError());
#endif #endif
digitalWrite(LED_INFO, LED_INFO_ON); digitalWrite(LED_ERROR, LED_ERROR_ON);
delay(1000); delay(2000);
digitalWrite(LED_INFO, !LED_INFO_ON); digitalWrite(LED_ERROR, !LED_ERROR_ON);
delay(4000); delay(5000);
} }
} }
@@ -563,6 +563,14 @@ void setup() {
Log.begin(LOG_LEVEL, &Serial); Log.begin(LOG_LEVEL, &Serial);
Log.notice(F(CR "************* WELCOME TO OpenMQTTGateway **************" CR)); Log.notice(F(CR "************* WELCOME TO OpenMQTTGateway **************" CR));
//setup LED status
pinMode(LED_SEND_RECEIVE, OUTPUT);
pinMode(LED_INFO, OUTPUT);
pinMode(LED_ERROR, OUTPUT);
digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
digitalWrite(LED_INFO, !LED_INFO_ON);
digitalWrite(LED_ERROR, !LED_ERROR_ON);
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
# ifdef ESP8266 # ifdef ESP8266
# ifndef ZgatewaySRFB // if we are not in sonoff rf bridge case we apply the ESP8266 GPIO optimization # ifndef ZgatewaySRFB // if we are not in sonoff rf bridge case we apply the ESP8266 GPIO optimization
@@ -600,14 +608,6 @@ void setup() {
setup_ethernet(); setup_ethernet();
#endif #endif
//setup LED status
pinMode(LED_RECEIVE, OUTPUT);
pinMode(LED_SEND, OUTPUT);
pinMode(LED_INFO, OUTPUT);
digitalWrite(LED_RECEIVE, !LED_RECEIVE_ON);
digitalWrite(LED_SEND, !LED_SEND_ON);
digitalWrite(LED_INFO, !LED_INFO_ON);
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
if (mqtt_secure) { if (mqtt_secure) {
eClient = new WiFiClientSecure; eClient = new WiFiClientSecure;
@@ -819,6 +819,8 @@ void setOTA() {
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
Log.trace(F("Start OTA, lock other functions" CR)); Log.trace(F("Start OTA, lock other functions" CR));
digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, LED_ERROR_ON);
# if defined(ZgatewayBT) && defined(ESP32) # if defined(ZgatewayBT) && defined(ESP32)
stopProcessing(); stopProcessing();
# endif # endif
@@ -828,6 +830,8 @@ void setOTA() {
}); });
ArduinoOTA.onEnd([]() { ArduinoOTA.onEnd([]() {
Log.trace(F("\nOTA done" CR)); Log.trace(F("\nOTA done" CR));
digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, !LED_ERROR_ON);
# if defined(ZgatewayBT) && defined(ESP32) # if defined(ZgatewayBT) && defined(ESP32)
startProcessing(); startProcessing();
# endif # endif
@@ -839,6 +843,8 @@ void setOTA() {
Log.trace(F("Progress: %u%%\r" CR), (progress / (total / 100))); Log.trace(F("Progress: %u%%\r" CR), (progress / (total / 100)));
}); });
ArduinoOTA.onError([](ota_error_t error) { ArduinoOTA.onError([](ota_error_t error) {
digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, !LED_ERROR_ON);
# if defined(ZgatewayBT) && defined(ESP32) # if defined(ZgatewayBT) && defined(ESP32)
startProcessing(); startProcessing();
# endif # endif
@@ -1137,6 +1143,8 @@ void setup_wifimanager(bool reset_settings) {
} }
# endif # endif
digitalWrite(LED_ERROR, LED_ERROR_ON);
digitalWrite(LED_INFO, LED_INFO_ON);
Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, WifiManager_password); Log.notice(F("Connect your phone to WIFI AP: %s with PWD: %s" CR), WifiManager_ssid, WifiManager_password);
//fetches ssid and pass and tries to connect //fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name //if it does not connect it starts an access point with the specified name
@@ -1152,6 +1160,8 @@ void setup_wifimanager(bool reset_settings) {
# endif # endif
delay(5000); delay(5000);
} }
digitalWrite(LED_ERROR, !LED_ERROR_ON);
digitalWrite(LED_INFO, !LED_INFO_ON);
} }
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) # if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK)
@@ -1289,9 +1299,8 @@ void loop() {
// Switch off of the LED after TimeLedON // Switch off of the LED after TimeLedON
if (now > (timer_led_measures + (TimeLedON * 1000))) { if (now > (timer_led_measures + (TimeLedON * 1000))) {
timer_led_measures = millis(); timer_led_measures = millis();
digitalWrite(LED_RECEIVE, !LED_RECEIVE_ON);
digitalWrite(LED_INFO, !LED_INFO_ON); digitalWrite(LED_INFO, !LED_INFO_ON);
digitalWrite(LED_SEND, !LED_SEND_ON); digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
} }
#if defined(ESP8266) || defined(ESP32) #if defined(ESP8266) || defined(ESP32)
@@ -1428,10 +1437,10 @@ void loop() {
} }
} else { // disconnected from network } else { // disconnected from network
Log.warning(F("Network disconnected:" CR)); Log.warning(F("Network disconnected:" CR));
digitalWrite(LED_INFO, LED_INFO_ON); digitalWrite(LED_ERROR, LED_ERROR_ON);
delay(5000); // add a delay to avoid ESP32 crash and reset delay(2000); // add a delay to avoid ESP32 crash and reset
digitalWrite(LED_INFO, !LED_INFO_ON); digitalWrite(LED_ERROR, !LED_ERROR_ON);
delay(5000); delay(2000);
#if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET) #if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET)
# ifdef ESP32 // If used with ESP8266 this method prevent the reconnection # ifdef ESP32 // If used with ESP8266 this method prevent the reconnection
WiFi.reconnect(); WiFi.reconnect();
@@ -1663,7 +1672,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
MQTTHttpsFWUpdate(topicOri, jsondata); MQTTHttpsFWUpdate(topicOri, jsondata);
# endif # endif
#endif #endif
digitalWrite(LED_SEND, LED_SEND_ON); digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
MQTTtoSYS(topicOri, jsondata); MQTTtoSYS(topicOri, jsondata);
} else { // not a json object --> simple decoding } else { // not a json object --> simple decoding
@@ -1734,6 +1743,8 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
# endif # endif
Log.warning(F("Starting firmware update" CR)); Log.warning(F("Starting firmware update" CR));
digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, LED_ERROR_ON);
# if defined(ZgatewayBT) && defined(ESP32) # if defined(ZgatewayBT) && defined(ESP32)
stopProcessing(); stopProcessing();
@@ -1806,6 +1817,9 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
break; break;
} }
digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, !LED_ERROR_ON);
# if defined(ZgatewayBT) && defined(ESP32) # if defined(ZgatewayBT) && defined(ESP32)
startProcessing(); startProcessing();
# endif # endif