From 7dafeb280e08d64b7603d7204aebb816fb17714d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 28 Jun 2020 12:23:18 +0200 Subject: [PATCH] Rename global temp and pressure - Rename global temp and pressure (#8808, #8810) - Fix SGP30 calculation (#8808) --- tasmota/support.ino | 8 ++++---- tasmota/support_command.ino | 2 +- tasmota/tasmota.ino | 4 ++-- tasmota/xdrv_03_energy.ino | 4 ++-- tasmota/xdrv_10_scripter.ino | 4 ++-- tasmota/xsns_21_sgp30.ino | 14 +++++--------- tasmota/xsns_31_ccs811.ino | 4 ++-- tasmota/xsns_75_prometheus.ino | 12 ++++++------ 8 files changed, 24 insertions(+), 28 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 427a47dcf..1d05ae2d1 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -601,7 +601,7 @@ float ConvertTemp(float c) float result = c; global_update = uptime; - global_temperature = c; + global_temperature_celsius = c; if (!isnan(c) && Settings.flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit result = c * 1.8 + 32; // Fahrenheit @@ -661,7 +661,7 @@ float ConvertPressure(float p) float result = p; global_update = uptime; - global_pressure = p; + global_pressure_hpa = p; if (!isnan(p) && Settings.flag.pressure_conversion) { // SetOption24 - Switch between hPa or mmHg pressure unit result = p * 0.75006375541921; // mmHg @@ -690,9 +690,9 @@ void ResetGlobalValues(void) { if ((uptime - global_update) > GLOBAL_VALUES_VALID) { // Reset after 5 minutes global_update = 0; - global_temperature = NAN; + global_temperature_celsius = NAN; global_humidity = 0.0f; - global_pressure = 0.0f; + global_pressure_hpa = 0.0f; } } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 9c4c858cc..2df30eb25 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -631,7 +631,7 @@ void CmndGlobalTemp(void) global_update = 1; // Keep global values just entered valid } } - ResponseCmndFloat(global_temperature, 1); + ResponseCmndFloat(global_temperature_celsius, 1); } void CmndGlobalHum(void) diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index abc95d5d9..24b100541 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -111,9 +111,9 @@ uint32_t uptime = 0; // Counting every second until 42949 uint32_t loop_load_avg = 0; // Indicative loop load average uint32_t global_update = 0; // Timestamp of last global temperature and humidity update uint32_t web_log_index = 1; // Index in Web log buffer (should never be 0) -float global_temperature = NAN; // Provide a global temperature to be used by some sensors +float global_temperature_celsius = NAN; // Provide a global temperature to be used by some sensors float global_humidity = 0.0f; // Provide a global humidity to be used by some sensors -float global_pressure = 0.0f; // Provide a global pressure to be used by some sensors +float global_pressure_hpa = 0.0f; // Provide a global pressure to be used by some sensors uint16_t tele_period = 9999; // Tele period timer uint16_t blink_counter = 0; // Number of blink cycles uint16_t seriallog_timer = 0; // Timer to disable Seriallog diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index b84d69407..f38265bb8 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -459,10 +459,10 @@ void EnergyEverySecond(void) { // Overtemp check if (global_update) { - if (power && !isnan(global_temperature) && (global_temperature > (float)Settings.param[P_OVER_TEMP])) { // Device overtemp, turn off relays + if (power && !isnan(global_temperature_celsius) && (global_temperature_celsius > (float)Settings.param[P_OVER_TEMP])) { // Device overtemp, turn off relays char temperature[33]; - dtostrfd(global_temperature, 1, temperature); + dtostrfd(global_temperature_celsius, 1, temperature); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: GlobTemp %s"), temperature); SetAllPower(POWER_ALL_OFF, SRC_OVERTEMP); diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index e6c515b5d..cbd1c9d46 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1898,7 +1898,7 @@ chknext: break; case 'g': if (!strncmp(vname,"gtmp",4)) { - fvar=global_temperature; + fvar=global_temperature_celsius; goto exit; } if (!strncmp(vname,"ghum",4)) { @@ -1906,7 +1906,7 @@ chknext: goto exit; } if (!strncmp(vname,"gprs",4)) { - fvar=global_pressure; + fvar=global_pressure_hpa; goto exit; } if (!strncmp(vname,"gtopic",6)) { diff --git a/tasmota/xsns_21_sgp30.ino b/tasmota/xsns_21_sgp30.ino index ec1e85258..6f52f14a4 100644 --- a/tasmota/xsns_21_sgp30.ino +++ b/tasmota/xsns_21_sgp30.ino @@ -55,7 +55,7 @@ void sgp30_Init(void) //#define POW_FUNC pow #define POW_FUNC FastPrecisePow -float sgp30_AbsoluteHumidity(float temperature, float humidity,char tempUnit) { +float sgp30_AbsoluteHumidity(float temperature, float humidity) { //taken from https://carnotcycle.wordpress.com/2012/08/04/how-to-convert-relative-humidity-to-absolute-humidity/ //precision is about 0.1°C in range -30 to 35°C //August-Roche-Magnus 6.1094 exp(17.625 x T)/(T + 243.04) @@ -69,10 +69,6 @@ float sgp30_AbsoluteHumidity(float temperature, float humidity,char tempUnit) { return NAN; } - if (tempUnit != 'C') { - temperature = (temperature - 32.0) * (5.0 / 9.0); /*conversion to [°C]*/ - } - temp = POW_FUNC(2.718281828, (17.67 * temperature) / (temperature + 243.5)); //return (6.112 * temp * humidity * 2.1674) / (273.15 + temperature); //simplified version @@ -87,9 +83,9 @@ void Sgp30Update(void) // Perform every second to ensure proper operation of th if (!sgp.IAQmeasure()) { return; // Measurement failed } - if (global_update && (global_humidity > 0) && !isnan(global_temperature)) { + if (global_update && (global_humidity > 0) && !isnan(global_temperature_celsius)) { // abs hum in mg/m3 - sgp30_abshum=sgp30_AbsoluteHumidity(global_temperature,global_humidity,TempUnit()); + sgp30_abshum = sgp30_AbsoluteHumidity(global_temperature_celsius, global_humidity); sgp.setHumidity(sgp30_abshum*1000); } sgp30_ready = true; @@ -119,13 +115,13 @@ void Sgp30Show(bool json) if (sgp30_ready) { char abs_hum[33]; - if (global_update && (global_humidity > 0) && !isnan(global_temperature)) { + if (global_update && (global_humidity > 0) && !isnan(global_temperature_celsius)) { // has humidity + temperature dtostrfd(sgp30_abshum,4,abs_hum); } if (json) { ResponseAppend_P(PSTR(",\"SGP30\":{\"" D_JSON_ECO2 "\":%d,\"" D_JSON_TVOC "\":%d"), sgp.eCO2, sgp.TVOC); - if (global_update && global_humidity>0 && !isnan(global_temperature)) { + if (global_update && global_humidity>0 && !isnan(global_temperature_celsius)) { ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"),abs_hum); } ResponseJsonEnd(); diff --git a/tasmota/xsns_31_ccs811.ino b/tasmota/xsns_31_ccs811.ino index aada03d04..71bac8240 100644 --- a/tasmota/xsns_31_ccs811.ino +++ b/tasmota/xsns_31_ccs811.ino @@ -65,8 +65,8 @@ void CCS811Update(void) // Perform every n second TVOC = ccs.getTVOC(); eCO2 = ccs.geteCO2(); CCS811_ready = 1; - if (global_update && (global_humidity > 0) && !isnan(global_temperature)) { - ccs.setEnvironmentalData((uint8_t)global_humidity, global_temperature); + if (global_update && (global_humidity > 0) && !isnan(global_temperature_celsius)) { + ccs.setEnvironmentalData((uint8_t)global_humidity, global_temperature_celsius); } ecnt = 0; } diff --git a/tasmota/xsns_75_prometheus.ino b/tasmota/xsns_75_prometheus.ino index 7bdaa7995..fd4396a75 100644 --- a/tasmota/xsns_75_prometheus.ino +++ b/tasmota/xsns_75_prometheus.ino @@ -48,17 +48,17 @@ void HandleMetrics(void) // Wi-Fi Signal strength WSContentSend_P(PSTR("# TYPE tasmota_wifi_station_signal_dbm gauge\ntasmota_wifi_station_signal_dbm{mac_address=\"%s\"} %d\n"), WiFi.BSSIDstr().c_str(), WiFi.RSSI()); - if (!isnan(global_temperature)) { - dtostrfd(global_temperature, Settings.flag2.temperature_resolution, parameter); - WSContentSend_P(PSTR("# TYPE global_temperature gauge\nglobal_temperature %s\n"), parameter); + if (!isnan(global_temperature_celsius)) { + dtostrfd(global_temperature_celsius, Settings.flag2.temperature_resolution, parameter); + WSContentSend_P(PSTR("# TYPE global_temperature_celsius gauge\nglobal_temperature_celsius %s\n"), parameter); } if (global_humidity != 0) { dtostrfd(global_humidity, Settings.flag2.humidity_resolution, parameter); WSContentSend_P(PSTR("# TYPE global_humidity gauge\nglobal_humidity %s\n"), parameter); } - if (global_pressure != 0) { - dtostrfd(global_pressure, Settings.flag2.pressure_resolution, parameter); - WSContentSend_P(PSTR("# TYPE global_pressure gauge\nglobal_pressure %s\n"), parameter); + if (global_pressure_hpa != 0) { + dtostrfd(global_pressure_hpa, Settings.flag2.pressure_resolution, parameter); + WSContentSend_P(PSTR("# TYPE global_pressure_hpa gauge\nglobal_pressure_hpa %s\n"), parameter); } #ifdef USE_ENERGY_SENSOR