From 53214097279c7f7a2f8444c797ad0ccf7cab6fac Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 30 May 2019 13:09:38 +0200 Subject: [PATCH] Added support for reporting for freeHeap via MQTT. --- include/my_mqtt.h | 2 ++ src/mqtt.cpp | 8 ++++++++ src/pitrix.cpp | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/my_mqtt.h b/include/my_mqtt.h index 973172b..6c4261f 100644 --- a/include/my_mqtt.h +++ b/include/my_mqtt.h @@ -12,4 +12,6 @@ void mqtt_setup(); void mqtt_loop(); +void mqtt_publish(const char* topic, int number); + #endif // mqtt_H diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 0a25415..cd24519 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -69,3 +69,11 @@ void mqtt_loop() { mqtt_client.loop(); } } + +void mqtt_publish(const char* topic, int number) { + char t[127]; + sprintf(t, MQTT_TOPIC "%s", topic); + char b[32]; + sprintf(b, "%d", number); + mqtt_client.publish(t, b); +} diff --git a/src/pitrix.cpp b/src/pitrix.cpp index c51f5b6..f01aeb0 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -68,6 +68,12 @@ void loop() { FastLED.show(); } + EVERY_N_SECONDS(5) { + if (REPORT_FREE_HEAP) { + mqtt_publish("free_heap", ESP.getFreeHeap()); + } + } + if (MONITOR_LOOP_TIMES && millis()-loop_started_at>=MONITOR_LOOP_TIME_THRESHOLD) { LOG("Core * Loop took "); LOG(millis()-loop_started_at); LOGln("ms.");