utils/heartbeat: fix hbReport=1 condition, add Bssid (#1995)

* hb: fix hbReport=1 condition, add Bssid

* type
This commit is contained in:
Max Prokhorov
2019-11-18 02:46:54 +03:00
committed by GitHub
parent f588893373
commit 7fa05d1bf4
2 changed files with 36 additions and 12 deletions

View File

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

View File

@@ -7,6 +7,7 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/
#include <Ticker.h>
#include <limits>
#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();
}
return strtoul(cfg.c_str(), NULL, 10);
// 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();
}
// 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<uint32_t>::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());