From 0c65bfe36b8b1ed23c971c59bc186fa48f9980db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 13 Aug 2018 13:10:52 +0200 Subject: [PATCH] Option to cofigure ON/OFF payload at build time (#1085) --- code/espurna/config/general.h | 8 ++++++++ code/espurna/relay.ino | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 7c1725d9..6e2f236c 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -273,6 +273,14 @@ #define RELAY_SAVE_DELAY 1000 #endif +// Configure the MQTT payload for ON/OFF +#ifndef RELAY_MQTT_ON +#define RELAY_MQTT_ON "1" +#endif +#ifndef RELAY_MQTT_OFF +#define RELAY_MQTT_OFF "0" +#endif + // ----------------------------------------------------------------------------- // WIFI // ----------------------------------------------------------------------------- diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 384679c0..05c7aea6 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -718,7 +718,7 @@ void relayMQTT(unsigned char id) { // Send state topic if (_relays[id].report) { _relays[id].report = false; - mqttSend(MQTT_TOPIC_RELAY, id, _relays[id].current_status ? "1" : "0"); + mqttSend(MQTT_TOPIC_RELAY, id, _relays[id].current_status ? RELAY_MQTT_ON : RELAY_MQTT_OFF); } // Check group topic @@ -728,7 +728,7 @@ void relayMQTT(unsigned char id) { if (t.length() > 0) { bool status = relayStatus(id); if (getSetting("mqttGroupInv", id, 0).toInt() == 1) status = !status; - mqttSendRaw(t.c_str(), status ? "1" : "0"); + mqttSendRaw(t.c_str(), status ? RELAY_MQTT_ON : RELAY_MQTT_OFF); } } @@ -743,7 +743,7 @@ void relayMQTT(unsigned char id) { void relayMQTT() { for (unsigned int id=0; id < _relays.size(); id++) { - mqttSend(MQTT_TOPIC_RELAY, id, _relays[id].current_status ? "1" : "0"); + mqttSend(MQTT_TOPIC_RELAY, id, _relays[id].current_status ? RELAY_MQTT_ON : RELAY_MQTT_OFF); } }