Browse Source

Replace HEARTBEAT_ENABLED by HEARTBEAT_MDE allowing disable, single heartbeat on MQTT connect or repeat (default) (#1196)

ota
Xose Pérez 6 years ago
parent
commit
2b9a7341c3
4 changed files with 21 additions and 8 deletions
  1. +11
    -2
      code/espurna/config/general.h
  2. +1
    -1
      code/espurna/relay.ino
  3. +7
    -3
      code/espurna/system.ino
  4. +2
    -2
      code/espurna/utils.ino

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

@ -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


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

@ -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


+ 7
- 3
code/espurna/system.ino View File

@ -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


+ 2
- 2
code/espurna/utils.ino View File

@ -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


Loading…
Cancel
Save