mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 11:16:34 +00:00
Rename global temp and pressure
- Rename global temp and pressure (#8808, #8810) - Fix SGP30 calculation (#8808)
This commit is contained in:
parent
a75b60ca01
commit
7dafeb280e
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)) {
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user