diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index c880a333..2a1c9a95 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -9,7 +9,6 @@ #define SERIAL_BAUDRATE 115200 // Debugging console boud rate #define HOSTNAME DEVICE // Hostname -#define HEARTBEAT_INTERVAL 300000 // Report status every 5 minutes #define UPTIME_OVERFLOW 4294967295 // Uptime overflow value //-------------------------------------------------------------------------------- @@ -36,6 +35,27 @@ #define EEPROM_CUSTOM_RESET 5 // Address for the reset reason (1 byte) #define EEPROM_DATA_END 6 // End of custom EEPROM data block +//-------------------------------------------------------------------------------- +// HEARTBEAT +//-------------------------------------------------------------------------------- + +#define HEARTBEAT_INTERVAL 300000 // Interval between heartbeat messages (in ms) + +// Topics that will be reported in heartbeat +#define HEARTBEAT_REPORT_STATUS 1 +#define HEARTBEAT_REPORT_IP 1 +#define HEARTBEAT_REPORT_MAC 1 +#define HEARTBEAT_REPORT_RSSI 1 +#define HEARTBEAT_REPORT_UPTIME 1 +#define HEARTBEAT_REPORT_FREEHEAP 1 +#define HEARTBEAT_REPORT_VCC 1 +#define HEARTBEAT_REPORT_RELAY 1 +#define HEARTBEAT_REPORT_COLOR 1 +#define HEARTBEAT_REPORT_HOSTNAME 1 +#define HEARTBEAT_REPORT_APP 1 +#define HEARTBEAT_REPORT_VERSION 1 +#define HEARTBEAT_REPORT_INTERVAL 0 + //-------------------------------------------------------------------------------- // RESET //-------------------------------------------------------------------------------- @@ -227,21 +247,6 @@ PROGMEM const char* const custom_reset_string[] = { #define MQTT_TOPIC_TIME "time" #define MQTT_TOPIC_ANALOG "analog" -// These massages will be reported on heartbeat -#define MQTT_REPORT_STATUS 1 -#define MQTT_REPORT_IP 1 -#define MQTT_REPORT_MAC 1 -#define MQTT_REPORT_RSSI 1 -#define MQTT_REPORT_UPTIME 1 -#define MQTT_REPORT_FREEHEAP 1 -#define MQTT_REPORT_VCC 1 -#define MQTT_REPORT_RELAY 1 -#define MQTT_REPORT_COLOR 1 -#define MQTT_REPORT_HOSTNAME 1 -#define MQTT_REPORT_APP 1 -#define MQTT_REPORT_VERSION 1 -#define MQTT_REPORT_INTERVAL 0 - #define MQTT_STATUS_ONLINE "1" // Value for the device ON message #define MQTT_STATUS_OFFLINE "0" // Value for the device OFF message (will) @@ -255,7 +260,7 @@ PROGMEM const char* const custom_reset_string[] = { // Custom get and set postfixes // Use something like "/status" or "/set", with leading slash #define MQTT_USE_GETTER "" -#define MQTT_USE_SETTER "" +#define MQTT_USE_SETTER "/set" // ----------------------------------------------------------------------------- // I2C diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index e044085c..3ff54f9d 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -52,53 +52,53 @@ void heartbeat() { } - #if (MQTT_REPORT_INTERVAL) + #if (HEARTBEAT_REPORT_INTERVAL) mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000); #endif - #if (MQTT_REPORT_APP) + #if (HEARTBEAT_REPORT_APP) mqttSend(MQTT_TOPIC_APP, APP_NAME); #endif - #if (MQTT_REPORT_VERSION) + #if (HEARTBEAT_REPORT_VERSION) mqttSend(MQTT_TOPIC_VERSION, APP_VERSION); #endif - #if (MQTT_REPORT_HOSTNAME) + #if (HEARTBEAT_REPORT_HOSTNAME) mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str()); #endif - #if (MQTT_REPORT_IP) + #if (HEARTBEAT_REPORT_IP) mqttSend(MQTT_TOPIC_IP, getIP().c_str()); #endif - #if (MQTT_REPORT_MAC) + #if (HEARTBEAT_REPORT_MAC) mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str()); #endif - #if (MQTT_REPORT_RSSI) + #if (HEARTBEAT_REPORT_RSSI) mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str()); #endif - #if (MQTT_REPORT_UPTIME) + #if (HEARTBEAT_REPORT_UPTIME) mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); #if ENABLE_INFLUXDB influxDBSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); #endif #endif - #if (MQTT_REPORT_FREEHEAP) + #if (HEARTBEAT_REPORT_FREEHEAP) mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); #if ENABLE_INFLUXDB influxDBSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); #endif #endif - #if (MQTT_REPORT_RELAY) + #if (HEARTBEAT_REPORT_RELAY) relayMQTT(); #endif #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE - #if (MQTT_REPORT_COLOR) + #if (HEARTBEAT_REPORT_COLOR) mqttSend(MQTT_TOPIC_COLOR, lightColor().c_str()); #endif #endif - #if (MQTT_REPORT_VCC) + #if (HEARTBEAT_REPORT_VCC) #if ENABLE_ADC_VCC mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str()); #endif #endif - #if (MQTT_REPORT_STATUS) + #if (HEARTBEAT_REPORT_STATUS) mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true); #endif diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index b80d54ad..88f636c4 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -403,7 +403,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (type == MQTT_CONNECT_EVENT) { - #if not MQTT_REPORT_RELAY + #if not HEARTBEAT_REPORT_RELAY relayMQTT(); #endif