diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 4795303e..08af47b5 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -299,16 +299,16 @@ #define HEARTBEAT_REPORT_INTERVAL 0 #endif -#if THERMOSTAT_SUPPORT && ! defined HEARTBEAT_REPORT_RANGE -#define HEARTBEAT_REPORT_RANGE 1 -#else -#define HEARTBEAT_REPORT_RANGE 0 +#ifndef HEARTBEAT_REPORT_RANGE +#define HEARTBEAT_REPORT_RANGE THERMOSTAT_SUPPORT #endif -#if THERMOSTAT_SUPPORT && ! defined HEARTBEAT_REPORT_REMOTE_TEMP -#define HEARTBEAT_REPORT_REMOTE_TEMP 1 -#else -#define HEARTBEAT_REPORT_REMOTE_TEMP 0 +#ifndef HEARTBEAT_REPORT_REMOTE_TEMP +#define HEARTBEAT_REPORT_REMOTE_TEMP THERMOSTAT_SUPPORT +#endif + +#ifndef HEARTBEAT_REPORT_BSSID +#define HEARTBEAT_REPORT_BSSID 0 #endif //------------------------------------------------------------------------------ @@ -1047,6 +1047,7 @@ #define MQTT_TOPIC_BUTTON "button" #define MQTT_TOPIC_IP "ip" #define MQTT_TOPIC_SSID "ssid" +#define MQTT_TOPIC_BSSID "bssid" #define MQTT_TOPIC_VERSION "version" #define MQTT_TOPIC_UPTIME "uptime" #define MQTT_TOPIC_DATETIME "datetime" diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index 688dd23f..d710f42b 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -7,6 +7,7 @@ Copyright (C) 2017-2019 by Xose PĂ©rez */ #include +#include #include "libs/HeapStats.h" String getIdentifier() { @@ -135,6 +136,7 @@ bool haveRelaysOrSensors() { // Heartbeat helper // ----------------------------------------------------------------------------- namespace Heartbeat { + enum Report : uint32_t { Status = 1 << 1, Ssid = 1 << 2, @@ -155,7 +157,8 @@ namespace Heartbeat { Interval = 1 << 17, Description = 1 << 18, Range = 1 << 19, - Remote_temp = 1 << 20 + RemoteTemp = 1 << 20, + Bssid = 1 << 21 }; constexpr uint32_t defaultValue() { @@ -178,14 +181,31 @@ namespace Heartbeat { (Loadavg * (HEARTBEAT_REPORT_LOADAVG)) | \ (Interval * (HEARTBEAT_REPORT_INTERVAL)) | \ (Range * (HEARTBEAT_REPORT_RANGE)) | \ - (Remote_temp * (HEARTBEAT_REPORT_REMOTE_TEMP)); + (RemoteTemp * (HEARTBEAT_REPORT_REMOTE_TEMP)) | \ + (Bssid * (HEARTBEAT_REPORT_BSSID)); } uint32_t currentValue() { + // use default without any setting / when it is empty const String cfg = getSetting("hbReport"); - if (!cfg.length()) return defaultValue(); + if (!cfg.length()) { + return defaultValue(); + } + + // invalidate the whole string when invalid chars are detected + char *value_endptr = nullptr; + const auto value = strtoul(cfg.c_str(), &value_endptr, 10); + if (value_endptr) { + return defaultValue(); + } - return strtoul(cfg.c_str(), NULL, 10); + // because we start shifting from 1, we could use the + // first bit as a flag to enable all of the messages + if (value == 1) { + return std::numeric_limits::max(); + } + + return value; } } @@ -253,6 +273,9 @@ void heartbeat() { if (hb_cfg & Heartbeat::Ssid) mqttSend(MQTT_TOPIC_SSID, WiFi.SSID().c_str()); + if (hb_cfg & Heartbeat::Bssid) + mqttSend(MQTT_TOPIC_BSSID, WiFi.BSSIDstr().c_str()); + if (hb_cfg & Heartbeat::Ip) mqttSend(MQTT_TOPIC_IP, getIP().c_str());