Browse Source

Reset relays on MQTT disconnection

With option #define MQTT_DISCONNECT_RELAY_DEFAULT set to 1, all relays
will be reset in case of MQTT disconnection to avoid a connected device
being switched on while MQTT is not under broker control any more.
rfm69
Thomas Staerk 6 years ago
parent
commit
4c39202848
2 changed files with 13 additions and 0 deletions
  1. +2
    -0
      code/espurna/config/general.h
  2. +11
    -0
      code/espurna/relay.ino

+ 2
- 0
code/espurna/config/general.h View File

@ -513,6 +513,8 @@ PROGMEM const char* const custom_reset_string[] = {
#define MQTT_USE_JSON_DELAY 100 // Wait this many ms before grouping messages
#define MQTT_QUEUE_MAX_SIZE 10 // Size of the MQTT queue when MQTT_USE_JSON is enabled
#define MQTT_DISCONNECT_RELAY_DEFAULT 1 // 0 - do nothing, 1 - reset relays to OFF in case of MQTT disconnection
// These are the properties that will be sent when useJson is true
#ifndef MQTT_ENQUEUE_IP
#define MQTT_ENQUEUE_IP 1


+ 11
- 0
code/espurna/relay.ino View File

@ -654,6 +654,17 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo
}
if (type == MQTT_DISCONNECT_EVENT)
{
if (MQTT_DISCONNECT_RELAY_DEFAULT == 1){
for (unsigned int i=0; i < _relays.size(); i++){
DEBUG_MSG_P(PSTR("[RELAY] Reset relay (%d) due to MQTT disconnection\n"), i);
relayStatusWrap(i, false, false);
}
}
}
}
void relaySetupMQTT() {


Loading…
Cancel
Save