Fix global temperature

- Fix global temperature use of float solving intermittend power off (#8175)
- Fix BL0940 power monitoring when powered on but no load present
This commit is contained in:
Theo Arends 2020-06-12 16:51:21 +02:00
parent f14057d587
commit 0abfcf1954
8 changed files with 30 additions and 20 deletions

View File

@ -687,9 +687,9 @@ void ResetGlobalValues(void)
{
if ((uptime - global_update) > GLOBAL_VALUES_VALID) { // Reset after 5 minutes
global_update = 0;
global_temperature = 9999;
global_humidity = 0;
global_pressure = 0;
global_temperature = NAN;
global_humidity = 0.0f;
global_pressure = 0.0f;
}
}

View File

@ -626,7 +626,7 @@ void CmndGlobalTemp(void)
if (!isnan(temperature) && Settings.flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit
temperature = (temperature - 32) / 1.8; // Celsius
}
if ((temperature >= -50.0) && (temperature <= 100.0)) {
if ((temperature >= -50.0f) && (temperature <= 100.0f)) {
ConvertTemp(temperature);
global_update = 1; // Keep global values just entered valid
}

View File

@ -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 = 9999; // Provide a global temperature to be used by some sensors
float global_humidity = 0; // Provide a global humidity to be used by some sensors
float global_pressure = 0; // Provide a global pressure to be used by some sensors
float global_temperature = 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
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

View File

@ -459,7 +459,12 @@ void EnergyEverySecond(void)
{
// Overtemp check
if (global_update) {
if (power && (global_temperature != 9999) && (global_temperature > Settings.param[P_OVER_TEMP])) { // Device overtemp, turn off relays
if (power && !isnan(global_temperature) && (global_temperature > (float)Settings.param[P_OVER_TEMP])) { // Device overtemp, turn off relays
char temperature[33];
dtostrfd(global_temperature, 1, temperature);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: GlobTemp %s"), temperature);
SetAllPower(POWER_ALL_OFF, SRC_OVERTEMP);
}
}

View File

@ -83,17 +83,20 @@ void Bl0940Received(void) {
return;
}
Bl0940.voltage = Bl0940.rx_buffer[12] << 16 | Bl0940.rx_buffer[11] << 8 | Bl0940.rx_buffer[10];
Bl0940.current = Bl0940.rx_buffer[6] << 16 | Bl0940.rx_buffer[5] << 8 | Bl0940.rx_buffer[4];
Bl0940.power = Bl0940.rx_buffer[18] << 16 | Bl0940.rx_buffer[17] << 8 | Bl0940.rx_buffer[16];
// Bl0940.cf_pulses = Bl0940.rx_buffer[24] << 16 | Bl0940.rx_buffer[23] << 8 | Bl0940.rx_buffer[22];
uint16_t tps1 = Bl0940.rx_buffer[29] << 8 | Bl0940.rx_buffer[28];
Bl0940.voltage = Bl0940.rx_buffer[12] << 16 | Bl0940.rx_buffer[11] << 8 | Bl0940.rx_buffer[10]; // V_RMS unsigned
Bl0940.current = Bl0940.rx_buffer[6] << 16 | Bl0940.rx_buffer[5] << 8 | Bl0940.rx_buffer[4]; // I_RMS unsigned
int32_t power = Bl0940.rx_buffer[18] << 24 | Bl0940.rx_buffer[17] << 16 | Bl0940.rx_buffer[16] << 8; // WATT signed
Bl0940.power = abs(power) >> 8; // WATT unsigned
// Bl0940.cf_pulses = Bl0940.rx_buffer[24] << 16 | Bl0940.rx_buffer[23] << 8 | Bl0940.rx_buffer[22]; // CF_CNT unsigned
uint16_t tps1 = Bl0940.rx_buffer[29] << 8 | Bl0940.rx_buffer[28]; // TPS1 unsigned
float t = ((170.0f/448.0f)*(((float)tps1/2.0f)-32.0f))-45.0f;
Bl0940.temperature = ConvertTemp(t);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("BL9: U %d, I %d, P %d, T %d"), Bl0940.voltage, Bl0940.current, Bl0940.power, tps1);
if (Energy.power_on) { // Powered on
Energy.voltage[0] = (float)Bl0940.voltage / Settings.energy_voltage_calibration;
if (power != 0) {
if (power && (Bl0940.power > Settings.energy_power_calibration)) { // We need at least 1W
Energy.active_power[0] = (float)Bl0940.power / Settings.energy_power_calibration;
Energy.current[0] = (float)Bl0940.current / (Settings.energy_current_calibration * 100);
} else {

View File

@ -87,7 +87,7 @@ void Sgp30Update(void) // Perform every second to ensure proper operation of th
if (!sgp.IAQmeasure()) {
return; // Measurement failed
}
if (global_update && (global_humidity > 0) && (global_temperature != 9999)) {
if (global_update && (global_humidity > 0) && !isnan(global_temperature)) {
// abs hum in mg/m3
sgp30_abshum=sgp30_AbsoluteHumidity(global_temperature,global_humidity,TempUnit());
sgp.setHumidity(sgp30_abshum*1000);
@ -118,14 +118,14 @@ void Sgp30Show(bool json)
{
if (sgp30_ready) {
char abs_hum[33];
if (global_update && global_humidity>0 && global_temperature!=9999) {
if (global_update && (global_humidity > 0) && !isnan(global_temperature)) {
// 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 && global_temperature!=9999) {
if (global_update && global_humidity>0 && !isnan(global_temperature)) {
ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"),abs_hum);
}
ResponseJsonEnd();

View File

@ -65,7 +65,9 @@ void CCS811Update(void) // Perform every n second
TVOC = ccs.getTVOC();
eCO2 = ccs.geteCO2();
CCS811_ready = 1;
if (global_update && global_humidity>0 && global_temperature!=9999) { ccs.setEnvironmentalData((uint8_t)global_humidity, global_temperature); }
if (global_update && (global_humidity > 0) && !isnan(global_temperature)) {
ccs.setEnvironmentalData((uint8_t)global_humidity, global_temperature);
}
ecnt = 0;
}
} else {

View File

@ -37,7 +37,7 @@ void HandleMetrics(void)
char parameter[FLOATSZ];
if (global_temperature != 9999) {
if (!isnan(global_temperature)) {
dtostrfd(global_temperature, Settings.flag2.temperature_resolution, parameter);
WSContentSend_P(PSTR("# TYPE global_temperature gauge\nglobal_temperature %s\n"), parameter);
}