mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Fix ESP32 do not use chip temperature sensor as global temperature if external temperature sensor is used (#12630)
This commit is contained in:
parent
c69e276d37
commit
5abadbf221
@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file.
|
||||
- AM2320 value reporting (#12552)
|
||||
- Exception 28 when unable to send MQTT message and a topic name without a slash '/' (#12555)
|
||||
- Wi-Fi initial setup workaround for 11n only routers (#12566)
|
||||
- ESP32 do not use chip temperature sensor as global temperature if external temperature sensor is used (#12630)
|
||||
|
||||
## [9.5.0.1] 20210701
|
||||
### Added
|
||||
|
@ -135,6 +135,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
|
||||
- Zigbee Hue angle encoding [#12545](https://github.com/arendst/Tasmota/issues/12545)
|
||||
- Exception 28 when unable to send MQTT message and a topic name without a slash '/' [#12555](https://github.com/arendst/Tasmota/issues/12555)
|
||||
- Wi-Fi initial setup workaround for 11n only routers [#12566](https://github.com/arendst/Tasmota/issues/12566)
|
||||
- ESP32 do not use chip temperature sensor as global temperature if external temperature sensor is used [#12630](https://github.com/arendst/Tasmota/issues/12630)
|
||||
|
||||
### Noted
|
||||
- ESP32 single core **tasmota32solo1.bin** binary can only be uploaded using the GUI as OTA upload will trigger the watchdog timer
|
@ -720,31 +720,37 @@ char* GetPowerDevice(char* dest, uint32_t idx, size_t size)
|
||||
return GetPowerDevice(dest, idx, size, 0);
|
||||
}
|
||||
|
||||
float ConvertTemp(float c)
|
||||
{
|
||||
float ConvertTempToFahrenheit(float c) {
|
||||
float result = c;
|
||||
|
||||
TasmotaGlobal.global_update = TasmotaGlobal.uptime;
|
||||
TasmotaGlobal.temperature_celsius = c;
|
||||
|
||||
if (!isnan(c) && Settings->flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
result = c * 1.8 + 32; // Fahrenheit
|
||||
result = c * 1.8 + 32; // Fahrenheit
|
||||
}
|
||||
result = result + (0.1 * Settings->temp_comp);
|
||||
return result;
|
||||
}
|
||||
|
||||
float ConvertTempToCelsius(float c)
|
||||
{
|
||||
float ConvertTempToCelsius(float c) {
|
||||
float result = c;
|
||||
|
||||
if (!isnan(c) && Settings->flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
result = (c - 32) / 1.8; // Celsius
|
||||
if (!isnan(c) && !Settings->flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
|
||||
result = (c - 32) / 1.8; // Celsius
|
||||
}
|
||||
result = result + (0.1 * Settings->temp_comp);
|
||||
return result;
|
||||
}
|
||||
|
||||
void UpdateGlobalTemperature(float c) {
|
||||
TasmotaGlobal.global_update = TasmotaGlobal.uptime;
|
||||
TasmotaGlobal.temperature_celsius = c;
|
||||
}
|
||||
|
||||
float ConvertTemp(float c) {
|
||||
UpdateGlobalTemperature(c);
|
||||
|
||||
return ConvertTempToFahrenheit(c);
|
||||
}
|
||||
|
||||
char TempUnit(void)
|
||||
{
|
||||
// SetOption8 - Switch between Celsius or Fahrenheit
|
||||
@ -1328,6 +1334,23 @@ bool ResponseContains_P(const char* needle) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
uint32_t ResponseContains_P(const char* needle) {
|
||||
const char *tmp;
|
||||
#ifdef MQTT_DATA_STRING
|
||||
tmp = TasmotaGlobal.mqtt_data.c_str();
|
||||
#else
|
||||
tmp = TasmotaGlobal.mqtt_data;
|
||||
#endif
|
||||
uint32_t count = 0;
|
||||
while (tmp = strstr_P(tmp, needle)) {
|
||||
count++;
|
||||
tmp++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
*/
|
||||
|
||||
/*********************************************************************************************\
|
||||
* GPIO Module and Template management
|
||||
\*********************************************************************************************/
|
||||
|
@ -487,7 +487,7 @@ void *special_calloc(size_t num, size_t size) {
|
||||
}
|
||||
|
||||
float CpuTemperature(void) {
|
||||
return ConvertTemp(temperatureRead());
|
||||
return (float)temperatureRead(); // In Celsius
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -837,6 +837,36 @@ bool MqttShowSensor(void)
|
||||
XsnsCall(FUNC_JSON_APPEND);
|
||||
XdrvCall(FUNC_JSON_APPEND);
|
||||
|
||||
if (TasmotaGlobal.global_update) {
|
||||
if ((TasmotaGlobal.humidity > 0) || !isnan(TasmotaGlobal.temperature_celsius) || (TasmotaGlobal.pressure_hpa != 0)) {
|
||||
uint32_t add_comma = 0;
|
||||
ResponseAppend_P(PSTR(",\"Global\":{"));
|
||||
if (!isnan(TasmotaGlobal.temperature_celsius)) {
|
||||
float t = ConvertTempToFahrenheit(TasmotaGlobal.temperature_celsius);
|
||||
ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%*_f"),
|
||||
Settings->flag2.temperature_resolution, &t);
|
||||
add_comma++;
|
||||
}
|
||||
if (TasmotaGlobal.humidity > 0) {
|
||||
ResponseAppend_P(PSTR("%s\"" D_JSON_HUMIDITY "\":%*_f"),
|
||||
(add_comma)?",":"", Settings->flag2.humidity_resolution, &TasmotaGlobal.humidity);
|
||||
add_comma++;
|
||||
}
|
||||
if (2 == add_comma) {
|
||||
float dewpoint = CalcTempHumToDew(TasmotaGlobal.temperature_celsius, TasmotaGlobal.humidity);
|
||||
ResponseAppend_P(PSTR("%s\"" D_JSON_DEWPOINT "\":%*_f"),
|
||||
(add_comma)?",":"", Settings->flag2.temperature_resolution, &dewpoint);
|
||||
}
|
||||
if (TasmotaGlobal.pressure_hpa != 0) {
|
||||
float p = ConvertPressure(TasmotaGlobal.pressure_hpa);
|
||||
float s = ConvertPressureForSeaLevel(TasmotaGlobal.pressure_hpa);
|
||||
ResponseAppend_P(PSTR("%s\"" D_JSON_PRESSURE "\":%*_f,\"" D_JSON_PRESSUREATSEALEVEL "\":%*_f"),
|
||||
(add_comma)?",":"", Settings->flag2.pressure_resolution, &p, Settings->flag2.pressure_resolution, &s);
|
||||
}
|
||||
ResponseJsonEnd();
|
||||
}
|
||||
}
|
||||
|
||||
bool json_data_available = (ResponseLength() - json_data_start);
|
||||
if (ResponseContains_P(PSTR(D_JSON_PRESSURE))) {
|
||||
ResponseAppend_P(PSTR(",\"" D_JSON_PRESSURE_UNIT "\":\"%s\""), PressureUnit().c_str());
|
||||
|
@ -193,15 +193,11 @@ struct {
|
||||
char mqtt_client[99]; // Composed MQTT Clientname
|
||||
char mqtt_topic[TOPSZ]; // Composed MQTT topic
|
||||
|
||||
#ifdef ESP8266
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
|
||||
char* log_buffer = nullptr; // Log buffer in IRAM
|
||||
#else
|
||||
char log_buffer[LOG_BUFFER_SIZE]; // Log buffer in DRAM
|
||||
#endif // PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
|
||||
#else // Not ESP8266
|
||||
char log_buffer[LOG_BUFFER_SIZE]; // Log buffer in DRAM
|
||||
#endif // ESP8266
|
||||
} TasmotaGlobal;
|
||||
|
||||
TSettings* Settings = nullptr;
|
||||
@ -262,7 +258,6 @@ void setup(void) {
|
||||
// Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars
|
||||
TasmotaGlobal.seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded
|
||||
|
||||
#ifdef ESP8266
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
|
||||
ESP.setIramHeap();
|
||||
Settings = (TSettings*)malloc(sizeof(TSettings)); // Allocate in "new" 16k heap space
|
||||
@ -275,7 +270,6 @@ void setup(void) {
|
||||
TasmotaGlobal.log_buffer[0] = '\0';
|
||||
}
|
||||
#endif // PIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED
|
||||
#endif // ESP8266
|
||||
if (Settings == nullptr) {
|
||||
Settings = (TSettings*)malloc(sizeof(TSettings));
|
||||
}
|
||||
|
@ -52,7 +52,16 @@ void Esp32SensorInit(void) {
|
||||
#endif // CONFIG_IDF_TARGET_ESP32
|
||||
|
||||
void Esp32SensorShow(bool json) {
|
||||
float t = CpuTemperature();
|
||||
static bool add_global_temp = false;
|
||||
|
||||
if (json) {
|
||||
add_global_temp = !ResponseContains_P(PSTR(D_JSON_TEMPERATURE));
|
||||
}
|
||||
float c = CpuTemperature(); // in Celsius
|
||||
if (add_global_temp) {
|
||||
UpdateGlobalTemperature(c);
|
||||
}
|
||||
float t = ConvertTempToFahrenheit(c);
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
int value = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user