From d97a09ba1fe042523e5c05a75c8c68d0ea2dbb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 4 Feb 2023 14:56:04 +0100 Subject: [PATCH] add DEBUG_HEAP_MQTT flag to send stats info to mqtt. Used to graph these values over time. Turned off for regular builds --- src/Power.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Power.cpp b/src/Power.cpp index 082c05181..f84c7b71d 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -7,6 +7,12 @@ #include "sleep.h" #include "utils.h" +#ifdef DEBUG_HEAP_MQTT +#include "mqtt/MQTT.h" +#include "target_specific.h" +#include +#endif + #ifdef HAS_PMU #include "XPowersAXP192.tpp" #include "XPowersAXP2101.tpp" @@ -311,6 +317,25 @@ void Power::readPowerStatus() ESP.getFreeHeap() - lastheap, running, concurrency::mainController.size(false)); lastheap = ESP.getFreeHeap(); } +#ifdef DEBUG_HEAP_MQTT + if (mqtt) { + // send MQTT-Packet with Heap-Size + uint8_t dmac[6]; + getMacAddr(dmac); // Get our hardware ID + char mac[18]; + sprintf(mac, "!%02x%02x%02x%02x", dmac[2], dmac[3], dmac[4], dmac[5]); + auto newHeap = ESP.getFreeHeap(); + std::string heapTopic = "msh/2/heap/" + std::string(mac); + std::string heapString = std::to_string(newHeap); + mqtt->pubSub.publish(heapTopic.c_str(), heapString.c_str(), false); + // auto fragHeap = ESP.getHeapFragmentation(); + auto wifiRSSI = WiFi.RSSI(); + heapTopic = "msh/2/wifi/" + std::string(mac); + std::string wifiString = std::to_string(wifiRSSI); + mqtt->pubSub.publish(heapTopic.c_str(), wifiString.c_str(), false); + } +#endif + #endif // If we have a battery at all and it is less than 10% full, force deep sleep if we have more than 3 low readings in a row