Skip to content

Commit

Permalink
Merge pull request #2360 from proddy/dev
Browse files Browse the repository at this point in the history
implement CPU temp for ESP32
  • Loading branch information
proddy authored Jan 18, 2025
2 parents eab94f3 + 9a7f7fa commit 01793dd
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For more details go to [docs.emsesp.org](https://docs.emsesp.org/).
- thermostat `reduce threshold` [#2288](https://github.com/emsesp/EMS-ESP32/issues/2288)
- thermostat `absent` [#1957](https://github.com/emsesp/EMS-ESP32/issues/1957)
- CR11 thermostat [#2295](https://github.com/emsesp/EMS-ESP32/issues/2295)
- Show ESP32's CPU temp in Hardware Status

## Fixed

Expand Down
2 changes: 1 addition & 1 deletion interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-icons": "^5.4.0",
"react-router": "^7.1.2",
"react-router": "^7.1.3",
"react-toastify": "^11.0.3",
"typesafe-i18n": "^5.26.2",
"typescript": "^5.7.3"
Expand Down
8 changes: 7 additions & 1 deletion interface/src/app/status/HardwareStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ const HardwareStatus = () => {
' @ ' +
data.cpu_freq_mhz +
' Mhz' +
(data.temperature ? ', T: ' + data.temperature + ' °C' : '')
// bit of a hack : if the CPU temp is higher than 90 (=32 Fahrenheit if using Celsius), show F, otherwise C
(data.temperature
? ', T: ' +
data.temperature +
' °' +
(data.temperature > 90 ? 'F' : 'C')
: '')
}
/>
</ListItem>
Expand Down
2 changes: 1 addition & 1 deletion interface/src/i18n/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const de: Translation = {
DEVELOPER_MODE: 'Entwicklermodus',
DUPLICATE: 'Kopieren',
UPGRADE: 'Aktualisieren',
DASHBOARD_1: 'All EMS entities that are active and marked as Favorite, plus all Custom Entities, Schedules and external Sensors data are displayed below.', // TODO translate
DASHBOARD_1: 'Alle EMS-Entitäten, die aktiv und als Favorit markiert sind, sowie alle benutzerdefinierten Entitäten, Zeitpläne und externen Sensordaten werden unten angezeigt.',
NO_DATA_1: 'Keine favorisierten EMS-Entitäten gefunden! Verwenden Sie das Modul',
NO_DATA_2: ', um sie zu markieren.',
NO_DATA_3: 'Um alle verfügbaren Entitäten anzuzeigen, gehen Sie zu'
Expand Down
10 changes: 5 additions & 5 deletions interface/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ __metadata:
react: "npm:^19.0.0"
react-dom: "npm:^19.0.0"
react-icons: "npm:^5.4.0"
react-router: "npm:^7.1.2"
react-router: "npm:^7.1.3"
react-toastify: "npm:^11.0.3"
rollup-plugin-visualizer: "npm:^5.14.0"
terser: "npm:^5.37.0"
Expand Down Expand Up @@ -5607,9 +5607,9 @@ __metadata:
languageName: node
linkType: hard

"react-router@npm:^7.1.2":
version: 7.1.2
resolution: "react-router@npm:7.1.2"
"react-router@npm:^7.1.3":
version: 7.1.3
resolution: "react-router@npm:7.1.3"
dependencies:
"@types/cookie": "npm:^0.6.0"
cookie: "npm:^1.0.1"
Expand All @@ -5621,7 +5621,7 @@ __metadata:
peerDependenciesMeta:
react-dom:
optional: true
checksum: 10c0/f2ef57c8c95cfee0c0689cbcb9a28ebbc5a554831b9e8f9d0295f4c6ac0960a448e16b828dd75168b4e8da228068c99d88248be3418467d6a76ab4ea02bf0d71
checksum: 10c0/f42f7b245533d1adaa00779a0287993a836d5b56039d97a6643a8b3a721ffb92ff47c97cfb36409fec8794ac3c8a884339f588cf21fcd7f6dccdfc834520c76f
languageName: node
linkType: hard

Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ platform = [email protected] ; Arduino Core 2.0.18 / IDF 4.4.8
framework = arduino
board_build.partitions = partitions/esp32_partition_4M.csv
board_upload.flash_size = 4MB
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.06.00/platform-espressif32.zip ; Arduino Core 2.0.18 with IPv6 support, based on IDF 4.4.8
; platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.12.30/platform-espressif32.zip ; Arduino Core 3.1.0.241206 based on IDF 5.3.2
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.06.00/platform-espressif32.zip ; Arduino Core 2.0.18 with IPv6 support, based on IDF 4.4.8
; platform = https://github.com/tasmota/platform-espressif32/releases/download/2025.01.31/platform-espressif32.zip ; Arduino Core 3.1.1, based on IDF 5.3.2

; use Tasmota's library for 16MB Flash variants.
; Removes libs (like mbedtsl, so no WiFi_secure.h) to increase available heap
Expand Down
2 changes: 1 addition & 1 deletion src/core/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ char * Helpers::hextoa(char * result, const uint8_t value) {
return result;
}

// same as above but to a hex string
// same as hextoa but uses to a hex std::string
std::string Helpers::hextoa(const uint8_t value, bool prefix) {
char buf[3];
if (prefix) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Helpers {
static uint16_t string2minutes(const std::string & str);
static float numericoperator2scalefactor(int8_t numeric_operator);

static double transformNumFloat(double value, const int8_t numeric_operator, const uint8_t fahrenheit = 0);
static double transformNumFloat(double value, const int8_t numeric_operator = 0, const uint8_t fahrenheit = 0);

static std::string toLower(std::string const & s);
static std::string toUpper(std::string const & s);
Expand Down
5 changes: 4 additions & 1 deletion src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,10 @@ void System::system_check() {
last_system_check_ = uuid::get_uptime();

#ifndef EMSESP_STANDALONE
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#if defined(CONFIG_IDF_TARGET_ESP32)
uint8_t raw = temprature_sens_read();
temperature_ = (raw - 32) / 1.8f; // convert to Celsius
#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#if ESP_IDF_VERSION_MAJOR < 5
temp_sensor_read_celsius(&temperature_);
#else
Expand Down
11 changes: 8 additions & 3 deletions src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
#include <uuid/log.h>
#include <PButton.h>

#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#if defined(CONFIG_IDF_TARGET_ESP32)
// there is no official API available on the original ESP32
extern "C" {
uint8_t temprature_sens_read();
}
#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#if ESP_IDF_VERSION_MAJOR < 5
#include "driver/temp_sensor.h"
#else
Expand Down Expand Up @@ -331,7 +336,7 @@ class System {
test_set_all_active_ = n;
}

#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32
float temperature() {
return temperature_;
}
Expand Down Expand Up @@ -435,8 +440,8 @@ class System {
#if ESP_IDF_VERSION_MAJOR >= 5
temperature_sensor_handle_t temperature_handle_ = NULL;
#endif
float temperature_ = 0;
#endif
float temperature_ = 0;
};

} // namespace emsesp
Expand Down
10 changes: 5 additions & 5 deletions src/web/WebCustomEntityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,33 +517,33 @@ void WebCustomEntityService::generate_value_web(JsonObject output, const bool is
}
case DeviceValueType::INT8:
if ((int8_t)entity.value != EMS_VALUE_INT8_NOTSET) {
obj["v"] = Helpers::transformNumFloat(entity.factor * (int8_t)entity.value, 0);
obj["v"] = Helpers::transformNumFloat(entity.factor * (int8_t)entity.value);
include = true;
}
break;
case DeviceValueType::UINT8:
if ((uint8_t)entity.value != EMS_VALUE_UINT8_NOTSET) {
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint8_t)entity.value, 0);
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint8_t)entity.value);
include = true;
}
break;
case DeviceValueType::INT16:
if ((int16_t)entity.value != EMS_VALUE_INT16_NOTSET) {
obj["v"] = Helpers::transformNumFloat(entity.factor * (int16_t)entity.value, 0);
obj["v"] = Helpers::transformNumFloat(entity.factor * (int16_t)entity.value);
include = true;
}
break;
case DeviceValueType::UINT16:
if ((uint16_t)entity.value != EMS_VALUE_UINT16_NOTSET) {
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint16_t)entity.value, 0);
obj["v"] = Helpers::transformNumFloat(entity.factor * (uint16_t)entity.value);
include = true;
}
break;
case DeviceValueType::UINT24:
case DeviceValueType::TIME:
case DeviceValueType::UINT32:
if (entity.value != EMS_VALUE_UINT24_NOTSET) {
obj["v"] = Helpers::transformNumFloat(entity.factor * entity.value, 0);
obj["v"] = Helpers::transformNumFloat(entity.factor * entity.value);
include = true;
}
break;
Expand Down
8 changes: 4 additions & 4 deletions src/web/WebDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void WebDataService::sensor_data(AsyncWebServerRequest * request) {
obj["t"] = sensor.type();

if (sensor.type() != AnalogSensor::AnalogType::NOTUSED) {
obj["v"] = Helpers::transformNumFloat(sensor.value(), 0); // is optional and is a float
obj["v"] = Helpers::transformNumFloat(sensor.value()); // is optional and is a float
} else {
obj["v"] = 0; // must have a value for web sorting to work
}
Expand Down Expand Up @@ -423,11 +423,11 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
dv["id"] = "00" + sensor.name();
#if CONFIG_IDF_TARGET_ESP32
if (sensor.type() == AnalogSensor::AnalogType::DIGITAL_OUT && (sensor.gpio() == 25 || sensor.gpio() == 26)) {
obj["v"] = Helpers::transformNumFloat(sensor.value(), 0);
obj["v"] = Helpers::transformNumFloat(sensor.value());
} else
#elif CONFIG_IDF_TARGET_ESP32S2
if (sensor.type() == AnalogSensor::AnalogType::DIGITAL_OUT && (sensor.gpio() == 17 || sensor.gpio() == 18)) {
obj["v"] = Helpers::transformNumFloat(sensor.value(), 0);
obj["v"] = Helpers::transformNumFloat(sensor.value());
} else
#endif
if (sensor.type() == AnalogSensor::AnalogType::DIGITAL_OUT || sensor.type() == AnalogSensor::AnalogType::DIGITAL_IN) {
Expand All @@ -437,7 +437,7 @@ void WebDataService::dashboard_data(AsyncWebServerRequest * request) {
l.add(Helpers::render_boolean(s, false, true));
l.add(Helpers::render_boolean(s, true, true));
} else {
dv["v"] = Helpers::transformNumFloat(sensor.value(), 0);
dv["v"] = Helpers::transformNumFloat(sensor.value());
dv["u"] = sensor.uom();
}
if (sensor.type() == AnalogSensor::AnalogType::COUNTER || sensor.type() >= AnalogSensor::AnalogType::DIGITAL_OUT) {
Expand Down
4 changes: 2 additions & 2 deletions src/web/WebStatusService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
root["free_psram"] = ESP.getFreePsram() / 1024;
}
root["model"] = EMSESP::system_.getBBQKeesGatewayDetails();
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2
root["temperature"] = EMSESP::system_.temperature();
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32
root["temperature"] = Helpers::transformNumFloat(EMSESP::system_.temperature(), 0, EMSESP::system_.fahrenheit() ? 2 : 0); // only 2 decimal places
#endif

// check for a factory partition first
Expand Down

0 comments on commit 01793dd

Please sign in to comment.