Feature: Show MCU temperature in system info
This commit is contained in:
parent
e211dd5be2
commit
6ce474053e
51
lib/CpuTemperature/src/CpuTemperature.cpp
Normal file
51
lib/CpuTemperature/src/CpuTemperature.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Thomas Basler and others
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CpuTemperature.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||||
|
// there is no official API available on the original ESP32
|
||||||
|
extern "C" {
|
||||||
|
uint8_t temprature_sens_read();
|
||||||
|
}
|
||||||
|
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
#include "driver/temp_sensor.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CpuTemperatureClass CpuTemperature;
|
||||||
|
|
||||||
|
float CpuTemperatureClass::read()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
|
||||||
|
float temperature = NAN;
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||||
|
uint8_t raw = temprature_sens_read();
|
||||||
|
ESP_LOGV(TAG, "Raw temperature value: %d", raw);
|
||||||
|
temperature = (raw - 32) / 1.8f;
|
||||||
|
success = (raw != 128);
|
||||||
|
#elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||||
|
temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
|
||||||
|
temp_sensor_set_config(tsens);
|
||||||
|
temp_sensor_start();
|
||||||
|
#if defined(CONFIG_IDF_TARGET_ESP32S3) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 3))
|
||||||
|
#error \
|
||||||
|
"ESP32-S3 internal temperature sensor requires ESP IDF V4.4.3 or higher. See https://github.com/esphome/issues/issues/4271"
|
||||||
|
#endif
|
||||||
|
esp_err_t result = temp_sensor_read_celsius(&temperature);
|
||||||
|
temp_sensor_stop();
|
||||||
|
success = (result == ESP_OK);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (success && std::isfinite(temperature)) {
|
||||||
|
return temperature;
|
||||||
|
} else {
|
||||||
|
ESP_LOGD(TAG, "Ignoring invalid temperature (success=%d, value=%.1f)", success, temperature);
|
||||||
|
return NAN;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lib/CpuTemperature/src/CpuTemperature.h
Normal file
14
lib/CpuTemperature/src/CpuTemperature.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
class CpuTemperatureClass {
|
||||||
|
public:
|
||||||
|
float read();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mutex _mutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CpuTemperatureClass CpuTemperature;
|
||||||
@ -7,11 +7,12 @@
|
|||||||
#include "NetworkSettings.h"
|
#include "NetworkSettings.h"
|
||||||
#include "PinMapping.h"
|
#include "PinMapping.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
#include "__compiled_constants.h"
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
|
#include <CpuTemperature.h>
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include <ResetReason.h>
|
#include <ResetReason.h>
|
||||||
#include "__compiled_constants.h"
|
|
||||||
|
|
||||||
void WebApiSysstatusClass::init(AsyncWebServer& server, Scheduler& scheduler)
|
void WebApiSysstatusClass::init(AsyncWebServer& server, Scheduler& scheduler)
|
||||||
{
|
{
|
||||||
@ -33,6 +34,7 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
root["sdkversion"] = ESP.getSdkVersion();
|
root["sdkversion"] = ESP.getSdkVersion();
|
||||||
root["cpufreq"] = ESP.getCpuFreqMHz();
|
root["cpufreq"] = ESP.getCpuFreqMHz();
|
||||||
|
root["cputemp"] = CpuTemperature.read();
|
||||||
|
|
||||||
root["heap_total"] = ESP.getHeapSize();
|
root["heap_total"] = ESP.getHeapSize();
|
||||||
root["heap_used"] = ESP.getHeapSize() - ESP.getFreeHeap();
|
root["heap_used"] = ESP.getHeapSize() - ESP.getFreeHeap();
|
||||||
|
|||||||
@ -19,6 +19,10 @@
|
|||||||
<th>{{ $t('hardwareinfo.CpuFrequency') }}</th>
|
<th>{{ $t('hardwareinfo.CpuFrequency') }}</th>
|
||||||
<td>{{ systemStatus.cpufreq }} {{ $t('hardwareinfo.Mhz') }}</td>
|
<td>{{ systemStatus.cpufreq }} {{ $t('hardwareinfo.Mhz') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>{{ $t('hardwareinfo.CpuTemperature') }}</th>
|
||||||
|
<td>{{ $n(systemStatus.cputemp, 'decimalNoDigits') }} {{ $t('hardwareinfo.DegreeC') }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ $t('hardwareinfo.FlashSize') }}</th>
|
<th>{{ $t('hardwareinfo.FlashSize') }}</th>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@ -203,6 +203,8 @@
|
|||||||
"ChipCores": "Chip-Kerne",
|
"ChipCores": "Chip-Kerne",
|
||||||
"CpuFrequency": "CPU-Frequenz",
|
"CpuFrequency": "CPU-Frequenz",
|
||||||
"Mhz": "MHz",
|
"Mhz": "MHz",
|
||||||
|
"CpuTemperature": "CPU Temperatur",
|
||||||
|
"DegreeC": "°C",
|
||||||
"FlashSize": "Flash-Speichergröße",
|
"FlashSize": "Flash-Speichergröße",
|
||||||
"Bytes": "Bytes",
|
"Bytes": "Bytes",
|
||||||
"MegaBytes": "MB"
|
"MegaBytes": "MB"
|
||||||
|
|||||||
@ -203,6 +203,8 @@
|
|||||||
"ChipCores": "Chip Cores",
|
"ChipCores": "Chip Cores",
|
||||||
"CpuFrequency": "CPU Frequency",
|
"CpuFrequency": "CPU Frequency",
|
||||||
"Mhz": "MHz",
|
"Mhz": "MHz",
|
||||||
|
"CpuTemperature": "CPU Temperature",
|
||||||
|
"DegreeC": "°C",
|
||||||
"FlashSize": "Flash Memory Size",
|
"FlashSize": "Flash Memory Size",
|
||||||
"Bytes": "Bytes",
|
"Bytes": "Bytes",
|
||||||
"MegaBytes": "MB"
|
"MegaBytes": "MB"
|
||||||
|
|||||||
@ -203,6 +203,8 @@
|
|||||||
"ChipCores": "Nombre de cœurs",
|
"ChipCores": "Nombre de cœurs",
|
||||||
"CpuFrequency": "Fréquence du CPU",
|
"CpuFrequency": "Fréquence du CPU",
|
||||||
"Mhz": "MHz",
|
"Mhz": "MHz",
|
||||||
|
"CpuTemperature": "CPU Temperature",
|
||||||
|
"DegreeC": "°C",
|
||||||
"FlashSize": "Taille de la mémoire flash",
|
"FlashSize": "Taille de la mémoire flash",
|
||||||
"Bytes": "octets",
|
"Bytes": "octets",
|
||||||
"MegaBytes": "Mo"
|
"MegaBytes": "Mo"
|
||||||
|
|||||||
@ -4,6 +4,7 @@ export interface SystemStatus {
|
|||||||
chiprevision: number;
|
chiprevision: number;
|
||||||
chipcores: number;
|
chipcores: number;
|
||||||
cpufreq: number;
|
cpufreq: number;
|
||||||
|
cputemp: number;
|
||||||
flashsize: number;
|
flashsize: number;
|
||||||
// FirmwareInfo
|
// FirmwareInfo
|
||||||
hostname: string;
|
hostname: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user