From 86cab0f28134b143f1b3400469c30b7b652ffc9d Mon Sep 17 00:00:00 2001 From: ranma Date: Fri, 13 Sep 2024 16:55:38 +0200 Subject: [PATCH] Feature: ESP heap and temperature details on MQTT and HASS (#1242) I noticed that some useful ESP stats are missing on the MQTT broker, so this adds: - ESP temperature - ESP heap stats (size, free, minFree, maxAlloc) --- src/MqttHandleDtu.cpp | 6 ++++++ src/MqttHandleHass.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/MqttHandleDtu.cpp b/src/MqttHandleDtu.cpp index e8192b2e2..6c8c38c8e 100644 --- a/src/MqttHandleDtu.cpp +++ b/src/MqttHandleDtu.cpp @@ -7,6 +7,7 @@ #include "MqttSettings.h" #include "NetworkSettings.h" #include +#include MqttHandleDtuClass MqttHandleDtu; @@ -34,6 +35,11 @@ void MqttHandleDtuClass::loop() MqttSettings.publish("dtu/uptime", String(millis() / 1000)); MqttSettings.publish("dtu/ip", NetworkSettings.localIP().toString()); MqttSettings.publish("dtu/hostname", NetworkSettings.getHostname()); + MqttSettings.publish("dtu/temperature", String(CpuTemperature.read())); + MqttSettings.publish("dtu/heap/size", String(ESP.getHeapSize())); + MqttSettings.publish("dtu/heap/free", String(ESP.getFreeHeap())); + MqttSettings.publish("dtu/heap/minfree", String(ESP.getMinFreeHeap())); + MqttSettings.publish("dtu/heap/maxalloc", String(ESP.getMaxAllocHeap())); if (NetworkSettings.NetworkMode() == network_mode::WiFi) { MqttSettings.publish("dtu/rssi", String(WiFi.RSSI())); MqttSettings.publish("dtu/bssid", WiFi.BSSIDstr()); diff --git a/src/MqttHandleHass.cpp b/src/MqttHandleHass.cpp index 87f1ccb9b..258a3cdce 100644 --- a/src/MqttHandleHass.cpp +++ b/src/MqttHandleHass.cpp @@ -61,6 +61,11 @@ void MqttHandleHassClass::publishConfig() publishDtuSensor("IP", "", "diagnostic", "mdi:network-outline", "", ""); publishDtuSensor("WiFi Signal", "signal_strength", "diagnostic", "", "dBm", "rssi"); publishDtuSensor("Uptime", "duration", "diagnostic", "", "s", ""); + publishDtuSensor("Temperature", "temperature", "diagnostic", "mdi:thermometer", "°C", "temperature"); + publishDtuSensor("Heap Size", "", "diagnostic", "mdi:memory", "Bytes", "heap/size"); + publishDtuSensor("Heap Free", "", "diagnostic", "mdi:memory", "Bytes", "heap/free"); + publishDtuSensor("Largest Free Heap Block", "", "diagnostic", "mdi:memory", "Bytes", "heap/maxalloc`"); + publishDtuSensor("Lifetime Minimum Free Heap", "", "diagnostic", "mdi:memory", "Bytes", "heap/minfree`"); publishDtuBinarySensor("Status", "connectivity", "diagnostic", config.Mqtt.Lwt.Value_Online, config.Mqtt.Lwt.Value_Offline, config.Mqtt.Lwt.Topic); yield();