From 2c2745a120edd840cd80c80cca31e4cf37498ea6 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:00:45 +0200 Subject: [PATCH 1/7] Update pubMqtt.h --- src/publisher/pubMqtt.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 6e021bed..b497e8fa 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -158,6 +158,7 @@ class PubMqtt { publish(subtopics[MQTT_UPTIME], mVal.data()); publish(subtopics[MQTT_RSSI], String(WiFi.RSSI()).c_str()); publish(subtopics[MQTT_FREE_HEAP], String(ESP.getFreeHeap()).c_str()); + publish(subtopics[MQTT_TEMP_SENS_C], String(ah::readTemperature()).c_str()); #ifndef ESP32 publish(subtopics[MQTT_HEAP_FRAG], String(ESP.getHeapFragmentation()).c_str()); #endif From 571260b2de853b42fa5dcb7c3750527f9665d1cd Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:01:45 +0200 Subject: [PATCH 2/7] Update pubMqttDefs.h --- src/publisher/pubMqttDefs.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/publisher/pubMqttDefs.h b/src/publisher/pubMqttDefs.h index c97daa78..c903f92e 100644 --- a/src/publisher/pubMqttDefs.h +++ b/src/publisher/pubMqttDefs.h @@ -56,7 +56,8 @@ enum { MQTT_STATUS, MQTT_LWT_ONLINE, MQTT_LWT_OFFLINE, - MQTT_ACK_PWR_LMT + MQTT_ACK_PWR_LMT, + MQTT_TEMP_SENS_C }; const char* const subtopics[] PROGMEM = { @@ -76,7 +77,8 @@ const char* const subtopics[] PROGMEM = { "status", "connected", "not_connected", - "ack_pwr_limit" + "ack_pwr_limit", + "temp_sensor_c" }; enum { From ff8888ff38d3c8325d3b24205f4dd09f7fa9b09d Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:02:50 +0200 Subject: [PATCH 3/7] Update helper.cpp --- src/utils/helper.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index edb9b9b9..a692f9ea 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -3,6 +3,7 @@ // Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ //----------------------------------------------------------------------------- +#include #include "helper.h" #include "dbg.h" #include "../plugins/plugin_lang.h" @@ -142,4 +143,22 @@ namespace ah { } DBGPRINTLN(""); } + +#if defined(ESP32) + float readTemperature() { + /*// ADC1 channel 0 is GPIO36 + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0); + int adc_reading = adc1_get_raw(ADC1_CHANNEL_0); + // Convert the raw ADC reading to a voltage in mV + esp_adc_cal_characteristics_t characteristics; + esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_0, ADC_WIDTH_BIT_12, 1100, &characteristics); + uint32_t voltage = esp_adc_cal_raw_to_voltage(adc_reading, &characteristics); + // Convert the voltage to a temperature in Celsius + // This formula is an approximation and might need to be calibrated for your specific use case. + float temperature = (voltage - 500) / 10.0;*/ + + return temperatureRead(); + } +#endif } From 695496b6e9af3cb33fa29270f5ffacd235551fa4 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:03:28 +0200 Subject: [PATCH 4/7] Update helper.h --- src/utils/helper.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/helper.h b/src/utils/helper.h index ff1a9aed..6344d06b 100644 --- a/src/utils/helper.h +++ b/src/utils/helper.h @@ -49,6 +49,10 @@ namespace ah { String getTimeStrMs(uint64_t t); uint64_t Serial2u64(const char *val); void dumpBuf(uint8_t buf[], uint8_t len, uint8_t firstRepl = 0, uint8_t lastRepl = 0); + + #if defined(ESP32) + float readTemperature(); + #endif } #endif /*__HELPER_H__*/ From 0692e311a7e3704e0ff74f43fb8e4ea80f9d4684 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:04:23 +0200 Subject: [PATCH 5/7] Update RestApi.h --- src/web/RestApi.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 7e7971e4..cb846fb5 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -878,6 +878,8 @@ class RestApi { obj[F("par_size_app0")] = ESP.getFreeSketchSpace(); obj[F("par_used_app0")] = ESP.getSketchSize(); + obj[F("temp_sensor_c")] = ah::readTemperature(); + #if defined(ESP32) obj[F("heap_total")] = ESP.getHeapSize(); From 240d0c51edeeafe7a71ffdd0f48ec4adc06dc7b0 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 18:06:59 +0200 Subject: [PATCH 6/7] Update system.html --- src/web/html/system.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/web/html/system.html b/src/web/html/system.html index c7e74ef3..407de425 100644 --- a/src/web/html/system.html +++ b/src/web/html/system.html @@ -44,7 +44,8 @@ tr("{#ENVIRONMENT}", obj.generic.env + " ({#BUILD_OPTIONS}: " + obj.generic.modules + ")"), tr("Version", obj.generic.version + " - " + obj.generic.build), tr("Chip", "CPU: " + obj.chip.cpu_freq + "MHz, " + obj.chip.cores + " Core(s)"), - tr("Chip Model", obj.chip.model) + tr("Chip Model", obj.chip.model), + tr("Chip temp.", obj.chip.temp_sensor_c), ] document.getElementById("info").append( From fe13a649321417cd5679c28c7d566f2d7442b933 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Fri, 23 Aug 2024 20:30:22 +0200 Subject: [PATCH 7/7] fix Systeminfo --- src/web/RestApi.h | 4 ++-- src/web/html/system.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/web/RestApi.h b/src/web/RestApi.h index cb846fb5..b3d9df1f 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -822,6 +822,8 @@ class RestApi { void getChipInfo(JsonObject obj) { obj[F("cpu_freq")] = ESP.getCpuFreqMHz(); obj[F("sdk")] = ESP.getSdkVersion(); + obj[F("temp_sensor_c")] = ah::readTemperature(); + #if defined(ESP32) obj[F("revision")] = ESP.getChipRevision(); obj[F("model")] = ESP.getChipModel(); @@ -878,8 +880,6 @@ class RestApi { obj[F("par_size_app0")] = ESP.getFreeSketchSpace(); obj[F("par_used_app0")] = ESP.getSketchSize(); - obj[F("temp_sensor_c")] = ah::readTemperature(); - #if defined(ESP32) obj[F("heap_total")] = ESP.getHeapSize(); diff --git a/src/web/html/system.html b/src/web/html/system.html index 407de425..daaa5e05 100644 --- a/src/web/html/system.html +++ b/src/web/html/system.html @@ -45,7 +45,7 @@ tr("Version", obj.generic.version + " - " + obj.generic.build), tr("Chip", "CPU: " + obj.chip.cpu_freq + "MHz, " + obj.chip.cores + " Core(s)"), tr("Chip Model", obj.chip.model), - tr("Chip temp.", obj.chip.temp_sensor_c), + tr("Chip temp.", obj.chip.temp_sensor_c + "°C"), ] document.getElementById("info").append(