Browse Source

Option to cofigure ON/OFF payload at build time (#1085)

ech1560
Xose Pérez 6 years ago
parent
commit
0c65bfe36b
2 changed files with 11 additions and 3 deletions
  1. +8
    -0
      code/espurna/config/general.h
  2. +3
    -3
      code/espurna/relay.ino

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

@ -273,6 +273,14 @@
#define RELAY_SAVE_DELAY 1000 #define RELAY_SAVE_DELAY 1000
#endif #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 // WIFI
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 3
- 3
code/espurna/relay.ino View File

@ -718,7 +718,7 @@ void relayMQTT(unsigned char id) {
// Send state topic // Send state topic
if (_relays[id].report) { if (_relays[id].report) {
_relays[id].report = false; _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 // Check group topic
@ -728,7 +728,7 @@ void relayMQTT(unsigned char id) {
if (t.length() > 0) { if (t.length() > 0) {
bool status = relayStatus(id); bool status = relayStatus(id);
if (getSetting("mqttGroupInv", id, 0).toInt() == 1) status = !status; 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() { void relayMQTT() {
for (unsigned int id=0; id < _relays.size(); id++) { 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);
} }
} }


Loading…
Cancel
Save