Skip to content

Commit

Permalink
Publish ESP heap and temperature details on MQTT
Browse files Browse the repository at this point in the history
I noticed that some useful ESP stats are missing on the MQTT feed, so this adds:

- ESP temperature
- ESP heap stats (size, free, minFree, maxAlloc)
  • Loading branch information
ranma committed Sep 11, 2024
1 parent cec4003 commit 88119d3
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/heapSize", String(ESP.getHeapSize()));
MqttSettings.publish("dtu/heapFree", String(ESP.getFreeHeap()));
MqttSettings.publish("dtu/heapMinFree", String(ESP.getMinFreeHeap()));
MqttSettings.publish("dtu/heapMaxAlloc", 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", "heapSize");
publishDtuSensor("Heap Free", "", "diagnostic", "mdi:memory", "Bytes", "heapFree");
publishDtuSensor("Largest Free Heap Block", "", "diagnostic", "mdi:memory", "Bytes", "heapMaxAlloc`");
publishDtuSensor("Lifetime Minimum Free Heap", "", "diagnostic", "mdi:memory", "Bytes", "heapMinFree`");
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 88119d3

Please sign in to comment.