Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement error LED and status codes. #1006

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,33 +334,33 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
#endif

/*-------------DEFINE PINs FOR STATUS LEDs----------------*/
#ifndef LED_RECEIVE
#ifndef LED_SEND_RECEIVE
# ifdef ESP8266
# define LED_RECEIVE 40
# define LED_SEND_RECEIVE 40
# elif ESP32
# define LED_RECEIVE 40
# define LED_SEND_RECEIVE 40
# elif __AVR_ATmega2560__ //arduino mega
# define LED_RECEIVE 40
# define LED_SEND_RECEIVE 40
# else //arduino uno/nano
# define LED_RECEIVE 40
# define LED_SEND_RECEIVE 40
# endif
#endif
#ifndef LED_RECEIVE_ON
# define LED_RECEIVE_ON HIGH
#ifndef LED_SEND_RECEIVE_ON
# define LED_SEND_RECEIVE_ON HIGH
#endif
#ifndef LED_SEND
#ifndef LED_ERROR
# ifdef ESP8266
# define LED_SEND 42
# define LED_ERROR 42
# elif ESP32
# define LED_SEND 42
# define LED_ERROR 42
# elif __AVR_ATmega2560__ //arduino mega
# define LED_SEND 42
# define LED_ERROR 42
# else //arduino uno/nano
# define LED_SEND 42
# define LED_ERROR 42
# endif
#endif
#ifndef LED_SEND_ON
# define LED_SEND_ON HIGH
#ifndef LED_ERROR_ON
# define LED_ERROR_ON HIGH
#endif
#ifndef LED_INFO
# ifdef ESP8266
Expand Down
54 changes: 34 additions & 20 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {

void pub(const char* topicori, JsonObject& data) {
Log.notice(F("Subject: %s" CR), topicori);
digitalWrite(LED_RECEIVE, LED_RECEIVE_ON);
digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
logJson(data);
if (client.connected()) {
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
Expand Down Expand Up @@ -528,10 +528,10 @@ void connectMQTT() {
#elif defined(ESP8266)
Log.warning(F("failed, ssl error code=%d" CR), ((WiFiClientSecure*)eClient)->getLastSSLError());
#endif
digitalWrite(LED_INFO, LED_INFO_ON);
delay(1000);
digitalWrite(LED_INFO, !LED_INFO_ON);
delay(4000);
digitalWrite(LED_ERROR, LED_ERROR_ON);
delay(2000);
digitalWrite(LED_ERROR, !LED_ERROR_ON);
delay(5000);
}
}

Expand Down Expand Up @@ -563,6 +563,14 @@ void setup() {
Log.begin(LOG_LEVEL, &Serial);
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)
# ifdef ESP8266
# ifndef ZgatewaySRFB // if we are not in sonoff rf bridge case we apply the ESP8266 GPIO optimization
Expand Down Expand Up @@ -600,14 +608,6 @@ void setup() {
setup_ethernet();
#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 (mqtt_secure) {
eClient = new WiFiClientSecure;
Expand Down Expand Up @@ -819,6 +819,8 @@ void setOTA() {

ArduinoOTA.onStart([]() {
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)
stopProcessing();
# endif
Expand All @@ -828,6 +830,8 @@ void setOTA() {
});
ArduinoOTA.onEnd([]() {
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)
startProcessing();
# endif
Expand All @@ -839,6 +843,8 @@ void setOTA() {
Log.trace(F("Progress: %u%%\r" CR), (progress / (total / 100)));
});
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)
startProcessing();
# endif
Expand Down Expand Up @@ -1137,6 +1143,8 @@ void setup_wifimanager(bool reset_settings) {
}
# 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);
//fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name
Expand All @@ -1152,6 +1160,8 @@ void setup_wifimanager(bool reset_settings) {
# endif
delay(5000);
}
digitalWrite(LED_ERROR, !LED_ERROR_ON);
digitalWrite(LED_INFO, !LED_INFO_ON);
}

# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK)
Expand Down Expand Up @@ -1289,9 +1299,8 @@ void loop() {
// Switch off of the LED after TimeLedON
if (now > (timer_led_measures + (TimeLedON * 1000))) {
timer_led_measures = millis();
digitalWrite(LED_RECEIVE, !LED_RECEIVE_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)
Expand Down Expand Up @@ -1428,10 +1437,10 @@ void loop() {
}
} else { // disconnected from network
Log.warning(F("Network disconnected:" CR));
digitalWrite(LED_INFO, LED_INFO_ON);
delay(5000); // add a delay to avoid ESP32 crash and reset
digitalWrite(LED_INFO, !LED_INFO_ON);
delay(5000);
digitalWrite(LED_ERROR, LED_ERROR_ON);
delay(2000); // add a delay to avoid ESP32 crash and reset
digitalWrite(LED_ERROR, !LED_ERROR_ON);
delay(2000);
#if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET)
# ifdef ESP32 // If used with ESP8266 this method prevent the reconnection
WiFi.reconnect();
Expand Down Expand Up @@ -1663,7 +1672,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {
MQTTHttpsFWUpdate(topicOri, jsondata);
# endif
#endif
digitalWrite(LED_SEND, LED_SEND_ON);
digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);

MQTTtoSYS(topicOri, jsondata);
} else { // not a json object --> simple decoding
Expand Down Expand Up @@ -1734,6 +1743,8 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
# endif

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)
stopProcessing();
Expand Down Expand Up @@ -1806,6 +1817,9 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
break;
}

digitalWrite(LED_SEND_RECEIVE, !LED_SEND_RECEIVE_ON);
digitalWrite(LED_ERROR, !LED_ERROR_ON);

# if defined(ZgatewayBT) && defined(ESP32)
startProcessing();
# endif
Expand Down