Skip to content

Commit

Permalink
Feature: ESP heap and temperature details on MQTT and HASS (#1242)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ranma authored Sep 13, 2024
1 parent 89d9a40 commit 86cab0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/MqttHandleDtu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "MqttSettings.h"
#include "NetworkSettings.h"
#include <Hoymiles.h>
#include <CpuTemperature.h>

MqttHandleDtuClass MqttHandleDtu;

Expand Down Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions src/MqttHandleHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 86cab0f

Please sign in to comment.