From b93b7191087d7819bb97f3456cc21d4d21b84c09 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:32:07 +0100 Subject: [PATCH] Use global struct --- tasmota/support.ino | 50 ++++---- tasmota/support_button.ino | 2 +- tasmota/support_command.ino | 26 +++-- tasmota/support_rtc.ino | 8 +- tasmota/support_switch.ino | 4 +- tasmota/support_tasmota.ino | 28 ++--- tasmota/support_wifi.ino | 2 +- tasmota/tasmota.ino | 39 ++++--- tasmota/xdrv_01_webserver.ino | 14 +-- tasmota/xdrv_03_energy.ino | 4 +- tasmota/xdrv_09_timers.ino | 4 +- tasmota/xdrv_10_rules.ino | 4 +- tasmota/xdrv_10_scripter.ino | 4 +- tasmota/xdrv_12_home_assistant.ino | 2 +- tasmota/xdrv_16_tuyamcu.ino | 2 +- tasmota/xdrv_18_armtronix_dimmers.ino | 2 +- tasmota/xdrv_22_sonoff_ifan.ino | 2 +- tasmota/xdrv_26_ariluxrf.ino | 2 +- tasmota/xdrv_27_shutter.ino | 4 +- tasmota/xdrv_39_thermostat.ino | 66 +++++------ tasmota/xdrv_40_telegram.ino | 6 +- tasmota/xnrg_03_pzem004t.ino | 6 +- tasmota/xnrg_05_pzem_ac.ino | 6 +- tasmota/xnrg_06_pzem_dc.ino | 6 +- tasmota/xnrg_08_sdm120.ino | 2 +- tasmota/xnrg_09_dds2382.ino | 2 +- tasmota/xnrg_10_sdm630.ino | 2 +- tasmota/xnrg_11_ddsu666.ino | 2 +- tasmota/xnrg_12_solaxX1.ino | 2 +- tasmota/xnrg_13_fif_le01mr.ino | 2 +- tasmota/xnrg_15_teleinfo.ino | 158 +++++++++++++------------- tasmota/xnrg_16_iem3000.ino | 2 +- tasmota/xnrg_17_ornowe517.ino | 2 +- tasmota/xsns_05_ds18x20.ino | 2 +- tasmota/xsns_05_ds18x20_esp32.ino | 2 +- tasmota/xsns_06_dht.ino | 2 +- tasmota/xsns_07_sht1x.ino | 2 +- tasmota/xsns_08_htu21.ino | 2 +- tasmota/xsns_16_tsl2561.ino | 2 +- tasmota/xsns_21_sgp30.ino | 10 +- tasmota/xsns_31_ccs811.ino | 2 +- tasmota/xsns_35_tx20.ino | 14 +-- tasmota/xsns_43_hre.ino | 6 +- tasmota/xsns_44_sps30.ino | 4 +- tasmota/xsns_52_ibeacon.ino | 4 +- tasmota/xsns_55_hih_series.ino | 4 +- tasmota/xsns_58_dht12.ino | 2 +- tasmota/xsns_65_hdc1080.ino | 2 +- tasmota/xsns_73_hp303b.ino | 2 +- tasmota/xsns_75_prometheus.ino | 2 +- tasmota/xsns_78_ezoco2.ino | 4 +- tasmota/xsns_78_xezo.ino | 4 +- tasmota/xsns_interface.ino | 4 +- 53 files changed, 282 insertions(+), 261 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index d901a542c..a520588fd 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -657,7 +657,7 @@ float ConvertTemp(float c) { float result = c; - global_update = uptime; + TasmotaGlobal.global_update = TasmotaGlobal.uptime; global_temperature_celsius = c; if (!isnan(c) && Settings.flag.temperature_conversion) { // SetOption8 - Switch between Celsius or Fahrenheit @@ -688,7 +688,7 @@ float ConvertHumidity(float h) { float result = h; - global_update = uptime; + TasmotaGlobal.global_update = TasmotaGlobal.uptime; global_humidity = h; result = result + (0.1 * Settings.hum_comp); @@ -717,7 +717,7 @@ float ConvertPressure(float p) { float result = p; - global_update = uptime; + TasmotaGlobal.global_update = TasmotaGlobal.uptime; global_pressure_hpa = p; if (!isnan(p) && Settings.flag.pressure_conversion) { // SetOption24 - Switch between hPa or mmHg pressure unit @@ -745,8 +745,8 @@ String SpeedUnit(void) void ResetGlobalValues(void) { - if ((uptime - global_update) > GLOBAL_VALUES_VALID) { // Reset after 5 minutes - global_update = 0; + if ((TasmotaGlobal.uptime - TasmotaGlobal.global_update) > GLOBAL_VALUES_VALID) { // Reset after 5 minutes + TasmotaGlobal.global_update = 0; global_temperature_celsius = NAN; global_humidity = 0.0f; global_pressure_hpa = 0.0f; @@ -902,10 +902,10 @@ String GetSerialConfig(void) { } void SetSerialBegin(void) { - baudrate = Settings.baudrate * 300; - AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), baudrate); + TasmotaGlobal.baudrate = Settings.baudrate * 300; + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), TasmotaGlobal.baudrate); Serial.flush(); - Serial.begin(baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config)); + Serial.begin(TasmotaGlobal.baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config)); } void SetSerialConfig(uint32_t serial_config) { @@ -918,19 +918,19 @@ void SetSerialConfig(uint32_t serial_config) { } } -void SetSerialBaudrate(uint32_t ubaudrate) { - baudrate = ubaudrate; - Settings.baudrate = baudrate / 300; - if (Serial.baudRate() != baudrate) { +void SetSerialBaudrate(uint32_t baudrate) { + TasmotaGlobal.baudrate = baudrate; + Settings.baudrate = TasmotaGlobal.baudrate / 300; + if (Serial.baudRate() != TasmotaGlobal.baudrate) { SetSerialBegin(); } } -void SetSerial(uint32_t ubaudrate, uint32_t serial_config) { +void SetSerial(uint32_t baudrate, uint32_t serial_config) { Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG Settings.serial_config = serial_config; - baudrate = ubaudrate; - Settings.baudrate = baudrate / 300; + TasmotaGlobal.baudrate = baudrate; + Settings.baudrate = TasmotaGlobal.baudrate / 300; SetSeriallog(LOG_LEVEL_NONE); SetSerialBegin(); } @@ -939,8 +939,8 @@ void ClaimSerial(void) { serial_local = true; AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial")); SetSeriallog(LOG_LEVEL_NONE); - baudrate = Serial.baudRate(); - Settings.baudrate = baudrate / 300; + TasmotaGlobal.baudrate = Serial.baudRate(); + Settings.baudrate = TasmotaGlobal.baudrate / 300; } void SerialSendRaw(char *codes) @@ -1996,9 +1996,11 @@ void AddLog(uint32_t loglevel) (masterlog_level <= Settings.weblog_level)) { // Delimited, zero-terminated buffer of log lines. // Each entry has this format: [index][log data]['\1'] - web_log_index &= 0xFF; - if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string - while (web_log_index == web_log[0] || // If log already holds the next index, remove it + TasmotaGlobal.web_log_index &= 0xFF; + if (!TasmotaGlobal.web_log_index) { + TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string + } + while (TasmotaGlobal.web_log_index == web_log[0] || // If log already holds the next index, remove it strlen(web_log) + strlen(log_data) + 13 > WEB_LOG_SIZE) // 13 = web_log_index + mxtime + '\1' + '\0' { char* it = web_log; @@ -2007,9 +2009,11 @@ void AddLog(uint32_t loglevel) it++; // Skip delimiting "\1" memmove(web_log, it, WEB_LOG_SIZE -(it-web_log)); // Move buffer forward to remove oldest log line } - snprintf_P(web_log, sizeof(web_log), PSTR("%s%c%s%s\1"), web_log, web_log_index++, mxtime, log_data); - web_log_index &= 0xFF; - if (!web_log_index) web_log_index++; // Index 0 is not allowed as it is the end of char string + snprintf_P(web_log, sizeof(web_log), PSTR("%s%c%s%s\1"), web_log, TasmotaGlobal.web_log_index++, mxtime, log_data); + TasmotaGlobal.web_log_index &= 0xFF; + if (!TasmotaGlobal.web_log_index) { + TasmotaGlobal.web_log_index++; // Index 0 is not allowed as it is the end of char string + } } #endif // USE_WEBSERVER if (Settings.flag.mqtt_enabled && // SetOption3 - Enable MQTT diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index aef3c31a3..ffb458a82 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -135,7 +135,7 @@ uint8_t ButtonSerial(uint8_t serial_in_byte) void ButtonHandler(void) { - if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit + if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command uint16_t loops_per_second = 1000 / Settings.button_debounce; // ButtonDebounce (50) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index d3f50f826..737bec091 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -244,8 +244,8 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) DEBUG_CORE_LOG(PSTR("CMD: Payload %d"), payload); -// backlog_delay = millis() + (100 * MIN_BACKLOG_DELAY); - backlog_delay = millis() + Settings.param[P_BACKLOG_DELAY]; +// TasmotaGlobal.backlog_delay = millis() + (100 * MIN_BACKLOG_DELAY); + TasmotaGlobal.backlog_delay = millis() + Settings.param[P_BACKLOG_DELAY]; char command[CMDSZ] = { 0 }; XdrvMailbox.command = command; @@ -344,7 +344,7 @@ void CmndBacklog(void) } // ResponseCmndChar(D_JSON_APPENDED); mqtt_data[0] = '\0'; - backlog_delay = 0; + TasmotaGlobal.backlog_delay = 0; } else { bool blflag = BACKLOG_EMPTY; #ifdef SUPPORT_IF_STATEMENT @@ -359,10 +359,10 @@ void CmndBacklog(void) void CmndDelay(void) { if ((XdrvMailbox.payload >= (MIN_BACKLOG_DELAY / 100)) && (XdrvMailbox.payload <= 3600)) { - backlog_delay = millis() + (100 * XdrvMailbox.payload); + TasmotaGlobal.backlog_delay = millis() + (100 * XdrvMailbox.payload); } uint32_t bl_delay = 0; - long bl_delta = TimePassedSince(backlog_delay); + long bl_delta = TimePassedSince(TasmotaGlobal.backlog_delay); if (bl_delta < 0) { bl_delay = (bl_delta *-1) / 100; } ResponseCmndNumber(bl_delay); } @@ -440,7 +440,7 @@ void CmndStatus(void) ",\"" D_JSON_SAVEADDRESS "\":\"%X\"" #endif "}}"), - baudrate, GetSerialConfig().c_str(), SettingsText(SET_MQTT_GRP_TOPIC), SettingsText(SET_OTAURL), + TasmotaGlobal.baudrate, GetSerialConfig().c_str(), SettingsText(SET_MQTT_GRP_TOPIC), SettingsText(SET_OTAURL), GetResetReason().c_str(), GetUptime().c_str(), GetDateAndTime(DT_RESTART).c_str(), Settings.sleep, Settings.cfg_holder, Settings.bootcount, GetDateAndTime(DT_BOOTCOUNT).c_str(), Settings.save_flag #ifdef ESP8266 @@ -661,7 +661,7 @@ void CmndGlobalTemp(void) } if ((temperature >= -50.0f) && (temperature <= 100.0f)) { ConvertTemp(temperature); - global_update = 1; // Keep global values just entered valid + TasmotaGlobal.global_update = 1; // Keep global values just entered valid } } ResponseCmndFloat(global_temperature_celsius, 1); @@ -673,7 +673,7 @@ void CmndGlobalHum(void) float humidity = CharToFloat(XdrvMailbox.data); if ((humidity >= 0.0) && (humidity <= 100.0)) { ConvertHumidity(humidity); - global_update = 1; // Keep global values just entered valid + TasmotaGlobal.global_update = 1; // Keep global values just entered valid } } ResponseCmndFloat(global_humidity, 1); @@ -805,7 +805,9 @@ void CmndBlinktime(void) { if ((XdrvMailbox.payload > 1) && (XdrvMailbox.payload <= 3600)) { Settings.blinktime = XdrvMailbox.payload; - if (blink_timer > 0) { blink_timer = millis() + (100 * XdrvMailbox.payload); } + if (TasmotaGlobal.blink_timer > 0) { + TasmotaGlobal.blink_timer = millis() + (100 * XdrvMailbox.payload); + } } ResponseCmndNumber(Settings.blinktime); } @@ -1340,10 +1342,10 @@ void CmndBaudrate(void) { if (XdrvMailbox.payload >= 300) { XdrvMailbox.payload /= 300; // Make it a valid baudrate - baudrate = (XdrvMailbox.payload & 0xFFFF) * 300; - SetSerialBaudrate(baudrate); + TasmotaGlobal.baudrate = (XdrvMailbox.payload & 0xFFFF) * 300; + SetSerialBaudrate(TasmotaGlobal.baudrate); } - ResponseCmndNumber(baudrate); + ResponseCmndNumber(TasmotaGlobal.baudrate); } void CmndSerialConfig(void) diff --git a/tasmota/support_rtc.ino b/tasmota/support_rtc.ino index 25ad82435..460593f38 100644 --- a/tasmota/support_rtc.ino +++ b/tasmota/support_rtc.ino @@ -225,7 +225,7 @@ uint32_t UpTime(void) if (Rtc.restart_time) { return Rtc.utc_time - Rtc.restart_time; } else { - return uptime; + return TasmotaGlobal.uptime; } } @@ -380,11 +380,11 @@ void RtcSecond(void) if (!Rtc.user_time_entry) { if (!global_state.network_down) { - uint8_t uptime_minute = (uptime / 60) % 60; // 0 .. 59 + uint8_t uptime_minute = (TasmotaGlobal.uptime / 60) % 60; // 0 .. 59 if ((Rtc.ntp_sync_minute > 59) && (uptime_minute > 2)) { Rtc.ntp_sync_minute = 1; // If sync prepare for a new cycle } - uint8_t offset = (uptime < 30) ? RtcTime.second : (((ESP_getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id + uint8_t offset = (TasmotaGlobal.uptime < 30) ? RtcTime.second : (((ESP_getChipId() & 0xF) * 3) + 3) ; // First try ASAP to sync. If fails try once every 60 seconds based on chip id if ( (((offset == RtcTime.second) && ( (RtcTime.year < 2016) || // Never synced (Rtc.ntp_sync_minute == uptime_minute))) || // Re-sync every hour ntp_force_sync ) ) { // Forced sync @@ -395,7 +395,7 @@ void RtcSecond(void) Rtc.last_sync = Rtc.ntp_time; Rtc.ntp_sync_minute = 60; // Sync so block further requests if (Rtc.restart_time == 0) { - Rtc.restart_time = Rtc.utc_time - uptime; // save first ntp time as restart time + Rtc.restart_time = Rtc.utc_time - TasmotaGlobal.uptime; // save first ntp time as restart time } BreakTime(Rtc.utc_time, tmpTime); RtcTime.year = tmpTime.year + 1970; diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 3323bbe01..bf5b0e579 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -88,7 +88,7 @@ bool SwitchState(uint32_t index) void SwitchProbe(void) { - if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit + if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit uint8_t state_filter; uint8_t debounce_flags = Settings.switch_debounce % 10; @@ -232,7 +232,7 @@ void SwitchInit(void) void SwitchHandler(uint8_t mode) { - if (uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit + if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit uint16_t loops_per_second = 1000 / Settings.switch_debounce; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index ccc4c1574..37b869bda 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -421,12 +421,12 @@ void SetLedLink(uint32_t state) void SetPulseTimer(uint32_t index, uint32_t time) { - pulse_timer[index] = (time > 111) ? millis() + (1000 * (time - 100)) : (time > 0) ? millis() + (100 * time) : 0L; + TasmotaGlobal.pulse_timer[index] = (time > 111) ? millis() + (1000 * (time - 100)) : (time > 0) ? millis() + (100 * time) : 0L; } uint32_t GetPulseTimer(uint32_t index) { - long time = TimePassedSince(pulse_timer[index]); + long time = TimePassedSince(TasmotaGlobal.pulse_timer[index]); if (time < 0) { time *= -1; return (time > 11100) ? (time / 1000) + 100 : (time > 0) ? time / 100 : 0; @@ -606,7 +606,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source) blink_powersave = (blink_powersave & (POWER_MASK ^ mask)) | (power & mask); // Save state blink_power = (power >> (device -1))&1; // Prep to Toggle } - blink_timer = millis() + 100; + TasmotaGlobal.blink_timer = millis() + 100; blink_counter = ((!Settings.blinkcount) ? 64000 : (Settings.blinkcount *2)) +1; blink_mask |= mask; // Set device mask MqttPublishPowerBlinkState(device); @@ -669,7 +669,7 @@ void MqttShowState(void) ResponseAppend_P(PSTR(",\"" D_JSON_HEAPSIZE "\":%d,\"SleepMode\":\"%s\",\"Sleep\":%u,\"LoadAvg\":%u,\"MqttCount\":%u"), ESP_getFreeHeap()/1024, GetTextIndexed(stemp1, sizeof(stemp1), Settings.flag3.sleep_normal, kSleepMode), // SetOption60 - Enable normal sleep instead of dynamic sleep - ssleep, loop_load_avg, MqttConnectCount()); + ssleep, TasmotaGlobal.loop_load_avg, MqttConnectCount()); for (uint32_t i = 1; i <= devices_present; i++) { #ifdef USE_LIGHT @@ -789,13 +789,13 @@ void MqttPublishSensor(void) void PerformEverySecond(void) { - uptime++; + TasmotaGlobal.uptime++; - if (POWER_CYCLE_TIME == uptime) { + if (POWER_CYCLE_TIME == TasmotaGlobal.uptime) { UpdateQuickPowerCycle(false); } - if (BOOT_LOOP_TIME == uptime) { + if (BOOT_LOOP_TIME == TasmotaGlobal.uptime) { RtcRebootReset(); #ifdef USE_DEEPSLEEP @@ -867,8 +867,8 @@ void PerformEverySecond(void) wifiKeepAlive(); #ifdef ESP32 - if (11 == uptime) { // Perform one-time ESP32 houskeeping - ESP_getSketchSize(); // Init sketchsize as it can take up to 2 seconds + if (11 == TasmotaGlobal.uptime) { // Perform one-time ESP32 houskeeping + ESP_getSketchSize(); // Init sketchsize as it can take up to 2 seconds } #endif } @@ -892,9 +892,9 @@ void Every100mSeconds(void) } for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) { - if (pulse_timer[i] != 0L) { // Timer active? - if (TimeReached(pulse_timer[i])) { // Timer finished? - pulse_timer[i] = 0L; // Turn off this timer + if (TasmotaGlobal.pulse_timer[i] != 0L) { // Timer active? + if (TimeReached(TasmotaGlobal.pulse_timer[i])) { // Timer finished? + TasmotaGlobal.pulse_timer[i] = 0L; // Turn off this timer for (uint32_t j = 0; j < devices_present; j = j +MAX_PULSETIMERS) { ExecuteCommandPower(i + j +1, (POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? POWER_ON : POWER_OFF, SRC_PULSETIMER); } @@ -903,8 +903,8 @@ void Every100mSeconds(void) } if (blink_mask) { - if (TimeReached(blink_timer)) { - SetNextTimeInterval(blink_timer, 100 * Settings.blinktime); + if (TimeReached(TasmotaGlobal.blink_timer)) { + SetNextTimeInterval(TasmotaGlobal.blink_timer, 100 * Settings.blinktime); blink_counter--; if (!blink_counter) { StopAllPowerBlink(); diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index b93d6f2d8..9ed57f886 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -520,7 +520,7 @@ void WifiCheck(uint8_t param) #endif // LWIP_IPV6=1 WifiSetState(1); if (Settings.flag3.use_wifi_rescan) { // SetOption57 - Scan wifi network every 44 minutes for configured AP's - if (!(uptime % (60 * WIFI_RESCAN_MINUTES))) { + if (!(TasmotaGlobal.uptime % (60 * WIFI_RESCAN_MINUTES))) { Wifi.scan_state = 2; } } diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 97dfe171d..213f055e8 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -77,14 +77,18 @@ WiFiUDP PortUdp; // UDP Syslog and Alexa -uint32_t pulse_timer[MAX_PULSETIMERS] = { 0 }; // Power off timer -uint32_t blink_timer = 0; // Power cycle timer -uint32_t backlog_delay = 0; // Command backlog delay -uint32_t uptime = 0; // Counting every second until 4294967295 = 130 year -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) -uint32_t baudrate = APP_BAUDRATE; // Current Serial baudrate +struct { + uint32_t baudrate; // Current Serial baudrate + uint32_t pulse_timer[MAX_PULSETIMERS]; // Power off timer + uint32_t blink_timer; // Power cycle timer + uint32_t backlog_delay; // Command backlog delay + uint32_t loop_load_avg; // Indicative loop load average + uint32_t global_update; // Timestamp of last global temperature and humidity update + uint32_t web_log_index; // Index in Web log buffer + uint32_t uptime; // Counting every second until 4294967295 = 130 year + +} TasmotaGlobal; + power_t power = 0; // Current copy of Settings.power power_t last_power = 0; // Last power set state power_t blink_power; // Blink power state @@ -177,6 +181,9 @@ void setup(void) { #endif #endif + memset(&TasmotaGlobal, 0, sizeof(TasmotaGlobal)); + TasmotaGlobal.baudrate = APP_BAUDRATE; + global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues RtcRebootLoad(); @@ -190,7 +197,7 @@ void setup(void) { #endif RtcRebootSave(); - Serial.begin(baudrate); + Serial.begin(TasmotaGlobal.baudrate); // Serial.setRxBufferSize(INPUT_BUFFER_SIZE); // Default is 256 chars seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded @@ -229,6 +236,8 @@ void setup(void) { #endif #endif // USE_EMULATION +// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)&TasmotaGlobal, sizeof(TasmotaGlobal)); + if (Settings.param[P_BOOT_LOOP_OFFSET]) { // SetOption36 // Disable functionality as possible cause of fast restart within BOOT_LOOP_TIME seconds (Exception, WDT or restarts) if (RtcReboot.fast_reboot_count > Settings.param[P_BOOT_LOOP_OFFSET]) { // Restart twice @@ -297,7 +306,7 @@ void setup(void) { } void BacklogLoop(void) { - if (TimeReached(backlog_delay)) { + if (TimeReached(TasmotaGlobal.backlog_delay)) { if (!BACKLOG_EMPTY && !backlog_mutex) { backlog_mutex = true; bool nodelay = false; @@ -315,8 +324,12 @@ void BacklogLoop(void) { nodelay_detected = !strncasecmp_P(cmd.c_str(), PSTR(D_CMND_NODELAY), strlen(D_CMND_NODELAY)); if (nodelay_detected) { nodelay = true; } } while (!BACKLOG_EMPTY && nodelay_detected); - if (!nodelay_detected) { ExecuteCommand((char*)cmd.c_str(), SRC_BACKLOG); } - if (nodelay) { backlog_delay = 0; } // Reset backlog_delay which has been set by ExecuteCommand (CommandHandler) + if (!nodelay_detected) { + ExecuteCommand((char*)cmd.c_str(), SRC_BACKLOG); + } + if (nodelay) { + TasmotaGlobal.backlog_delay = 0; // Reset backlog_delay which has been set by ExecuteCommand (CommandHandler) + } backlog_mutex = false; } } @@ -408,5 +421,5 @@ void loop(void) { if (!loop_delay) { loop_delay++; } // We cannot divide by 0 uint32_t loops_per_second = 1000 / loop_delay; // We need to keep track of this many loops per second uint32_t this_cycle_ratio = 100 * my_activity / loop_delay; - loop_load_avg = loop_load_avg - (loop_load_avg / loops_per_second) + (this_cycle_ratio / loops_per_second); // Take away one loop average away and add the new one + TasmotaGlobal.loop_load_avg = TasmotaGlobal.loop_load_avg - (TasmotaGlobal.loop_load_avg / loops_per_second) + (this_cycle_ratio / loops_per_second); // Take away one loop average away and add the new one } diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 689b4bdd6..a722b3a91 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -3029,11 +3029,11 @@ void HandleHttpCommand(void) } WSContentBegin(200, CT_JSON); - uint32_t curridx = web_log_index; + uint32_t curridx = TasmotaGlobal.web_log_index; String svalue = Webserver->arg("cmnd"); if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) { ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND); - if (web_log_index != curridx) { + if (TasmotaGlobal.web_log_index != curridx) { uint32_t counter = curridx; WSContentSend_P(PSTR("{")); bool cflg = false; @@ -3056,7 +3056,7 @@ void HandleHttpCommand(void) counter++; counter &= 0xFF; if (!counter) counter++; // Skip 0 as it is not allowed - } while (counter != web_log_index); + } while (counter != TasmotaGlobal.web_log_index); WSContentSend_P(PSTR("}")); } else { WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}")); @@ -3104,14 +3104,14 @@ void HandleConsoleRefresh(void) if (strlen(stmp)) { counter = atoi(stmp); } WSContentBegin(200, CT_PLAIN); - WSContentSend_P(PSTR("%d}1%d}1"), web_log_index, Web.reset_web_log_flag); + WSContentSend_P(PSTR("%d}1%d}1"), TasmotaGlobal.web_log_index, Web.reset_web_log_flag); if (!Web.reset_web_log_flag) { counter = 0; Web.reset_web_log_flag = true; } - if (counter != web_log_index) { + if (counter != TasmotaGlobal.web_log_index) { if (!counter) { - counter = web_log_index; + counter = TasmotaGlobal.web_log_index; cflg = false; } do { @@ -3128,7 +3128,7 @@ void HandleConsoleRefresh(void) counter++; counter &= 0xFF; if (!counter) { counter++; } // Skip log index 0 as it is not allowed - } while (counter != web_log_index); + } while (counter != TasmotaGlobal.web_log_index); } WSContentSend_P(PSTR("}1")); WSContentEnd(); diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index 79e34e44b..25f14d03f 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -338,6 +338,8 @@ void EnergyMarginCheck(void) for (uint32_t phase = 0; phase < Energy.phase_count; phase++) { uint16_t active_power = (uint16_t)(Energy.active_power[phase]); +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("NRG: APower %d, HPower0 %d, HPower1 %d, HPower2 %d"), active_power, Energy.power_history[phase][0], Energy.power_history[phase][1], Energy.power_history[phase][2]); + if (Settings.energy_power_delta[phase]) { power_diff[phase] = active_power - Energy.power_history[phase][0]; uint16_t delta = abs(power_diff[phase]); @@ -502,7 +504,7 @@ void EnergyMqttShow(void) void EnergyEverySecond(void) { // Overtemp check - if (global_update) { + if (TasmotaGlobal.global_update) { if (power && !isnan(global_temperature_celsius) && (global_temperature_celsius > (float)Settings.param[P_OVER_TEMP])) { // Device overtemp, turn off relays char temperature[33]; diff --git a/tasmota/xdrv_09_timers.ino b/tasmota/xdrv_09_timers.ino index f398b0922..5b6aeaa10 100644 --- a/tasmota/xdrv_09_timers.ino +++ b/tasmota/xdrv_09_timers.ino @@ -177,7 +177,7 @@ void ApplyTimerOffsets(Timer *duskdawn) if (hour[mode]==255) { // Permanent day/night sets the unreachable limit values if ((Settings.latitude > 0) != (RtcTime.month>=4 && RtcTime.month<=9)) { - duskdawn->time=2046; // permanent night + duskdawn->time=2046; // permanent night } else { duskdawn->time=2047; // permanent day } @@ -256,7 +256,7 @@ void TimerEverySecond(void) if (RtcTime.valid) { if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second) { TimerSetRandomWindows(); } // Midnight if (Settings.flag3.timers_enable && // CMND_TIMERS - (uptime > 60) && (RtcTime.minute != timer_last_minute)) { // Execute from one minute after restart every minute only once + (TasmotaGlobal.uptime > 60) && (RtcTime.minute != timer_last_minute)) { // Execute from one minute after restart every minute only once timer_last_minute = RtcTime.minute; int32_t time = (RtcTime.hour *60) + RtcTime.minute; uint8_t days = 1 << (RtcTime.day_of_week -1); diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index b908f389d..68a75d02b 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -947,7 +947,7 @@ uint8_t rules_xsns_index = 0; void RulesEvery100ms(void) { - if (Settings.rule_enabled && !Rules.busy && (uptime > 4)) { // Any rule enabled and allow 4 seconds start-up time for sensors (#3811) + if (Settings.rule_enabled && !Rules.busy && (TasmotaGlobal.uptime > 4)) { // Any rule enabled and allow 4 seconds start-up time for sensors (#3811) mqtt_data[0] = '\0'; int tele_period_save = tele_period; tele_period = 2; // Do not allow HA updates during next function call @@ -967,7 +967,7 @@ void RulesEverySecond(void) char json_event[120]; if (RtcTime.valid) { - if ((uptime > 60) && (RtcTime.minute != Rules.last_minute)) { // Execute from one minute after restart every minute only once + if ((TasmotaGlobal.uptime > 60) && (RtcTime.minute != Rules.last_minute)) { // Execute from one minute after restart every minute only once Rules.last_minute = RtcTime.minute; snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Minute\":%d}}"), MinutesPastMidnight()); RulesProcessEvent(json_event); diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 9725e94a2..83acd7a66 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -3012,7 +3012,7 @@ chknext: goto exit; } if (!strncmp(vname, "upsecs", 6)) { - fvar = uptime; + fvar = TasmotaGlobal.uptime; goto exit; } if (!strncmp(vname, "upd[", 4)) { @@ -4495,7 +4495,7 @@ uint8_t script_xsns_index = 0; void ScripterEvery100ms(void) { - if (Settings.rule_enabled && (uptime > 4)) { + if (Settings.rule_enabled && (TasmotaGlobal.uptime > 4)) { mqtt_data[0] = '\0'; uint16_t script_tele_period_save = tele_period; tele_period = 2; diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 85483c62c..f74739e3f 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -1019,7 +1019,7 @@ void HAssPublishStatus(void) "\"WiFi " D_JSON_LINK_COUNT "\":%d,\"WiFi " D_JSON_DOWNTIME "\":\"%s\",\"" D_JSON_MQTT_COUNT "\":%d,\"LoadAvg\":%lu}"), my_version, my_image, GetBuildDateAndTime().c_str(), ModuleName().c_str(), GetResetReason().c_str(), GetUptime().c_str(), my_hostname, WiFi.localIP().toString().c_str(), WifiGetRssiAsQuality(WiFi.RSSI()), - WiFi.RSSI(), WifiLinkCount(), WifiDowntime().c_str(), MqttConnectCount(), loop_load_avg); + WiFi.RSSI(), WifiLinkCount(), WifiDowntime().c_str(), MqttConnectCount(), TasmotaGlobal.loop_load_avg); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_HASS_STATE)); } diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index f750302cc..f465b44f3 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -1123,7 +1123,7 @@ bool Xdrv16(uint8_t function) TuyaSendCmd(TUYA_CMD_HEARTBEAT); } #ifdef USE_TUYA_TIME - if (!(uptime % 60)) { + if (!(TasmotaGlobal.uptime % 60)) { TuyaSetTime(); } #endif //USE_TUYA_TIME diff --git a/tasmota/xdrv_18_armtronix_dimmers.ino b/tasmota/xdrv_18_armtronix_dimmers.ino index 710697a28..63fb5500b 100644 --- a/tasmota/xdrv_18_armtronix_dimmers.ino +++ b/tasmota/xdrv_18_armtronix_dimmers.ino @@ -182,7 +182,7 @@ bool Xdrv18(uint8_t function) case FUNC_EVERY_SECOND: if (ArmtronixSerial) { if (Armtronix.wifi_state!=WifiState()) { ArmtronixSetWifiLed(); } - if (uptime &1) { + if (TasmotaGlobal.uptime &1) { ArmtronixSerial->println("Status"); } } diff --git a/tasmota/xdrv_22_sonoff_ifan.ino b/tasmota/xdrv_22_sonoff_ifan.ino index a51265f99..638106576 100644 --- a/tasmota/xdrv_22_sonoff_ifan.ino +++ b/tasmota/xdrv_22_sonoff_ifan.ino @@ -233,7 +233,7 @@ void SonoffIfanUpdate(void) } } - if (ifan_restart_flag && (4 == uptime) && (SONOFF_IFAN02 == my_module_type)) { // Microcontroller needs 3 seconds before accepting commands + if (ifan_restart_flag && (4 == TasmotaGlobal.uptime) && (SONOFF_IFAN02 == my_module_type)) { // Microcontroller needs 3 seconds before accepting commands ifan_restart_flag = false; SetDevicePower(1, SRC_RETRY); // Sync with default power on state microcontroller being Light ON and Fan OFF SetDevicePower(power, SRC_RETRY); // Set required power on state diff --git a/tasmota/xdrv_26_ariluxrf.ino b/tasmota/xdrv_26_ariluxrf.ino index d4491423d..b9e2f6c56 100644 --- a/tasmota/xdrv_26_ariluxrf.ino +++ b/tasmota/xdrv_26_ariluxrf.ino @@ -179,7 +179,7 @@ bool Xdrv26(uint8_t function) if (PinUsed(GPIO_ARIRFRCV)) { AriluxRfHandler(); } break; case FUNC_EVERY_SECOND: - if (10 == uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts + if (10 == TasmotaGlobal.uptime) { AriluxRfInit(); } // Needs rest before enabling RF interrupts break; } return result; diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index 0d7f38748..8e4b9c133 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -522,8 +522,8 @@ void ShutterAllowPreStartProcedure(uint8_t i) AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start. var%d <99>=<%s>, max10s?"),i+i, rules_vars[i]); rules_flag.shutter_moving = 1; XdrvRulesProcess(); - uptime_Local = uptime; - while (uptime_Local+10 > uptime && (String)rules_vars[i] == "99") { + uptime_Local = TasmotaGlobal.uptime; + while (uptime_Local+10 > TasmotaGlobal.uptime && (String)rules_vars[i] == "99") { loop(); } AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start. Done")); diff --git a/tasmota/xdrv_39_thermostat.ino b/tasmota/xdrv_39_thermostat.ino index 2fa479d46..bc53190f3 100644 --- a/tasmota/xdrv_39_thermostat.ino +++ b/tasmota/xdrv_39_thermostat.ino @@ -367,7 +367,7 @@ int16_t ThermostatFahrenheitToCelsius(const int32_t deg, uint8_t conv_type) { void ThermostatSignalPreProcessingSlow(uint8_t ctr_output) { // Update input sensor status - if ((uptime - Thermostat[ctr_output].timestamp_temp_measured_update) > ((uint32_t)Thermostat[ctr_output].time_sens_lost * 60)) { + if ((TasmotaGlobal.uptime - Thermostat[ctr_output].timestamp_temp_measured_update) > ((uint32_t)Thermostat[ctr_output].time_sens_lost * 60)) { Thermostat[ctr_output].status.sensor_alive = IFACE_OFF; Thermostat[ctr_output].temp_measured_gradient = 0; Thermostat[ctr_output].temp_measured = 0; @@ -392,7 +392,7 @@ void ThermostatSignalProcessingFast(uint8_t ctr_output) Thermostat[ctr_output].status.status_input = (uint32_t)ThermostatInputStatus(Thermostat[ctr_output].status.input_switch_number); // Update timestamp of last input if (Thermostat[ctr_output].status.status_input == IFACE_ON) { - Thermostat[ctr_output].timestamp_input_on = uptime; + Thermostat[ctr_output].timestamp_input_on = TasmotaGlobal.uptime; } // Update real status of the output Thermostat[ctr_output].status.status_output = (uint32_t)ThermostatOutputStatus(Thermostat[ctr_output].status.output_relay_number); @@ -453,7 +453,7 @@ void ThermostatHybridCtrPhase(uint8_t ctr_output) // If ramp-up offtime counter has been initalized // AND ramp-up offtime counter value reached if((Thermostat[ctr_output].time_ctr_checkpoint != 0) - && (uptime >= Thermostat[ctr_output].time_ctr_checkpoint)) { + && (TasmotaGlobal.uptime >= Thermostat[ctr_output].time_ctr_checkpoint)) { // Reset pause period Thermostat[ctr_output].time_ctr_checkpoint = 0; // Reset timers @@ -468,13 +468,13 @@ void ThermostatHybridCtrPhase(uint8_t ctr_output) // AND temp target has changed // AND value of temp target - actual temperature bigger than threshold for heating and lower for cooling // then go to ramp-up - if (((uptime - Thermostat[ctr_output].timestamp_output_off) > (60 * (uint32_t)Thermostat[ctr_output].time_allow_rampup)) + if (((TasmotaGlobal.uptime - Thermostat[ctr_output].timestamp_output_off) > (60 * (uint32_t)Thermostat[ctr_output].time_allow_rampup)) && (Thermostat[ctr_output].temp_target_level != Thermostat[ctr_output].temp_target_level_ctr) && ( ( (Thermostat[ctr_output].temp_target_level - Thermostat[ctr_output].temp_measured > Thermostat[ctr_output].temp_rampup_delta_in) && (flag_heating)) || ( (Thermostat[ctr_output].temp_measured - Thermostat[ctr_output].temp_target_level > Thermostat[ctr_output].temp_rampup_delta_in) && (!flag_heating)))) { - Thermostat[ctr_output].timestamp_rampup_start = uptime; + Thermostat[ctr_output].timestamp_rampup_start = TasmotaGlobal.uptime; Thermostat[ctr_output].temp_rampup_start = Thermostat[ctr_output].temp_measured; Thermostat[ctr_output].temp_rampup_meas_gradient = 0; Thermostat[ctr_output].time_rampup_deadtime = 0; @@ -541,7 +541,7 @@ bool ThermostatStateManualToAuto(uint8_t ctr_output) // then go to automatic if ((Thermostat[ctr_output].status.status_input == IFACE_OFF) &&(Thermostat[ctr_output].status.sensor_alive == IFACE_ON) - && ((uptime - Thermostat[ctr_output].timestamp_input_on) > ((uint32_t)Thermostat[ctr_output].time_manual_to_auto * 60))) { + && ((TasmotaGlobal.uptime - Thermostat[ctr_output].timestamp_input_on) > ((uint32_t)Thermostat[ctr_output].time_manual_to_auto * 60))) { change_state = true; } return change_state; @@ -608,7 +608,7 @@ void ThermostatOutputRelay(uint8_t ctr_output, uint32_t command) ExecuteCommandPower(Thermostat[ctr_output].status.output_relay_number, POWER_OFF, SRC_THERMOSTAT); } //#endif // DEBUG_THERMOSTAT - Thermostat[ctr_output].timestamp_output_off = uptime; + Thermostat[ctr_output].timestamp_output_off = TasmotaGlobal.uptime; Thermostat[ctr_output].status.status_output = IFACE_OFF; #ifdef DEBUG_THERMOSTAT ThermostatVirtualSwitch(ctr_output); @@ -793,15 +793,15 @@ void ThermostatCalculatePI(uint8_t ctr_output) } // Adjust output switch point - Thermostat[ctr_output].time_ctr_changepoint = uptime + (uint32_t)Thermostat[ctr_output].time_total_pi; + Thermostat[ctr_output].time_ctr_changepoint = TasmotaGlobal.uptime + (uint32_t)Thermostat[ctr_output].time_total_pi; // Adjust next cycle point - Thermostat[ctr_output].time_ctr_checkpoint = uptime + ((uint32_t)Thermostat[ctr_output].time_pi_cycle * 60); + Thermostat[ctr_output].time_ctr_checkpoint = TasmotaGlobal.uptime + ((uint32_t)Thermostat[ctr_output].time_pi_cycle * 60); } void ThermostatWorkAutomaticPI(uint8_t ctr_output) { bool flag_heating = (Thermostat[ctr_output].status.climate_mode == CLIMATE_HEATING); - if ( (uptime >= Thermostat[ctr_output].time_ctr_checkpoint) + if ( (TasmotaGlobal.uptime >= Thermostat[ctr_output].time_ctr_checkpoint) || (Thermostat[ctr_output].temp_target_level != Thermostat[ctr_output].temp_target_level_ctr) || ( (( (Thermostat[ctr_output].temp_measured < Thermostat[ctr_output].temp_target_level) && (Thermostat[ctr_output].temp_measured_gradient < 0) @@ -815,7 +815,7 @@ void ThermostatWorkAutomaticPI(uint8_t ctr_output) // Reset cycle active Thermostat[ctr_output].status.status_cycle_active = CYCLE_OFF; } - if (uptime < Thermostat[ctr_output].time_ctr_changepoint) { + if (TasmotaGlobal.uptime < Thermostat[ctr_output].time_ctr_changepoint) { Thermostat[ctr_output].status.status_cycle_active = CYCLE_ON; Thermostat[ctr_output].status.command_output = IFACE_ON; } @@ -842,7 +842,7 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) } // Update time in ramp-up as well as delta temp - time_in_rampup = uptime - Thermostat[ctr_output].timestamp_rampup_start; + time_in_rampup = TasmotaGlobal.uptime - Thermostat[ctr_output].timestamp_rampup_start; temp_delta_rampup = Thermostat[ctr_output].temp_measured - Thermostat[ctr_output].temp_rampup_start; // Init command output status to true Thermostat[ctr_output].status.command_output = IFACE_ON; @@ -873,14 +873,14 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) } // Calculate absolute gradient since start of ramp-up (considering deadtime) in thousandths of º/hour Thermostat[ctr_output].temp_rampup_meas_gradient = (int32_t)((360000 * (int32_t)temp_delta_rampup) / (int32_t)time_in_rampup); - Thermostat[ctr_output].time_rampup_nextcycle = uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); + Thermostat[ctr_output].time_rampup_nextcycle = TasmotaGlobal.uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); // Set auxiliary variables Thermostat[ctr_output].temp_rampup_cycle = Thermostat[ctr_output].temp_measured; - Thermostat[ctr_output].time_ctr_changepoint = uptime + (60 * (uint32_t)Thermostat[ctr_output].time_rampup_max); + Thermostat[ctr_output].time_ctr_changepoint = TasmotaGlobal.uptime + (60 * (uint32_t)Thermostat[ctr_output].time_rampup_max); Thermostat[ctr_output].temp_rampup_output_off = Thermostat[ctr_output].temp_target_level_ctr; } // Gradient calculation every time_rampup_cycle - else if ((Thermostat[ctr_output].time_rampup_deadtime > 0) && (uptime >= Thermostat[ctr_output].time_rampup_nextcycle)) { + else if ((Thermostat[ctr_output].time_rampup_deadtime > 0) && (TasmotaGlobal.uptime >= Thermostat[ctr_output].time_rampup_nextcycle)) { // Calculate temp. gradient in º/hour and set again time_rampup_nextcycle and temp_rampup_cycle // temp_rampup_meas_gradient = ((3600 * temp_delta_rampup) / (os.time() - time_rampup_nextcycle)) temp_delta_rampup = Thermostat[ctr_output].temp_measured - Thermostat[ctr_output].temp_rampup_cycle; @@ -902,7 +902,7 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) // y = (((y2-y1)/(x2-x1))*(x-x1)) + y1 Thermostat[ctr_output].temp_rampup_output_off = (int16_t)(((int32_t)temp_delta_rampup * (int32_t)(Thermostat[ctr_output].time_ctr_changepoint - (uptime - (time_total_rampup)))) / (int32_t)(time_total_rampup * Thermostat[ctr_output].counter_rampup_cycles)) + Thermostat[ctr_output].temp_rampup_cycle; // Set auxiliary variables - Thermostat[ctr_output].time_rampup_nextcycle = uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); + Thermostat[ctr_output].time_rampup_nextcycle = TasmotaGlobal.uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); Thermostat[ctr_output].temp_rampup_cycle = Thermostat[ctr_output].temp_measured; // Reset period counter Thermostat[ctr_output].counter_rampup_cycles = 1; @@ -911,9 +911,9 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) // Increase the period counter Thermostat[ctr_output].counter_rampup_cycles++; // Set another period - Thermostat[ctr_output].time_rampup_nextcycle = uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); + Thermostat[ctr_output].time_rampup_nextcycle = TasmotaGlobal.uptime + ((uint32_t)Thermostat[ctr_output].time_rampup_cycle * 60); // Reset time_ctr_changepoint and temp_rampup_output_off - Thermostat[ctr_output].time_ctr_changepoint = uptime + (60 * (uint32_t)Thermostat[ctr_output].time_rampup_max) - time_in_rampup; + Thermostat[ctr_output].time_ctr_changepoint = TasmotaGlobal.uptime + (60 * (uint32_t)Thermostat[ctr_output].time_rampup_max) - time_in_rampup; Thermostat[ctr_output].temp_rampup_output_off = Thermostat[ctr_output].temp_target_level_ctr; } // Set time to get out of ramp-up @@ -927,7 +927,7 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) // or gradient is <= 0 for heating of >= 0 for cooling if ((Thermostat[ctr_output].time_rampup_deadtime == 0) || (Thermostat[ctr_output].time_ctr_checkpoint == 0) - || (uptime < Thermostat[ctr_output].time_ctr_changepoint) + || (TasmotaGlobal.uptime < Thermostat[ctr_output].time_ctr_changepoint) || ( ((Thermostat[ctr_output].temp_measured < Thermostat[ctr_output].temp_rampup_output_off) && (flag_heating)) || ((Thermostat[ctr_output].temp_measured > Thermostat[ctr_output].temp_rampup_output_off) @@ -951,7 +951,7 @@ void ThermostatWorkAutomaticRampUp(uint8_t ctr_output) Thermostat[ctr_output].temp_pi_accum_error = Thermostat[ctr_output].temp_rampup_pi_acc_error; } // Set to now time to get out of ramp-up - Thermostat[ctr_output].time_ctr_checkpoint = uptime; + Thermostat[ctr_output].time_ctr_checkpoint = TasmotaGlobal.uptime; // Switch Off output Thermostat[ctr_output].status.command_output = IFACE_OFF; } @@ -971,7 +971,7 @@ void ThermostatPeakDetectorInit(uint8_t ctr_output) Thermostat[ctr_output].peak_ctr = 0; Thermostat[ctr_output].temp_abs_max_atune = 0; Thermostat[ctr_output].temp_abs_min_atune = 100; - Thermostat[ctr_output].time_ctr_checkpoint = uptime + THERMOSTAT_TIME_MAX_AUTOTUNE; + Thermostat[ctr_output].time_ctr_checkpoint = TasmotaGlobal.uptime + THERMOSTAT_TIME_MAX_AUTOTUNE; } void ThermostatPeakDetector(uint8_t ctr_output) @@ -1020,7 +1020,7 @@ void ThermostatPeakDetector(uint8_t ctr_output) if ( (cond_peak_2) && (abs(Thermostat[ctr_output].temp_measured - Thermostat[ctr_output].temp_peaks_atune[peak_num]) > Thermostat[ctr_output].temp_band_no_peak_det)) { // Register peak timestamp; - Thermostat[ctr_output].time_peak_timestamps_atune[peak_num] = (uptime / 60); + Thermostat[ctr_output].time_peak_timestamps_atune[peak_num] = (TasmotaGlobal.uptime / 60); Thermostat[ctr_output].peak_ctr++; peak_transition = true; } @@ -1040,7 +1040,7 @@ void ThermostatPeakDetector(uint8_t ctr_output) && (abs(Thermostat[ctr_output].temp_measured - Thermostat[ctr_output].temp_peaks_atune[peak_num]) > Thermostat[ctr_output].temp_band_no_peak_det)) { // Calculate period // Register peak timestamp; - Thermostat[ctr_output].time_peak_timestamps_atune[peak_num] = (uptime / 60); + Thermostat[ctr_output].time_peak_timestamps_atune[peak_num] = (TasmotaGlobal.uptime / 60); Thermostat[ctr_output].peak_ctr++; peak_transition = true; } @@ -1117,17 +1117,17 @@ void ThermostatWorkAutomaticPIAutotune(uint8_t ctr_output) bool flag_heating = (Thermostat[ctr_output].status.climate_mode == CLIMATE_HEATING); // If no timeout of the PI Autotune function // AND no change in setpoint - if ((uptime < Thermostat[ctr_output].time_ctr_checkpoint) + if ((TasmotaGlobal.uptime < Thermostat[ctr_output].time_ctr_checkpoint) &&(Thermostat[ctr_output].temp_target_level_ctr == Thermostat[ctr_output].temp_target_level)) { - if (uptime >= Thermostat[ctr_output].time_ctr_checkpoint) { + if (TasmotaGlobal.uptime >= Thermostat[ctr_output].time_ctr_checkpoint) { Thermostat[ctr_output].temp_target_level_ctr = Thermostat[ctr_output].temp_target_level; // Calculate time_ctr_changepoint - Thermostat[ctr_output].time_ctr_changepoint = uptime + (((uint32_t)Thermostat[ctr_output].time_pi_cycle * (uint32_t)Thermostat[ctr_output].dutycycle_step_autotune) / (uint32_t)100); + Thermostat[ctr_output].time_ctr_changepoint = TasmotaGlobal.uptime + (((uint32_t)Thermostat[ctr_output].time_pi_cycle * (uint32_t)Thermostat[ctr_output].dutycycle_step_autotune) / (uint32_t)100); // Reset cycle active Thermostat[ctr_output].status.status_cycle_active = CYCLE_OFF; } // Set Output On/Off depending on the changepoint - if (uptime < Thermostat[ctr_output].time_ctr_changepoint) { + if (TasmotaGlobal.uptime < Thermostat[ctr_output].time_ctr_changepoint) { Thermostat[ctr_output].status.status_cycle_active = CYCLE_ON; Thermostat[ctr_output].status.command_output = IFACE_ON; } @@ -1318,7 +1318,7 @@ void ThermostatDebug(uint8_t ctr_output) AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat[ctr_output].temp_rampup_output_off: %s"), result_chr); dtostrfd(Thermostat[ctr_output].time_ctr_checkpoint, 0, result_chr); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Thermostat[ctr_output].time_ctr_checkpoint: %s"), result_chr); - dtostrfd(uptime, 0, result_chr); + dtostrfd(TasmotaGlobal.uptime, 0, result_chr); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("uptime: %s"), result_chr); dtostrfd(power, 0, result_chr); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("power: %s"), result_chr); @@ -1341,7 +1341,7 @@ void ThermostatGetLocalSensor(uint8_t ctr_output) { if ( (value >= -1000) && (value <= 1000) && (Thermostat[ctr_output].status.sensor_type == SENSOR_LOCAL)) { - uint32_t timestamp = uptime; + uint32_t timestamp = TasmotaGlobal.uptime; // Calculate temperature gradient if temperature value has changed if (value != Thermostat[ctr_output].temp_measured) { int32_t temp_delta = (value - Thermostat[ctr_output].temp_measured); // in tenths of degrees @@ -1385,7 +1385,7 @@ void CmndClimateModeSet(void) if ((value >= CLIMATE_HEATING) && (value < CLIMATE_MODES_MAX)) { Thermostat[ctr_output].status.climate_mode = value; // Trigger a restart of the controller - Thermostat[ctr_output].time_ctr_checkpoint = uptime; + Thermostat[ctr_output].time_ctr_checkpoint = TasmotaGlobal.uptime; } } ResponseCmndNumber((int)Thermostat[ctr_output].status.climate_mode); @@ -1428,7 +1428,7 @@ void CmndControllerModeSet(void) if ((value >= CTR_HYBRID) && (value < CTR_MODES_MAX)) { Thermostat[ctr_output].status.controller_mode = value; // Reset controller variables - Thermostat[ctr_output].timestamp_rampup_start = uptime; + Thermostat[ctr_output].timestamp_rampup_start = TasmotaGlobal.uptime; Thermostat[ctr_output].temp_rampup_start = Thermostat[ctr_output].temp_measured; Thermostat[ctr_output].temp_rampup_meas_gradient = 0; Thermostat[ctr_output].time_rampup_deadtime = 0; @@ -1449,7 +1449,7 @@ void CmndInputSwitchSet(void) uint8_t value = (uint8_t)(XdrvMailbox.payload); if (ThermostatSwitchIdValid(value)) { Thermostat[ctr_output].status.input_switch_number = value; - Thermostat[ctr_output].timestamp_input_on = uptime; + Thermostat[ctr_output].timestamp_input_on = TasmotaGlobal.uptime; } } ResponseCmndNumber((int)Thermostat[ctr_output].status.input_switch_number); @@ -1538,7 +1538,7 @@ void CmndTempMeasuredSet(void) if ( (value >= -1000) && (value <= 1000) && (Thermostat[ctr_output].status.sensor_type == SENSOR_MQTT)) { - uint32_t timestamp = uptime; + uint32_t timestamp = TasmotaGlobal.uptime; // Calculate temperature gradient if temperature value has changed if (value != Thermostat[ctr_output].temp_measured) { int32_t temp_delta = (value - Thermostat[ctr_output].temp_measured); // in tenths of degrees diff --git a/tasmota/xdrv_40_telegram.ino b/tasmota/xdrv_40_telegram.ino index ddec0b3fb..4bfe20aca 100644 --- a/tasmota/xdrv_40_telegram.ino +++ b/tasmota/xdrv_40_telegram.ino @@ -289,9 +289,9 @@ void TelegramSendGetMe(void) { String TelegramExecuteCommand(const char *svalue) { String response = ""; - uint32_t curridx = web_log_index; + uint32_t curridx = TasmotaGlobal.web_log_index; ExecuteCommand(svalue, SRC_CHAT); - if (web_log_index != curridx) { + if (TasmotaGlobal.web_log_index != curridx) { uint32_t counter = curridx; response = F("{"); bool cflg = false; @@ -315,7 +315,7 @@ String TelegramExecuteCommand(const char *svalue) { counter++; counter &= 0xFF; if (!counter) counter++; // Skip 0 as it is not allowed - } while (counter != web_log_index); + } while (counter != TasmotaGlobal.web_log_index); response += F("}"); } else { response = F("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}"); diff --git a/tasmota/xnrg_03_pzem004t.ino b/tasmota/xnrg_03_pzem004t.ino index f06b34b0e..51001b847 100644 --- a/tasmota/xnrg_03_pzem004t.ino +++ b/tasmota/xnrg_03_pzem004t.ino @@ -194,7 +194,7 @@ void PzemEvery250ms(void) Pzem.energy += value; if (Pzem.phase == Energy.phase_count -1) { if (Pzem.energy > Pzem.last_energy) { // Handle missed phase - if (uptime > PZEM_STABILIZE) { + if (TasmotaGlobal.uptime > PZEM_STABILIZE) { EnergyUpdateTotal(Pzem.energy, false); } Pzem.last_energy = Pzem.energy; @@ -232,7 +232,7 @@ void PzemEvery250ms(void) } else { Pzem.send_retry--; - if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (uptime < PZEM_STABILIZE)) { + if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (TasmotaGlobal.uptime < PZEM_STABILIZE)) { Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart } } @@ -285,7 +285,7 @@ bool Xnrg03(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (PzemSerial && (uptime > 4)) { PzemEvery250ms(); } + if (PzemSerial && (TasmotaGlobal.uptime > 4)) { PzemEvery250ms(); } break; case FUNC_COMMAND: result = PzemCommand(); diff --git a/tasmota/xnrg_05_pzem_ac.ino b/tasmota/xnrg_05_pzem_ac.ino index bd656a874..5ebddc0d7 100644 --- a/tasmota/xnrg_05_pzem_ac.ino +++ b/tasmota/xnrg_05_pzem_ac.ino @@ -81,7 +81,7 @@ void PzemAcEverySecond(void) PzemAc.energy += (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh if (PzemAc.phase == Energy.phase_count -1) { if (PzemAc.energy > PzemAc.last_energy) { // Handle missed phase - if (uptime > PZEM_AC_STABILIZE) { + if (TasmotaGlobal.uptime > PZEM_AC_STABILIZE) { EnergyUpdateTotal(PzemAc.energy, false); } PzemAc.last_energy = PzemAc.energy; @@ -109,7 +109,7 @@ void PzemAcEverySecond(void) } else { PzemAc.send_retry--; - if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (uptime < PZEM_AC_STABILIZE)) { + if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (TasmotaGlobal.uptime < PZEM_AC_STABILIZE)) { Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart } } @@ -158,7 +158,7 @@ bool Xnrg05(uint8_t function) switch (function) { case FUNC_ENERGY_EVERY_SECOND: - if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875 + if (TasmotaGlobal.uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875 break; case FUNC_COMMAND: result = PzemAcCommand(); diff --git a/tasmota/xnrg_06_pzem_dc.ino b/tasmota/xnrg_06_pzem_dc.ino index 444861fb0..3b920204e 100644 --- a/tasmota/xnrg_06_pzem_dc.ino +++ b/tasmota/xnrg_06_pzem_dc.ino @@ -78,7 +78,7 @@ void PzemDcEverySecond(void) PzemDc.energy += (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh if (PzemDc.channel == Energy.phase_count -1) { if (PzemDc.energy > PzemDc.last_energy) { // Handle missed channel - if (uptime > PZEM_DC_STABILIZE) { + if (TasmotaGlobal.uptime > PZEM_DC_STABILIZE) { EnergyUpdateTotal(PzemDc.energy, false); } PzemDc.last_energy = PzemDc.energy; @@ -105,7 +105,7 @@ void PzemDcEverySecond(void) } else { PzemDc.send_retry--; - if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (uptime < PZEM_DC_STABILIZE)) { + if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (TasmotaGlobal.uptime < PZEM_DC_STABILIZE)) { Energy.phase_count--; // Decrement channels if no response after retry within 30 seconds after restart } } @@ -155,7 +155,7 @@ bool Xnrg06(uint8_t function) switch (function) { case FUNC_ENERGY_EVERY_SECOND: - if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875 + if (TasmotaGlobal.uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875 break; case FUNC_COMMAND: result = PzemDcCommand(); diff --git a/tasmota/xnrg_08_sdm120.ino b/tasmota/xnrg_08_sdm120.ino index 8f764ad52..189b76a96 100644 --- a/tasmota/xnrg_08_sdm120.ino +++ b/tasmota/xnrg_08_sdm120.ino @@ -242,7 +242,7 @@ bool Xnrg08(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { SDM120Every250ms(); } + if (TasmotaGlobal.uptime > 4) { SDM120Every250ms(); } break; case FUNC_JSON_APPEND: Sdm220Show(1); diff --git a/tasmota/xnrg_09_dds2382.ino b/tasmota/xnrg_09_dds2382.ino index 7acb36f05..06d5aaad0 100644 --- a/tasmota/xnrg_09_dds2382.ino +++ b/tasmota/xnrg_09_dds2382.ino @@ -117,7 +117,7 @@ bool Xnrg09(uint8_t function) switch (function) { case FUNC_ENERGY_EVERY_SECOND: - if (uptime > 4) { Dds2382EverySecond(); } + if (TasmotaGlobal.uptime > 4) { Dds2382EverySecond(); } break; case FUNC_INIT: Dds2382SnsInit(); diff --git a/tasmota/xnrg_10_sdm630.ino b/tasmota/xnrg_10_sdm630.ino index c1f36b110..58a3dff0f 100644 --- a/tasmota/xnrg_10_sdm630.ino +++ b/tasmota/xnrg_10_sdm630.ino @@ -242,7 +242,7 @@ bool Xnrg10(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { SDM630Every250ms(); } + if (TasmotaGlobal.uptime > 4) { SDM630Every250ms(); } break; case FUNC_INIT: Sdm630SnsInit(); diff --git a/tasmota/xnrg_11_ddsu666.ino b/tasmota/xnrg_11_ddsu666.ino index f01ad50a5..49e24a19b 100644 --- a/tasmota/xnrg_11_ddsu666.ino +++ b/tasmota/xnrg_11_ddsu666.ino @@ -159,7 +159,7 @@ bool Xnrg11(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { DDSU666Every250ms(); } + if (TasmotaGlobal.uptime > 4) { DDSU666Every250ms(); } break; case FUNC_INIT: Ddsu666SnsInit(); diff --git a/tasmota/xnrg_12_solaxX1.ino b/tasmota/xnrg_12_solaxX1.ino index 513cf1317..8a583fdec 100644 --- a/tasmota/xnrg_12_solaxX1.ino +++ b/tasmota/xnrg_12_solaxX1.ino @@ -505,7 +505,7 @@ bool Xnrg12(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { solaxX1250MSecond(); } + if (TasmotaGlobal.uptime > 4) { solaxX1250MSecond(); } break; case FUNC_JSON_APPEND: solaxX1Show(1); diff --git a/tasmota/xnrg_13_fif_le01mr.ino b/tasmota/xnrg_13_fif_le01mr.ino index f8d25e06f..c0060e55d 100644 --- a/tasmota/xnrg_13_fif_le01mr.ino +++ b/tasmota/xnrg_13_fif_le01mr.ino @@ -269,7 +269,7 @@ bool Xnrg13(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { + if (TasmotaGlobal.uptime > 4) { FifLEEvery250ms(); } break; diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index e87d899f8..c4d653dd3 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -20,73 +20,73 @@ #ifdef USE_ENERGY_SENSOR #ifdef USE_TELEINFO /*********************************************************************************************\ - * Teleinfo : French energy provider metering telemety data + * Teleinfo : French energy provider metering telemety data * Source: http://hallard.me/category/tinfo/ * * Denky ESP32 Teleinfo Template * {"NAME":"Denky (Teleinfo)","GPIO":[1,1,1,1,5664,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1376,1,1,0,0,0,0,1,5632,1,1,1,0,0,1],"FLAG":0,"BASE":1} - * + * * Denky (aka WifInfo) ESP8266 Teleinfo Template * {"NAME":"WifInfo v1.0a","GPIO":[17,255,255,255,6,5,255,255,7,210,255,255,255],"FLAG":15,"BASE":18} * {"NAME":"WifInfo","GPIO":[7,255,255,210,6,5,255,255,255,255,255,255,255],"FLAG":15,"BASE":18} - * + * \*********************************************************************************************/ -#define XNRG_15 15 +#define XNRG_15 15 #include "LibTeleinfo.h" #include -#define TINFO_READ_TIMEOUT 400 +#define TINFO_READ_TIMEOUT 400 // All contract type for legacy, standard mode has in clear text enum TInfoContrat{ - CONTRAT_BAS = 1, // BASE => Option Base. - CONTRAT_HC, // HC.. => Option Heures Creuses. - CONTRAT_EJP, // EJP. => Option EJP. + CONTRAT_BAS = 1, // BASE => Option Base. + CONTRAT_HC, // HC.. => Option Heures Creuses. + CONTRAT_EJP, // EJP. => Option EJP. CONTRAT_BBR, // BBRx => Option Tempo CONTRAT_END }; // contract displayed name for legacy, standard mode has in clear text -const char kContratName[] PROGMEM = +const char kContratName[] PROGMEM = "|Base|Heures Creuses|EJP|Bleu Blanc Rouge" ; // Received current contract value for legacy, standard mode has in clear text -const char kContratValue[] PROGMEM = +const char kContratValue[] PROGMEM = "|BASE|HC..|EJP.|BBR" ; // all tariff type for legacy, standard mode has in clear text enum TInfoTarif{ - TARIF_TH = 1, - TARIF_HC, TARIF_HP, + TARIF_TH = 1, + TARIF_HC, TARIF_HP, TARIF_HN, TARIF_PM, TARIF_CB, TARIF_CW, TARIF_CR, TARIF_PB, TARIF_PW, TARIF_PR, TARIF_END }; -// Received current tariff values +// Received current tariff values // for legacy, standard mode has in clear text -const char kTarifValue[] PROGMEM = - "|TH..|HC..|HP.." - "|HN..|PM.." - "|HCJB|HCJW|HCJR" - "|HPJB|HPJW|HPJR" +const char kTarifValue[] PROGMEM = + "|TH..|HC..|HP.." + "|HN..|PM.." + "|HCJB|HCJW|HCJR" + "|HPJB|HPJW|HPJR" ; // tariff displayed name (for legacy, standard mode has in clear text) -const char kTarifName[] PROGMEM = - "|Toutes|Creuses|Pleines" - "|Normales|Pointe Mobile" - "|Creuses Bleu|Creuses Blanc|Creuse Rouges" - "|Pleines Bleu|Pleines Blanc|Pleines Rouges" +const char kTarifName[] PROGMEM = + "|Toutes|Creuses|Pleines" + "|Normales|Pointe Mobile" + "|Creuses Bleu|Creuses Blanc|Creuse Rouges" + "|Pleines Bleu|Pleines Blanc|Pleines Rouges" ; // Label used to do some post processing and/or calculation enum TInfoLabel{ - LABEL_BASE = 1, + LABEL_BASE = 1, LABEL_ADCO, LABEL_ADSC, LABEL_HCHC, LABEL_HCHP, LABEL_EAST, LABEL_EASF01, LABEL_EASF02, LABEL_OPTARIF, LABEL_NGTF, LABEL_ISOUSC, LABEL_PREF, LABEL_PTEC, LABEL_LTARF, LABEL_NTARF, @@ -96,7 +96,7 @@ enum TInfoLabel{ LABEL_END }; -const char kLabel[] PROGMEM = +const char kLabel[] PROGMEM = "|BASE|ADCO|ADSC" "|HCHC|HCHP|EAST|EASF01|EASF02" "|OPTARIF|NGTF|ISOUSC|PREF|PTEC|LTARF|NTARF" @@ -117,7 +117,7 @@ int isousc; /*********************************************************************************************/ /* ====================================================================== -Function: getValueFromLabelIndex +Function: getValueFromLabelIndex Purpose : return label value from label index Input : label index to search for Output : value filled @@ -133,14 +133,14 @@ char * getValueFromLabelIndex(int labelIndex, char * value) } /* ====================================================================== -Function: ADPSCallback +Function: ADPSCallback Purpose : called by library when we detected a ADPS on any phased -Input : phase number +Input : phase number 0 for ADPS (monophase) 1 for ADIR1 triphase 2 for ADIR2 triphase 3 for ADIR3 triphase -Output : - +Output : - Comments: should have been initialised with a tinfo.attachADPSCallback(ADPSCallback()) ====================================================================== */ @@ -162,11 +162,11 @@ void ADPSCallback(uint8_t phase) } /* ====================================================================== -Function: DataCallback +Function: DataCallback Purpose : callback when we detected new or modified data received Input : linked list pointer on the concerned data current flags value -Output : - +Output : - Comments: - ====================================================================== */ void DataCallback(struct _ValueList * me, uint8_t flags) @@ -180,7 +180,7 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // Find the label index for ( ilabel = 1 ; ilabel < LABEL_END ; ilabel++) { GetTextIndexed(labelName, sizeof(labelName), ilabel, kLabel); - if (!strcmp(labelName, me->name)) { + if (!strcmp(labelName, me->name)) { break; } } @@ -198,24 +198,24 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // Find the tariff index for (tarif = TARIF_TH ; tarif < TARIF_END ; tarif++) { GetTextIndexed(tarif_value, sizeof(tarif_value), tarif-1, kTarifValue); - if (!strcmp(tarif_value, me->value)) { + if (!strcmp(tarif_value, me->value)) { break; } } AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Tarif changed, now '%s' (%d)"), me->value, tarif); - } + } // Current tariff (standard is in clear text in value) else if (ilabel == LABEL_LTARF) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Tarif name changed, now '%s'"), me->value); - } + } // Current tariff (standard index is is in clear text in value) else if (ilabel == LABEL_NTARF) { tarif = atoi(me->value); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Tarif index changed, now '%d'"), tarif); - } + } // Voltage V (not present on all Smart Meter) @@ -257,14 +257,14 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // Heures creuses get heures pleines if (ilabel == LABEL_HCHC) { hc = atoi(me->value); - if ( getValueFromLabelIndex(LABEL_HCHP, value) ) { + if ( getValueFromLabelIndex(LABEL_HCHP, value) ) { hp = atoi(value); } - + // Heures pleines, get heures creuses } else if (ilabel == LABEL_HCHP) { hp = atoi(me->value); - if ( getValueFromLabelIndex(LABEL_HCHC, value) ) { + if ( getValueFromLabelIndex(LABEL_HCHC, value) ) { hc = atoi(value); } } @@ -272,17 +272,17 @@ void DataCallback(struct _ValueList * me, uint8_t flags) AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u HP:%u Total:%u"), hc, hp, total); } - if (!Settings.flag4.teleinfo_rawdata) { - EnergyUpdateTotal(total/1000.0f, true); + if (!Settings.flag4.teleinfo_rawdata) { + EnergyUpdateTotal(total/1000.0f, true); } } - // Wh total index (standard) + // Wh total index (standard) else if ( ilabel == LABEL_EAST) { uint32_t total = atoi(me->value); - if (!Settings.flag4.teleinfo_rawdata) { - EnergyUpdateTotal(total/1000.0f, true); + if (!Settings.flag4.teleinfo_rawdata) { + EnergyUpdateTotal(total/1000.0f, true); } AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%uWh"), total); } @@ -304,45 +304,45 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // Find the contract index for (contrat = CONTRAT_BAS ; contrat < CONTRAT_END ; contrat++) { GetTextIndexed(contrat_value, sizeof(contrat_value), contrat, kContratValue); - if (!strcmp(contrat_value, me->value)) { + if (!strcmp(contrat_value, me->value)) { break; } } AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Contract changed, now '%s' (%d)"), me->value, contrat); - } + } // Contract subscribed (standard is in clear text in value) else if (ilabel == LABEL_NGTF) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Contract changed, now '%s'"), me->value); - } + } // Contract subscribed (Power) else if (ilabel == LABEL_ISOUSC || ilabel == LABEL_PREF) { isousc = atoi( me->value); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: ISousc set to %d"), isousc); - } + } // Serial Number of device else if (ilabel == LABEL_ADCO || ilabel == LABEL_ADSC) { strcpy(serialNumber, me->value); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: %s set to %s"), me->name, serialNumber); - } + } } } - + } /* ====================================================================== -Function: responseDumpTInfo +Function: responseDumpTInfo Purpose : add teleinfo values into JSON response Input : 1st separator space if begining of JSON, else comma -Output : - +Output : - Comments: - ====================================================================== */ void ResponseAppendTInfo(char sep) @@ -383,17 +383,17 @@ void ResponseAppendTInfo(char sep) ResponseAppend_P( PSTR("%d"), atoi(me->value)); } - // Now JSON separator is needed + // Now JSON separator is needed sep =','; } } } /* ====================================================================== -Function: NewFrameCallback +Function: NewFrameCallback Purpose : callback when we received a complete Teleinfo frama Input : linked list pointer on the concerned data -Output : - +Output : - Comments: - ====================================================================== */ void NewFrameCallback(struct _ValueList * me) @@ -403,7 +403,7 @@ void NewFrameCallback(struct _ValueList * me) // send teleinfo full frame only if setup like that // see setOption108 - if (Settings.flag4.teleinfo_rawdata) { + if (Settings.flag4.teleinfo_rawdata) { Response_P(PSTR("{")); ResponseAppendTInfo(' '); ResponseJsonEnd(); @@ -414,10 +414,10 @@ void NewFrameCallback(struct _ValueList * me) } /* ====================================================================== -Function: TInfoDrvInit -Purpose : Tasmota core driver init +Function: TInfoDrvInit +Purpose : Tasmota core driver init Input : - -Output : - +Output : - Comments: - ====================================================================== */ void TInfoDrvInit(void) { @@ -428,10 +428,10 @@ void TInfoDrvInit(void) { } /* ====================================================================== -Function: TInfoInit -Purpose : Tasmota core device init +Function: TInfoInit +Purpose : Tasmota core device init Input : - -Output : - +Output : - Comments: - ====================================================================== */ void TInfoInit(void) @@ -439,16 +439,16 @@ void TInfoInit(void) int baudrate; // SetOption102 - Set Baud rate for Teleinfo serial communication (0 = 1200 or 1 = 9600) - if (Settings.flag4.teleinfo_baudrate) { - baudrate = 9600; + if (Settings.flag4.teleinfo_baudrate) { + baudrate = 9600; tinfo_mode = TINFO_MODE_STANDARD; } else { - baudrate = 1200; + baudrate = 1200; tinfo_mode = TINFO_MODE_HISTORIQUE; } AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: inferface speed %d bps"),baudrate); - + if (PinUsed(GPIO_TELEINFO_RX)) { uint8_t rx_pin = Pin(GPIO_TELEINFO_RX); AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: RX on GPIO%d"), rx_pin); @@ -456,7 +456,7 @@ void TInfoInit(void) // Enable Teleinfo pin used, control it if (PinUsed(GPIO_TELEINFO_ENABLE)) { uint8_t en_pin = Pin(GPIO_TELEINFO_ENABLE); - pinMode(en_pin, OUTPUT); + pinMode(en_pin, OUTPUT); digitalWrite(en_pin, HIGH); AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: Enable with GPIO%d"), en_pin); } else { @@ -472,7 +472,7 @@ void TInfoInit(void) #endif // Trick here even using SERIAL_7E1 or TS_SERIAL_7E1 - // this is not working, need to call SetSerialConfig after + // this is not working, need to call SetSerialConfig after if (TInfoSerial->begin(baudrate)) { @@ -481,9 +481,9 @@ void TInfoInit(void) ClaimSerial(); // This is a hack, looks like begin does not take into account - // the TS_SERIAL_7E1 configuration so on ESP8266 this is + // the TS_SERIAL_7E1 configuration so on ESP8266 this is // working only on Serial RX pin (Hardware Serial) for now - + //SetSerialConfig(TS_SERIAL_7E1); //TInfoSerial->setTimeout(TINFO_READ_TIMEOUT); @@ -499,8 +499,8 @@ void TInfoInit(void) tinfo.init(tinfo_mode); // Attach needed callbacks tinfo.attachADPS(ADPSCallback); - tinfo.attachData(DataCallback); - tinfo.attachNewFrame(NewFrameCallback); + tinfo.attachData(DataCallback); + tinfo.attachNewFrame(NewFrameCallback); tinfo_found = true; AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: Ready")); @@ -509,10 +509,10 @@ void TInfoInit(void) } /* ====================================================================== -Function: TInfoEvery250ms +Function: TInfoEvery250ms Purpose : Tasmota callback executed every 250ms Input : - -Output : - +Output : - Comments: - ====================================================================== */ void TInfoEvery250ms(void) @@ -536,10 +536,10 @@ void TInfoEvery250ms(void) } /* ====================================================================== -Function: TInfoShow +Function: TInfoShow Purpose : Tasmota callback executed to send telemetry or WEB display Input : - -Output : - +Output : - Comments: - ====================================================================== */ #ifdef USE_WEBSERVER @@ -556,7 +556,7 @@ const char HTTP_ENERGY_PMAX_TELEINFO[] PROGMEM = "{s}" D_MAX_POWER "{m}%d" D_UN void TInfoShow(bool json) { - // Since it's an Energy device , current, voltage and power are + // Since it's an Energy device , current, voltage and power are // already present on the telemetry frame. No need to add here // Just add the raw label/values of the teleinfo frame if (json) @@ -567,7 +567,7 @@ void TInfoShow(bool json) } // add teleinfo full frame only if no teleinfo raw data setup - if (!Settings.flag4.teleinfo_rawdata) { + if (!Settings.flag4.teleinfo_rawdata) { ResponseAppendTInfo(','); } @@ -640,7 +640,7 @@ bool Xnrg15(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { TInfoEvery250ms(); } + if (TasmotaGlobal.uptime > 4) { TInfoEvery250ms(); } break; case FUNC_JSON_APPEND: TInfoShow(1); diff --git a/tasmota/xnrg_16_iem3000.ino b/tasmota/xnrg_16_iem3000.ino index 807d142e3..66f957a0a 100644 --- a/tasmota/xnrg_16_iem3000.ino +++ b/tasmota/xnrg_16_iem3000.ino @@ -192,7 +192,7 @@ bool Xnrg16(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { IEM3000Every250ms(); } + if (TasmotaGlobal.uptime > 4) { IEM3000Every250ms(); } break; case FUNC_INIT: Iem3000SnsInit(); diff --git a/tasmota/xnrg_17_ornowe517.ino b/tasmota/xnrg_17_ornowe517.ino index c62cccc4a..2aa60577d 100644 --- a/tasmota/xnrg_17_ornowe517.ino +++ b/tasmota/xnrg_17_ornowe517.ino @@ -216,7 +216,7 @@ bool Xnrg17(uint8_t function) switch (function) { case FUNC_EVERY_250_MSECOND: - if (uptime > 4) { WE517Every250ms(); } + if (TasmotaGlobal.uptime > 4) { WE517Every250ms(); } break; case FUNC_INIT: We517SnsInit(); diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index e828c55d6..4d9176c26 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -457,7 +457,7 @@ void Ds18x20EverySecond(void) if (now < w1_power_until) return; #endif - if (uptime & 1 + if (TasmotaGlobal.uptime & 1 #ifdef W1_PARASITE_POWER // if more than 1 sensor and only parasite power: convert every cycle || ds18x20_sensors >= 2 diff --git a/tasmota/xsns_05_ds18x20_esp32.ino b/tasmota/xsns_05_ds18x20_esp32.ino index 1d622448c..8647bcf01 100644 --- a/tasmota/xsns_05_ds18x20_esp32.ino +++ b/tasmota/xsns_05_ds18x20_esp32.ino @@ -167,7 +167,7 @@ void Ds18x20EverySecond(void) { if (!ds18x20_sensors) { return; } - if (uptime & 1) { + if (TasmotaGlobal.uptime & 1) { // 2mS // Ds18x20Search(); // Check for changes in sensors number Ds18x20Convert(); // Start Conversion, takes up to one second diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index d2e47fe17..6bece3af1 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -228,7 +228,7 @@ void DhtInit(void) void DhtEverySecond(void) { - if (uptime &1) { // Every 2 seconds + if (TasmotaGlobal.uptime &1) { // Every 2 seconds for (uint32_t sensor = 0; sensor < dht_sensors; sensor++) { // DHT11 and AM2301 25mS per sensor, SI7021 5mS per sensor if (!DhtRead(sensor)) { diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index e58c5553f..50780f66c 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -172,7 +172,7 @@ void ShtDetect(void) void ShtEverySecond(void) { - if (!(uptime %4)) { // Every 4 seconds + if (!(TasmotaGlobal.uptime %4)) { // Every 4 seconds // 344mS if (!ShtRead()) { AddLogMissed(sht_types, sht_valid); diff --git a/tasmota/xsns_08_htu21.ino b/tasmota/xsns_08_htu21.ino index 1dc4d4fb1..1367279b6 100644 --- a/tasmota/xsns_08_htu21.ino +++ b/tasmota/xsns_08_htu21.ino @@ -236,7 +236,7 @@ void HtuDetect(void) void HtuEverySecond(void) { - if (uptime &1) { // Every 2 seconds + if (TasmotaGlobal.uptime &1) { // Every 2 seconds // HTU21: 68mS, SI70xx: 37mS if (!HtuRead()) { AddLogMissed(Htu.types, Htu.valid); diff --git a/tasmota/xsns_16_tsl2561.ino b/tasmota/xsns_16_tsl2561.ino index 573fc3b93..511344b19 100644 --- a/tasmota/xsns_16_tsl2561.ino +++ b/tasmota/xsns_16_tsl2561.ino @@ -82,7 +82,7 @@ void Tsl2561Detect(void) void Tsl2561EverySecond(void) { - if (!(uptime %2)) { // Every 2 seconds + if (!(TasmotaGlobal.uptime %2)) { // Every 2 seconds // ?mS - 4Sec if (!Tsl2561Read()) { AddLogMissed(tsl2561_types, tsl2561_valid); diff --git a/tasmota/xsns_21_sgp30.ino b/tasmota/xsns_21_sgp30.ino index 6f52f14a4..d55ecb277 100644 --- a/tasmota/xsns_21_sgp30.ino +++ b/tasmota/xsns_21_sgp30.ino @@ -83,7 +83,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) && !isnan(global_temperature_celsius)) { + if (TasmotaGlobal.global_update && (global_humidity > 0) && !isnan(global_temperature_celsius)) { // abs hum in mg/m3 sgp30_abshum = sgp30_AbsoluteHumidity(global_temperature_celsius, global_humidity); sgp.setHumidity(sgp30_abshum*1000); @@ -91,7 +91,7 @@ void Sgp30Update(void) // Perform every second to ensure proper operation of th sgp30_ready = true; // these should normally be stored permanently and used for fast restart - if (!(uptime%SAVE_PERIOD)) { + if (!(TasmotaGlobal.uptime%SAVE_PERIOD)) { // store settings every N seconds uint16_t TVOC_base; uint16_t eCO2_base; @@ -115,13 +115,13 @@ void Sgp30Show(bool json) if (sgp30_ready) { char abs_hum[33]; - if (global_update && (global_humidity > 0) && !isnan(global_temperature_celsius)) { + if (TasmotaGlobal.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_celsius)) { + if (TasmotaGlobal.global_update && global_humidity>0 && !isnan(global_temperature_celsius)) { ResponseAppend_P(PSTR(",\"" D_JSON_AHUM "\":%s"),abs_hum); } ResponseJsonEnd(); @@ -131,7 +131,7 @@ void Sgp30Show(bool json) #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_SGP30, sgp.eCO2, sgp.TVOC); - if (global_update) { + if (TasmotaGlobal.global_update) { WSContentSend_PD(HTTP_SNS_AHUM, abs_hum); } #endif diff --git a/tasmota/xsns_31_ccs811.ino b/tasmota/xsns_31_ccs811.ino index 71bac8240..4085db9f9 100644 --- a/tasmota/xsns_31_ccs811.ino +++ b/tasmota/xsns_31_ccs811.ino @@ -65,7 +65,7 @@ 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_celsius)) { + if (TasmotaGlobal.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_35_tx20.ino b/tasmota/xsns_35_tx20.ino index 3ab33e402..474e43cae 100644 --- a/tasmota/xsns_35_tx20.ino +++ b/tasmota/xsns_35_tx20.ino @@ -238,7 +238,7 @@ void ICACHE_RAM_ATTR TX2xStartRead(void) #else if ((chk == tx2x_sd) && (tx2x_sb==tx2x_se) && (tx2x_sc==tx2x_sf) && (tx2x_sc < 511)) { #endif - tx2x_last_available = uptime; + tx2x_last_available = TasmotaGlobal.uptime; // Wind speed spec: 0 to 180 km/h (0 to 50 m/s) tx2x_wind_speed = tx2x_sc; tx2x_wind_direction = tx2x_sb; @@ -264,7 +264,7 @@ void ICACHE_RAM_ATTR TX2xStartRead(void) bool Tx2xAvailable(void) { - return ((uptime - tx2x_last_available) < TX2X_TIMEOUT); + return ((TasmotaGlobal.uptime - tx2x_last_available) < TX2X_TIMEOUT); } #ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS @@ -306,7 +306,7 @@ void Tx2xCheckSampleCount(void) void Tx2xResetStat(void) { DEBUG_SENSOR_LOG(PSTR(D_TX2x_NAME ": reset statistics")); - tx2x_last_uptime = uptime; + tx2x_last_uptime = TasmotaGlobal.uptime; Tx2xResetStatData(); } @@ -330,13 +330,13 @@ void Tx2xRead(void) // // note: TX23 speed calculation is unstable when conversion starts // less than 2 seconds after last request - if ((uptime % TX23_READ_INTERVAL)==0) { + if ((TasmotaGlobal.uptime % TX23_READ_INTERVAL)==0) { // TX23 start transmission by pulling down TxD line for at minimum 500ms // so we pull TxD signal to low every 3 seconds tx23_stage = 0; pinMode(Pin(GPIO_TX2X_TXD_BLACK), OUTPUT); digitalWrite(Pin(GPIO_TX2X_TXD_BLACK), LOW); - } else if ((uptime % TX23_READ_INTERVAL)==1) { + } else if ((TasmotaGlobal.uptime % TX23_READ_INTERVAL)==1) { // after pulling down TxD: pull-up TxD every x+1 seconds // to trigger TX23 start transmission tx23_stage = 1; // first rising signal is invalid @@ -419,7 +419,7 @@ void Tx2xRead(void) char siny[FLOATSZ]; dtostrfd(tx2x_wind_direction_avg_y, 1, siny); DEBUG_SENSOR_LOG(PSTR(D_TX2x_NAME ": dir stat - counter=%ld, actint=%ld, avgint=%ld, avg=%s (cosx=%s, siny=%s), min %d, max %d"), - (uptime-tx2x_last_uptime), + (TasmotaGlobal.uptime-tx2x_last_uptime), tx2x_wind_direction, tx2x_wind_direction_avg_int, diravg, @@ -443,7 +443,7 @@ void Tx2xRead(void) #ifndef USE_TX2X_WIND_SENSOR_NOSTATISTICS Tx2xCheckSampleCount(); - if (0==Settings.tele_period && (uptime-tx2x_last_uptime)>=tx2x_avg_samples) { + if (0==Settings.tele_period && (TasmotaGlobal.uptime-tx2x_last_uptime)>=tx2x_avg_samples) { Tx2xResetStat(); } #endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS diff --git a/tasmota/xsns_43_hre.ino b/tasmota/xsns_43_hre.ino index 19fffe957..2b5a3dff3 100644 --- a/tasmota/xsns_43_hre.ino +++ b/tasmota/xsns_43_hre.ino @@ -137,7 +137,7 @@ void hreEvery50ms(void) switch (hre_state) { case hre_sync: - if (uptime < 10) + if (TasmotaGlobal.uptime < 10) break; sync_run = 0; sync_counter = 0; @@ -174,7 +174,7 @@ void hreEvery50ms(void) AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "sync_run:%d, sync_counter:%d"), sync_run, sync_counter); read_counter = 0; parity_errors = 0; - curr_start = uptime; + curr_start = TasmotaGlobal.uptime; memset(buff, 0, sizeof(buff)); hre_state = hre_reading; AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HRE "hre_state:hre_reading")); @@ -223,7 +223,7 @@ void hreEvery50ms(void) case hre_sleeping: // If there isn't some delay between readings, rate calculations // aren't as accurate. 27 seconds will give about a 30 second refresh rate - if (uptime - hre_usage_time >= 27) + if (TasmotaGlobal.uptime - hre_usage_time >= 27) hre_state = hre_sync; } } diff --git a/tasmota/xsns_44_sps30.ino b/tasmota/xsns_44_sps30.ino index 441a05754..ce7912c88 100644 --- a/tasmota/xsns_44_sps30.ino +++ b/tasmota/xsns_44_sps30.ino @@ -158,7 +158,7 @@ const char HTTP_SNS_SPS30_c[] PROGMEM ="{s}SPS30 " "TYPSIZ" "{m}%s " "um" "{e}"; void SPS30_Every_Second() { if (!sps30_running) return; - if (uptime%10==0) { + if (TasmotaGlobal.uptime%10==0) { uint8_t vars[sizeof(float)*10]; sps30_get_data(SPS_CMD_READ_MEASUREMENT,vars,sizeof(vars)); float *fp=&sps30_result.PM1_0; @@ -178,7 +178,7 @@ void SPS30_Every_Second() { } } - if (uptime%3600==0 && uptime>60) { + if (TasmotaGlobal.uptime%3600==0 && TasmotaGlobal.uptime>60) { // should auto clean once per week runtime // so count hours, should be in Settings SPS30_HOURS++; diff --git a/tasmota/xsns_52_ibeacon.ino b/tasmota/xsns_52_ibeacon.ino index 5c8b0afd4..a733e97da 100755 --- a/tasmota/xsns_52_ibeacon.ino +++ b/tasmota/xsns_52_ibeacon.ino @@ -119,7 +119,7 @@ void hm17_every_second(void) { if (!IBEACON_Serial) return; if (hm17_found) { - if (IB_UPDATE_TIME && (uptime%IB_UPDATE_TIME==0)) { + if (IB_UPDATE_TIME && (TasmotaGlobal.uptime%IB_UPDATE_TIME==0)) { if (hm17_cmd!=99) { if (hm17_flag&2) { ib_sendbeep(); @@ -140,7 +140,7 @@ void hm17_every_second(void) { } } } else { - if (uptime%20==0) { + if (TasmotaGlobal.uptime%20==0) { hm17_sendcmd(HM17_TEST); } } diff --git a/tasmota/xsns_55_hih_series.ino b/tasmota/xsns_55_hih_series.ino index c108cce07..c7d1bf70b 100644 --- a/tasmota/xsns_55_hih_series.ino +++ b/tasmota/xsns_55_hih_series.ino @@ -76,7 +76,7 @@ void Hih6Detect(void) { if (I2cActive(HIH6_ADDR)) { return; } - if (uptime < 2) { delay(20); } // Skip entering power on comand mode + if (TasmotaGlobal.uptime < 2) { delay(20); } // Skip entering power on comand mode Hih6.type = Hih6Read(); if (Hih6.type) { I2cSetActiveFound(HIH6_ADDR, Hih6.types); @@ -85,7 +85,7 @@ void Hih6Detect(void) void Hih6EverySecond(void) { - if (uptime &1) { + if (TasmotaGlobal.uptime &1) { // HIH6130: 30mS if (!Hih6Read()) { AddLogMissed(Hih6.types, Hih6.valid); diff --git a/tasmota/xsns_58_dht12.ino b/tasmota/xsns_58_dht12.ino index 55c78a486..e7ba41af7 100644 --- a/tasmota/xsns_58_dht12.ino +++ b/tasmota/xsns_58_dht12.ino @@ -79,7 +79,7 @@ void Dht12Detect(void) void Dht12EverySecond(void) { - if (uptime &1) { + if (TasmotaGlobal.uptime &1) { // DHT12: 55mS if (!Dht12Read()) { AddLogMissed(Dht12.name, Dht12.valid); diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index 5b3b159ba..9fe90442f 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -259,7 +259,7 @@ void HdcDetect(void) { * */ void HdcEverySecond(void) { - if (uptime &1) { // Every 2 seconds + if (TasmotaGlobal.uptime &1) { // Every 2 seconds if (!HdcTriggerRead()) { AddLogMissed((char*) hdc_type_name, hdc_valid); } diff --git a/tasmota/xsns_73_hp303b.ino b/tasmota/xsns_73_hp303b.ino index 0d9363409..51943678c 100644 --- a/tasmota/xsns_73_hp303b.ino +++ b/tasmota/xsns_73_hp303b.ino @@ -88,7 +88,7 @@ void HP303B_Detect(void) { void HP303B_EverySecond(void) { for (uint32_t i = 0; i < hp303b_cfg.count; i++) { - if (uptime &1) { + if (TasmotaGlobal.uptime &1) { if (!HP303B_Read(i)) { AddLogMissed(hp303b_cfg.types, hp303b_sensor[i].valid); } diff --git a/tasmota/xsns_75_prometheus.ino b/tasmota/xsns_75_prometheus.ino index 1cd95e177..1a5dabcb2 100644 --- a/tasmota/xsns_75_prometheus.ino +++ b/tasmota/xsns_75_prometheus.ino @@ -38,7 +38,7 @@ void HandleMetrics(void) // Pseudo-metric providing metadata about the running firmware version. WSContentSend_P(PSTR("# TYPE tasmota_info gauge\ntasmota_info{version=\"%s\",image=\"%s\",build_timestamp=\"%s\"} 1\n"), my_version, my_image, GetBuildDateAndTime().c_str()); - WSContentSend_P(PSTR("# TYPE tasmota_uptime_seconds gauge\ntasmota_uptime_seconds %d\n"), uptime); + WSContentSend_P(PSTR("# TYPE tasmota_uptime_seconds gauge\ntasmota_uptime_seconds %d\n"), TasmotaGlobal.uptime); WSContentSend_P(PSTR("# TYPE tasmota_boot_count counter\ntasmota_boot_count %d\n"), Settings.bootcount); WSContentSend_P(PSTR("# TYPE tasmota_flash_writes_total counter\ntasmota_flash_writes_total %d\n"), Settings.save_flag); diff --git a/tasmota/xsns_78_ezoco2.ino b/tasmota/xsns_78_ezoco2.ino index f9f09e1c4..a7fe76cc8 100644 --- a/tasmota/xsns_78_ezoco2.ino +++ b/tasmota/xsns_78_ezoco2.ino @@ -32,7 +32,7 @@ struct EZOCO2 : public EZOStruct { EZOStruct::ProcessMeasurement(data, sizeof(data), EZO_CO2_READ_LATENCY); // sensor has a 10s warmup period - if (uptime >= 10) { + if (TasmotaGlobal.uptime >= 10) { CO2 = atoi(data); } } @@ -42,7 +42,7 @@ struct EZOCO2 : public EZOStruct { if (json) { ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_CO2 "\":%d}" ), name, CO2); } -#ifdef USE_WEBSERVER +#ifdef USE_WEBSERVER else { WSContentSend_PD(HTTP_SNS_CO2, name, CO2); #endif // USE_WEBSERVER diff --git a/tasmota/xsns_78_xezo.ino b/tasmota/xsns_78_xezo.ino index db384adbb..bea7c2b9d 100644 --- a/tasmota/xsns_78_xezo.ino +++ b/tasmota/xsns_78_xezo.ino @@ -138,12 +138,12 @@ struct EZOManager { // Do we have to deal with the 2 stage booting process? if (count < 0) { // EZO devices take 2s to boot - if (uptime >= next) { + if (TasmotaGlobal.uptime >= next) { count++; if (count == -1) { DetectRequest(); - next = uptime + 1; + next = TasmotaGlobal.uptime + 1; } else if (count == 0) { ProcessDetection(); } diff --git a/tasmota/xsns_interface.ino b/tasmota/xsns_interface.ino index 0c85854de..c6427c0b7 100644 --- a/tasmota/xsns_interface.ino +++ b/tasmota/xsns_interface.ino @@ -917,7 +917,7 @@ bool XsnsCall(uint8_t Function) uint32_t profile_millis = millis() - profile_start_millis; if (profile_millis) { if (FUNC_EVERY_SECOND == Function) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), TasmotaGlobal.uptime, Function, x, profile_millis); } } #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND @@ -937,7 +937,7 @@ bool XsnsCall(uint8_t Function) uint32_t profile_millis = millis() - profile_start_millis; if (profile_millis) { if (FUNC_EVERY_SECOND == Function) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PRF: At %08u XsnsCall %d took %u mS"), uptime, Function, profile_millis); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PRF: At %08u XsnsCall %d took %u mS"), TasmotaGlobal.uptime, Function, profile_millis); } } #endif // PROFILE_XSNS_EVERY_SECOND