values: Include boot count in state messages

This should be useful for diagnostic purposes.  It's not brought out
into a proper sensor in HA, but it can be seen using the MQTT message
viewer in the HA device configuration tool.
master
Dustin 2022-05-16 20:45:44 -05:00
parent 6c1757b43d
commit 38df5d00c4
3 changed files with 5 additions and 1 deletions

View File

@ -52,6 +52,7 @@ void setup() {
reboot();
}
values.boot_count = boot_count;
if (!values.read(&ss)) {
auto msg = "Failed to get sensor values";
Serial.println(msg);
@ -63,6 +64,7 @@ void setup() {
Serial.printf(" Temperature: %.02f\n", values.temperature);
Serial.printf(" Battery: %.02f\n", values.battery);
Serial.printf(" RSSI: %d\n", values.rssi);
Serial.printf(" Boot Count: %d\n", values.boot_count);
if (!values.send(&mqtt, TOPIC_STATE)) {
Serial.println("Failed to send sensor values");
}

View File

@ -16,11 +16,12 @@ bool Values::read(Adafruit_seesaw* ss) {
}
bool Values::send(PubSubClient* mqtt, const char* topic) {
StaticJsonDocument<64> doc;
StaticJsonDocument<96> doc;
doc["moisture"] = moisture;
doc["temperature"] = round2(temperature);
doc["battery_level"] = round2(battery);
doc["rssi"] = rssi;
doc["boot_count"] = boot_count;
String msg;
serializeJson(doc, msg);

View File

@ -7,6 +7,7 @@ class Values {
float temperature;
float battery;
int8_t rssi;
uint32_t boot_count;
Values() {};
~Values() {};