Add support for presenting status with 3 LEDs (#147)
* Add suport for presenting status with 3 LEDs * Add support for presenting status with 3 LEDs * Update Test_config.h * Update User_config.h Better names for LED variables * Change names for LED variables
This commit is contained in:
1 parent
87364e2897
commit
15cea6b222
3 files changed
+58
-5
No files matched your search
+43
-5
@@ -82,6 +82,11 @@ PubSubClient client(mqtt_server, mqtt_port, callback, eClient);
|
|||||||
//MQTT last attemps reconnection date
|
//MQTT last attemps reconnection date
|
||||||
unsigned long lastReconnectAttempt = 0;
|
unsigned long lastReconnectAttempt = 0;
|
||||||
|
|
||||||
|
//timers for LED indicators
|
||||||
|
unsigned long timer_led_receive = 0;
|
||||||
|
unsigned long timer_led_send = 0;
|
||||||
|
unsigned long timer_led_error = 0;
|
||||||
|
|
||||||
boolean reconnect() {
|
boolean reconnect() {
|
||||||
// Loop until we're reconnected
|
// Loop until we're reconnected
|
||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
@@ -179,6 +184,16 @@ void setup()
|
|||||||
Serial.begin(SERIAL_BAUD);
|
Serial.begin(SERIAL_BAUD);
|
||||||
//Begining ethernet connection in case of Arduino + W5100
|
//Begining ethernet connection in case of Arduino + W5100
|
||||||
setup_ethernet();
|
setup_ethernet();
|
||||||
|
//setup LED status, turn all ON for short amount then leave only the RED LED ON
|
||||||
|
pinMode(led_receive, OUTPUT);
|
||||||
|
pinMode(led_send, OUTPUT);
|
||||||
|
pinMode(led_error, OUTPUT);
|
||||||
|
digitalWrite(led_receive, LOW);
|
||||||
|
digitalWrite(led_send, LOW);
|
||||||
|
digitalWrite(led_error, LOW);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(led_receive, HIGH);
|
||||||
|
digitalWrite(led_send, HIGH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delay(1500);
|
delay(1500);
|
||||||
@@ -253,9 +268,12 @@ void setup_ethernet() {
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
unsigned long now = millis();
|
||||||
//MQTT client connexion management
|
//MQTT client connexion management
|
||||||
if (!client.connected()) { // not connected
|
if (!client.connected()) { // not connected
|
||||||
unsigned long now = millis();
|
//RED ON
|
||||||
|
digitalWrite(led_error, LOW);
|
||||||
|
|
||||||
if (now - lastReconnectAttempt > 5000) {
|
if (now - lastReconnectAttempt > 5000) {
|
||||||
lastReconnectAttempt = now;
|
lastReconnectAttempt = now;
|
||||||
// Attempt to reconnect
|
// Attempt to reconnect
|
||||||
@@ -265,6 +283,13 @@ void loop()
|
|||||||
}
|
}
|
||||||
} else { //connected
|
} else { //connected
|
||||||
// MQTT loop
|
// MQTT loop
|
||||||
|
//RED OFF
|
||||||
|
if (now - timer_led_receive > 300) {
|
||||||
|
timer_led_receive = now;
|
||||||
|
digitalWrite(led_receive, HIGH);
|
||||||
|
}
|
||||||
|
digitalWrite(led_error, HIGH);
|
||||||
|
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(ESP32)
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
@@ -291,21 +316,31 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
// Receive loop, if data received by RF433 or IR send it by MQTT
|
// Receive loop, if data received by RF433 or IR send it by MQTT
|
||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
if(RFtoMQTT())
|
if(RFtoMQTT()){
|
||||||
trc(F("RFtoMQTT OK"));
|
trc(F("RFtoMQTT OK"));
|
||||||
|
//GREEN ON
|
||||||
|
digitalWrite(led_receive, LOW);
|
||||||
|
timer_led_receive = millis();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayRF2
|
#ifdef ZgatewayRF2
|
||||||
if(RF2toMQTT())
|
if(RF2toMQTT()){
|
||||||
trc(F("RF2toMQTT OK"));
|
trc(F("RF2toMQTT OK"));
|
||||||
|
digitalWrite(led_receive, LOW);
|
||||||
|
timer_led_receive = millis();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewaySRFB
|
#ifdef ZgatewaySRFB
|
||||||
if(SRFBtoMQTT())
|
if(SRFBtoMQTT())
|
||||||
trc(F("SRFBtoMQTT OK"));
|
trc(F("SRFBtoMQTT OK"));
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayIR
|
#ifdef ZgatewayIR
|
||||||
if(IRtoMQTT())
|
if(IRtoMQTT()) {
|
||||||
trc(F("IRtoMQTT OK"));
|
trc(F("IRtoMQTT OK"));
|
||||||
|
digitalWrite(led_receive, LOW);
|
||||||
|
timer_led_receive = millis();
|
||||||
delay(100);
|
delay(100);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZgatewayBT
|
#ifdef ZgatewayBT
|
||||||
#ifndef ESP32
|
#ifndef ESP32
|
||||||
@@ -376,7 +411,8 @@ void receivingMQTT(char * topicOri, char * datacallback) {
|
|||||||
storeValue(data);
|
storeValue(data);
|
||||||
trc(F("Data stored"));
|
trc(F("Data stored"));
|
||||||
}
|
}
|
||||||
|
//YELLOW ON
|
||||||
|
digitalWrite(led_send, LOW);
|
||||||
#ifdef ZgatewayRF
|
#ifdef ZgatewayRF
|
||||||
MQTTtoRF(topicOri, datacallback);
|
MQTTtoRF(topicOri, datacallback);
|
||||||
#endif
|
#endif
|
||||||
@@ -392,6 +428,8 @@ void receivingMQTT(char * topicOri, char * datacallback) {
|
|||||||
#ifdef ZgatewayRFM69
|
#ifdef ZgatewayRFM69
|
||||||
MQTTtoRFM69(topicOri, datacallback);
|
MQTTtoRFM69(topicOri, datacallback);
|
||||||
#endif
|
#endif
|
||||||
|
//YELLOW OFF
|
||||||
|
digitalWrite(led_send, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extract_char(char * token_char, char * subset, int start ,int l, boolean reverse, boolean isNumber){
|
void extract_char(char * token_char, char * subset, int start ,int l, boolean reverse, boolean isNumber){
|
||||||
|
|||||||
@@ -64,6 +64,14 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define ota_password "OTAPASSWORD"
|
#define ota_password "OTAPASSWORD"
|
||||||
#define ota_port 8266
|
#define ota_port 8266
|
||||||
|
|
||||||
|
/*-------------DEFINE PINs FOR STATUS LEDs----------------*/
|
||||||
|
#define led_receive 40
|
||||||
|
#define led_send 42
|
||||||
|
#define led_error 44
|
||||||
|
|
||||||
|
// VCC ------------D|-----------/\/\/\/\ ----------------- Arduino PIN
|
||||||
|
// LED Resistor 270-510R
|
||||||
|
|
||||||
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
||||||
//Addons and module management, comment the Z line and the config file if you don't use
|
//Addons and module management, comment the Z line and the config file if you don't use
|
||||||
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
#ifdef ESP8266 // for nodemcu, weemos and esp8266
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
#define ota_hostname "OTAHOSTNAME"
|
#define ota_hostname "OTAHOSTNAME"
|
||||||
#define ota_password "OTAPASSWORD"
|
#define ota_password "OTAPASSWORD"
|
||||||
#define ota_port 8266
|
#define ota_port 8266
|
||||||
|
/*-------------DEFINE PINs FOR STATUS LEDs----------------*/
|
||||||
|
#define led_receive 40
|
||||||
|
#define led_send 42
|
||||||
|
#define led_error 44
|
||||||
|
|
||||||
|
// VCC ------------D|-----------/\/\/\/\ ----------------- Arduino PIN
|
||||||
|
// LED Resistor 270-510R
|
||||||
|
|
||||||
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
||||||
//Addons and module management, comment the Z line and the config file if you don't use
|
//Addons and module management, comment the Z line and the config file if you don't use
|
||||||
|
|||||||
Reference in new issue
Block a user