|
@ -81,67 +81,88 @@ void heartbeat() { |
|
|
unsigned long uptime_seconds = getUptime(); |
|
|
unsigned long uptime_seconds = getUptime(); |
|
|
unsigned int free_heap = ESP.getFreeHeap(); |
|
|
unsigned int free_heap = ESP.getFreeHeap(); |
|
|
|
|
|
|
|
|
#if NTP_SUPPORT
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) ntpDateTime().c_str()); |
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// MQTT
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#if MQTT_SUPPORT
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_INTERVAL)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_APP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_APP, APP_NAME); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_VERSION)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_VERSION, APP_VERSION); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_HOSTNAME)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_IP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_IP, getIP().c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_MAC)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_RSSI)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_UPTIME)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_FREEHEAP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_RELAY)
|
|
|
|
|
|
relayMQTT(); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) & (HEARTBEAT_REPORT_LIGHT)
|
|
|
|
|
|
lightMQTT(); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_VCC)
|
|
|
|
|
|
#if ADC_VCC_ENABLED
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_STATUS)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true); |
|
|
|
|
|
#endif
|
|
|
|
|
|
bool serial = !mqttConnected(); |
|
|
|
|
|
#else
|
|
|
|
|
|
bool serial = true; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
if (!mqttConnected()) { |
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// Serial
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
if (serial) { |
|
|
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds); |
|
|
DEBUG_MSG_P(PSTR("[MAIN] Uptime: %ld seconds\n"), uptime_seconds); |
|
|
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap); |
|
|
DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), free_heap); |
|
|
#if ADC_VCC_ENABLED
|
|
|
#if ADC_VCC_ENABLED
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc()); |
|
|
DEBUG_MSG_P(PSTR("[MAIN] Power: %d mV\n"), ESP.getVcc()); |
|
|
#endif
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_INTERVAL)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_INTERVAL, HEARTBEAT_INTERVAL / 1000); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_APP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_APP, APP_NAME); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_VERSION)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_VERSION, APP_VERSION); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_HOSTNAME)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_HOSTNAME, getSetting("hostname").c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_IP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_IP, getIP().c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_MAC)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_MAC, WiFi.macAddress().c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_RSSI)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_RSSI, String(WiFi.RSSI()).c_str()); |
|
|
|
|
|
|
|
|
#if NTP_SUPPORT
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] Time: %s\n"), (char *) ntpDateTime().c_str()); |
|
|
#endif
|
|
|
#endif
|
|
|
#if (HEARTBEAT_REPORT_UPTIME)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); |
|
|
|
|
|
#if INFLUXDB_SUPPORT
|
|
|
|
|
|
idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// InfluxDB
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#if INFLUXDB_SUPPORT
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_UPTIME)
|
|
|
|
|
|
idbSend(MQTT_TOPIC_UPTIME, String(uptime_seconds).c_str()); |
|
|
#endif
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_FREEHEAP)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); |
|
|
|
|
|
#if INFLUXDB_SUPPORT
|
|
|
|
|
|
idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); |
|
|
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_FREEHEAP)
|
|
|
|
|
|
idbSend(MQTT_TOPIC_FREEHEAP, String(free_heap).c_str()); |
|
|
#endif
|
|
|
#endif
|
|
|
#endif
|
|
|
#endif
|
|
|
#if (HEARTBEAT_REPORT_RELAY)
|
|
|
|
|
|
relayMQTT(); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (LIGHT_PROVIDER != LIGHT_PROVIDER_NONE) & (HEARTBEAT_REPORT_LIGHT)
|
|
|
|
|
|
lightMQTT(); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_VCC)
|
|
|
|
|
|
#if ADC_VCC_ENABLED
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_VCC, String(ESP.getVcc()).c_str()); |
|
|
|
|
|
#endif
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#if (HEARTBEAT_REPORT_STATUS)
|
|
|
|
|
|
mqttSend(MQTT_TOPIC_STATUS, MQTT_STATUS_ONLINE, true); |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Send info to websocket clients
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
// WebSockets
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
#if WEB_SUPPORT
|
|
|
#if WEB_SUPPORT
|
|
|
#if NTP_SUPPORT
|
|
|
#if NTP_SUPPORT
|
|
|
{ |
|
|
{ |
|
|