diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index c264e5d7..985aae1a 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -165,8 +165,17 @@ // HEARTBEAT //------------------------------------------------------------------------------ -#ifndef HEARTBEAT_ENABLED -#define HEARTBEAT_ENABLED 1 +#define HEARTBEAT_NONE 0 // Never send heartbeat +#define HEARTBEAT_ONCE 1 // Send it only once upon MQTT connection +#define HEARTBEAT_REPEAT 2 // Send it upon MQTT connection and every HEARTBEAT_INTERVAL + +// Backwards compatibility check +#if defined(HEARTBEAT_ENABLED) && (HEARTBEAT_ENABLED == 0) +#define HEARTBEAT_MODE HEARTBEAT_NONE +#endif + +#ifndef HEARTBEAT_MODE +#define HEARTBEAT_MODE HEARTBEAT_REPEAT #endif #ifndef HEARTBEAT_INTERVAL diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 5371802f..3cfab0c9 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -766,7 +766,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (type == MQTT_CONNECT_EVENT) { // Send status on connect - #if not HEARTBEAT_REPORT_RELAY + #if (HEARTBEAT_MODE == HEARTBEAT_NONE) or (not HEARTBEAT_REPORT_RELAY) relayMQTT(); #endif diff --git a/code/espurna/system.ino b/code/espurna/system.ino index f858216b..c988c6cd 100644 --- a/code/espurna/system.ino +++ b/code/espurna/system.ino @@ -89,15 +89,19 @@ void systemLoop() { // Heartbeat // ------------------------------------------------------------------------- - #if HEARTBEAT_ENABLED - // Heartbeat + #if HEARTBEAT_MODE == HEARTBEAT_ONCE + if (_system_send_heartbeat) { + _system_send_heartbeat = false; + heartbeat(); + } + #elif HEARTBEAT_MODE == HEARTBEAT_REPEAT static unsigned long last_hbeat = 0; if (_system_send_heartbeat || (last_hbeat == 0) || (millis() - last_hbeat > HEARTBEAT_INTERVAL)) { _system_send_heartbeat = false; last_hbeat = millis(); heartbeat(); } - #endif // HEARTBEAT_ENABLED + #endif // HEARTBEAT_MODE == HEARTBEAT_REPEAT // ------------------------------------------------------------------------- // Load Average calculation diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index fc156f0d..4032c2b2 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -133,7 +133,7 @@ unsigned long getUptime() { } -#if HEARTBEAT_ENABLED +#if HEARTBEAT_MODE != HEARTBEAT_NONE void heartbeat() { @@ -235,7 +235,7 @@ void heartbeat() { } -#endif /// HEARTBEAT_ENABLED +#endif /// HEARTBEAT_MODE != HEARTBEAT_NONE // ----------------------------------------------------------------------------- // INFO