diff --git a/tasmota/support.ino b/tasmota/support.ino index 4bc3b874f..de13338f9 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -2102,7 +2102,7 @@ void AddLogBuffer(uint32_t loglevel, uint8_t *buffer, uint32_t count) void AddLogSerial(uint32_t loglevel) { - AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, serial_in_byte_counter); + AddLogBuffer(loglevel, (uint8_t*)serial_in_buffer, TasmotaGlobal.serial_in_byte_counter); } void AddLogMissed(const char *sensor, uint32_t misses) diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index ffb458a82..1fd50cbdf 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -281,7 +281,7 @@ void ButtonHandler(void) if (Button.window_timer[button_index]) { Button.window_timer[button_index]--; } else { - if (!restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0) && (Button.press_counter[button_index] < 7)) { + if (!TasmotaGlobal.restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0) && (Button.press_counter[button_index] < 7)) { bool single_press = false; if (Button.press_counter[button_index] < 3) { // Single or Double press @@ -307,7 +307,7 @@ void ButtonHandler(void) } else { if (Button.press_counter[button_index] < 6) { // Single to Penta press if (WifiState() > WIFI_RESTART) { // Wifimanager active - restart_flag = 1; + TasmotaGlobal.restart_flag = 1; } if (!Settings.flag3.mqtt_buttons) { // SetOption73 - Detach buttons from relays and enable MQTT action state for multipress if (Button.press_counter[button_index] == 1) { // By default first press always send a TOGGLE (2) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 453d96dc5..84a43a18e 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -697,7 +697,7 @@ void CmndUpgrade(void) // Check if the version we have been asked to upgrade to is higher than our current version. // We also need at least 3 chars to make a valid version number string. if (((1 == XdrvMailbox.data_len) && (1 == XdrvMailbox.payload)) || ((XdrvMailbox.data_len >= 3) && NewerVersion(XdrvMailbox.data))) { - ota_state_flag = 3; + TasmotaGlobal.ota_state_flag = 3; char stemp1[TOPSZ]; Response_P(PSTR("{\"%s\":\"" D_JSON_VERSION " %s " D_JSON_FROM " %s\"}"), XdrvMailbox.command, my_version, GetOtaUrl(stemp1, sizeof(stemp1))); } else { @@ -726,11 +726,11 @@ void CmndRestart(void) { switch (XdrvMailbox.payload) { case 1: - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; ResponseCmndChar(D_JSON_RESTARTING); break; case 2: - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; restart_halt = true; ResponseCmndChar(D_JSON_HALTING); break; @@ -879,7 +879,7 @@ void CmndSetoption(void) #ifdef USE_LIGHT if (P_RGB_REMAP == pindex) { LightUpdateColorMapping(); - restart_flag = 2; // SetOption37 needs a reboot in most cases + TasmotaGlobal.restart_flag = 2; // SetOption37 needs a reboot in most cases } #endif #if (defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE)) || defined(USE_IR_REMOTE_FULL) @@ -907,7 +907,7 @@ void CmndSetoption(void) break; // Ignore command SetOption case 3: // mqtt case 15: // pwm_control - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; default: bitWrite(Settings.flag.data, pindex, XdrvMailbox.payload); } @@ -926,7 +926,7 @@ void CmndSetoption(void) switch (pindex) { case 5: // SetOption55 if (0 == XdrvMailbox.payload) { - restart_flag = 2; // Disable mDNS needs restart + TasmotaGlobal.restart_flag = 2; // Disable mDNS needs restart } break; case 10: // SetOption60 enable or disable traditional sleep @@ -934,7 +934,7 @@ void CmndSetoption(void) break; case 18: // SetOption68 for multi-channel PWM, requires a reboot case 25: // SetOption75 grouptopic change - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; break; } } @@ -949,7 +949,7 @@ void CmndSetoption(void) case 22: // SetOption104 - No Retain - disable all MQTT retained messages, some brokers don't support it: AWS IoT, Losant case 24: // SetOption106 - Virtual CT - Creates a virtual White ColorTemp for RGBW lights case 25: // SetOption107 - Virtual CT Channel - signals whether the hardware white is cold CW (true) or warm WW (false) - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; break; } } @@ -1085,7 +1085,7 @@ void CmndModule(void) Settings.my_gp.io[i] = GPIO_NONE; } } - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } } @@ -1144,7 +1144,7 @@ void CmndGpio(void) } } Settings.my_gp.io[XdrvMailbox.index] = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } Response_P(PSTR("{")); @@ -1241,7 +1241,7 @@ void CmndTemplate(void) XdrvMailbox.payload--; if (ValidTemplateModule(XdrvMailbox.payload)) { ModuleDefault(XdrvMailbox.payload); // Copy template module - if (USER_MODULE == Settings.module) { restart_flag = 2; } + if (USER_MODULE == Settings.module) { TasmotaGlobal.restart_flag = 2; } } } else if (0 == XdrvMailbox.payload) { // Copy current template to user template @@ -1267,7 +1267,7 @@ void CmndTemplate(void) } else { if (JsonTemplate(XdrvMailbox.data)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function - if (USER_MODULE == Settings.module) { restart_flag = 2; } + if (USER_MODULE == Settings.module) { TasmotaGlobal.restart_flag = 2; } } else { ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON)); error = true; @@ -1464,7 +1464,7 @@ void CmndIpAddress(void) uint32_t address; if (ParseIp(&address, XdrvMailbox.data)) { Settings.ip_address[XdrvMailbox.index -1] = address; -// restart_flag = 2; +// TasmotaGlobal.restart_flag = 2; } char stemp1[TOPSZ]; snprintf_P(stemp1, sizeof(stemp1), PSTR(" (%s)"), WiFi.localIP().toString().c_str()); @@ -1483,7 +1483,7 @@ void CmndNtpServer(void) SettingsUpdateText(ntp_server, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? PSTR(NTP_SERVER1) : (2 == XdrvMailbox.index) ? PSTR(NTP_SERVER2) : PSTR(NTP_SERVER3) : XdrvMailbox.data); SettingsUpdateText(ntp_server, ReplaceCommaWithDot(SettingsText(ntp_server))); - // restart_flag = 2; // Issue #3890 + // TasmotaGlobal.restart_flag = 2; // Issue #3890 ntp_force_sync = true; } ResponseCmndIdxChar(SettingsText(ntp_server)); @@ -1503,7 +1503,7 @@ void CmndAp(void) Settings.sta_active = XdrvMailbox.payload -1; } Settings.wifi_channel = 0; // Disable stored AP - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } Response_P(S_JSON_COMMAND_NVALUE_SVALUE, XdrvMailbox.command, Settings.sta_active +1, EscapeJSONString(SettingsText(SET_STASSID1 + Settings.sta_active)).c_str()); } @@ -1518,7 +1518,7 @@ void CmndSsid(void) SettingsUpdateText(SET_STASSID1 + XdrvMailbox.index -1, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_SSID1 : STA_SSID2 : XdrvMailbox.data); Settings.sta_active = XdrvMailbox.index -1; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndIdxChar(SettingsText(SET_STASSID1 + XdrvMailbox.index -1)); } @@ -1532,7 +1532,7 @@ void CmndPassword(void) SettingsUpdateText(SET_STAPWD1 + XdrvMailbox.index -1, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? (1 == XdrvMailbox.index) ? STA_PASS1 : STA_PASS2 : XdrvMailbox.data); Settings.sta_active = XdrvMailbox.index -1; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; ResponseCmndIdxChar(SettingsText(SET_STAPWD1 + XdrvMailbox.index -1)); } else { Response_P(S_JSON_COMMAND_INDEX_ASTERISK, XdrvMailbox.command, XdrvMailbox.index); @@ -1547,7 +1547,7 @@ void CmndHostname(void) if (strstr(SettingsText(SET_HOSTNAME), "%") != nullptr) { SettingsUpdateText(SET_HOSTNAME, WIFI_HOSTNAME); } - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndChar(SettingsText(SET_HOSTNAME)); } @@ -1561,7 +1561,7 @@ void CmndWifiConfig(void) Settings.sta_config = XdrvMailbox.payload; wifi_state_flag = Settings.sta_config; if (WifiState() > WIFI_RESTART) { - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } char stemp1[TOPSZ]; @@ -1572,7 +1572,7 @@ void CmndWifi(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag4.network_wifi = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndStateText(Settings.flag4.network_wifi); } @@ -1708,11 +1708,11 @@ void CmndReset(void) { switch (XdrvMailbox.payload) { case 1: - restart_flag = 211; + TasmotaGlobal.restart_flag = 211; ResponseCmndChar(PSTR(D_JSON_RESET_AND_RESTARTING)); break; case 2 ... 6: - restart_flag = 210 + XdrvMailbox.payload; + TasmotaGlobal.restart_flag = 210 + XdrvMailbox.payload; Response_P(PSTR("{\"" D_CMND_RESET "\":\"" D_JSON_ERASE ", " D_JSON_RESET_AND_RESTARTING "\"}")); break; case 99: @@ -1977,7 +1977,7 @@ void CmndI2cDriver(void) if (XdrvMailbox.index < MAX_I2C_DRIVERS) { if (XdrvMailbox.payload >= 0) { bitWrite(Settings.i2c_drivers[XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } Response_P(PSTR("{\"" D_CMND_I2CDRIVER "\":")); @@ -1996,7 +1996,7 @@ void CmndDevGroupName(void) else if (1 == XdrvMailbox.data_len && ('"' == XdrvMailbox.data[0] || '0' == XdrvMailbox.data[0])) XdrvMailbox.data[0] = 0; SettingsUpdateText(SET_DEV_GROUP_NAME1 + XdrvMailbox.index - 1, XdrvMailbox.data); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndAll(SET_DEV_GROUP_NAME1, MAX_DEV_GROUP_NAMES); } diff --git a/tasmota/support_device_groups.ino b/tasmota/support_device_groups.ino index be2b5fc90..86442e3b1 100644 --- a/tasmota/support_device_groups.ino +++ b/tasmota/support_device_groups.ino @@ -166,7 +166,7 @@ void DeviceGroupsInit(void) void DeviceGroupsStart() { - if (Settings.flag4.device_groups_enabled && !device_groups_up && !restart_flag) { + if (Settings.flag4.device_groups_enabled && !device_groups_up && !TasmotaGlobal.restart_flag) { // If we haven't successfuly initialized device groups yet, attempt to do it now. if (!device_groups_initialized) { @@ -806,7 +806,7 @@ void DeviceGroupStatus(uint8_t device_group_index) void DeviceGroupsLoop(void) { - if (!device_groups_up || restart_flag) return; + if (!device_groups_up || TasmotaGlobal.restart_flag) return; while (device_groups_udp.parsePacket()) { uint8_t packet_buffer[512]; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d074190a7..7d9f7d242 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -940,8 +940,8 @@ void Every250mSeconds(void) blinks = 201; // Allow only a single blink in case the problem is solved } } - if (blinks || restart_flag || ota_state_flag) { - if (restart_flag || ota_state_flag) { // Overrule blinks and keep led lit + if (blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { + if (TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { // Overrule blinks and keep led lit blinkstate = true; // Stay lit } else { blinkspeed--; @@ -958,7 +958,7 @@ void Every250mSeconds(void) if (200 == blinks) blinks = 0; // Disable blink } } - if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || restart_flag || ota_state_flag)) ) { + if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag)) ) { bool tstate = TasmotaGlobal.power & Settings.ledmask; #ifdef ESP8266 if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) { @@ -977,15 +977,15 @@ void Every250mSeconds(void) switch (state_250mS) { case 0: // Every x.0 second - if (ota_state_flag && BACKLOG_EMPTY) { - ota_state_flag--; - if (2 == ota_state_flag) { + if (TasmotaGlobal.ota_state_flag && BACKLOG_EMPTY) { + TasmotaGlobal.ota_state_flag--; + if (2 == TasmotaGlobal.ota_state_flag) { RtcSettings.ota_loader = 0; // Try requested image first ota_retry_counter = OTA_ATTEMPTS; ESPhttpUpdate.rebootOnUpdate(false); SettingsSave(1); // Free flash for OTA update } - if (ota_state_flag <= 0) { + if (TasmotaGlobal.ota_state_flag <= 0) { #ifdef USE_COUNTER CounterInterruptDisable(true); // Prevent OTA failures on 100Hz counter interrupts #endif // USE_COUNTER @@ -995,7 +995,7 @@ void Every250mSeconds(void) #ifdef USE_ARILUX_RF AriluxRfDisable(); // Prevent restart exception on Arilux Interrupt routine #endif // USE_ARILUX_RF - ota_state_flag = 92; + TasmotaGlobal.ota_state_flag = 92; ota_result = 0; ota_retry_counter--; if (ota_retry_counter) { @@ -1045,12 +1045,12 @@ void Every250mSeconds(void) RtcSettings.ota_loader = 1; // Try minimal image next } #endif // FIRMWARE_MINIMAL - ota_state_flag = 2; // Upgrade failed - retry + TasmotaGlobal.ota_state_flag = 2; // Upgrade failed - retry } } } - if (90 == ota_state_flag) { // Allow MQTT to reconnect - ota_state_flag = 0; + if (90 == TasmotaGlobal.ota_state_flag) { // Allow MQTT to reconnect + TasmotaGlobal.ota_state_flag = 0; Response_P(PSTR("{\"" D_CMND_UPGRADE "\":\"")); if (ota_result) { // SetFlashModeDout(); // Force DOUT for both ESP8266 and ESP8285 @@ -1058,13 +1058,13 @@ void Every250mSeconds(void) ResponseAppend_P(PSTR(D_JSON_FAILED " " D_UPLOAD_ERR_14)); } else { ResponseAppend_P(PSTR(D_JSON_SUCCESSFUL ". " D_JSON_RESTARTING)); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } else { ResponseAppend_P(PSTR(D_JSON_FAILED " %s"), ESPhttpUpdate.getLastErrorString().c_str()); } ResponseAppend_P(PSTR("\"}")); -// restart_flag = 2; // Restart anyway to keep memory clean webserver +// TasmotaGlobal.restart_flag = 2; // Restart anyway to keep memory clean webserver MqttPublishPrefixTopic_P(STAT, PSTR(D_CMND_UPGRADE)); #ifdef USE_COUNTER CounterInterruptDisable(false); @@ -1092,12 +1092,12 @@ void Every250mSeconds(void) } else { Settings.power = 0; } - if (!restart_flag) { SettingsSave(0); } + if (!TasmotaGlobal.restart_flag) { SettingsSave(0); } save_data_counter = Settings.save_data; } } - if (restart_flag && BACKLOG_EMPTY) { - if ((214 == restart_flag) || (215 == restart_flag) || (216 == restart_flag)) { + if (TasmotaGlobal.restart_flag && BACKLOG_EMPTY) { + if ((214 == TasmotaGlobal.restart_flag) || (215 == TasmotaGlobal.restart_flag) || (216 == TasmotaGlobal.restart_flag)) { // Backup current SSIDs and Passwords char storage_ssid1[strlen(SettingsText(SET_STASSID1)) +1]; strncpy(storage_ssid1, SettingsText(SET_STASSID1), sizeof(storage_ssid1)); @@ -1118,10 +1118,10 @@ void Every250mSeconds(void) strncpy(storage_mqtttopic, SettingsText(SET_MQTT_TOPIC), sizeof(storage_mqtttopic)); uint16_t mqtt_port = Settings.mqtt_port; -// if (216 == restart_flag) { +// if (216 == TasmotaGlobal.restart_flag) { // Backup mqtt host, port, client, username and password // } - if ((215 == restart_flag) || (216 == restart_flag)) { + if ((215 == TasmotaGlobal.restart_flag) || (216 == TasmotaGlobal.restart_flag)) { SettingsErase(0); // Erase all flash from program end to end of physical flash } SettingsDefault(); @@ -1130,7 +1130,7 @@ void Every250mSeconds(void) SettingsUpdateText(SET_STASSID2, storage_ssid2); SettingsUpdateText(SET_STAPWD1, storage_pass1); SettingsUpdateText(SET_STAPWD2, storage_pass2); - if (216 == restart_flag) { + if (216 == TasmotaGlobal.restart_flag) { // Restore the mqtt host, port, client, username and password SettingsUpdateText(SET_MQTT_HOST, storage_mqtthost); SettingsUpdateText(SET_MQTT_USER, storage_mqttuser); @@ -1138,25 +1138,25 @@ void Every250mSeconds(void) SettingsUpdateText(SET_MQTT_TOPIC, storage_mqtttopic); Settings.mqtt_port = mqtt_port; } - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } - else if (213 == restart_flag) { + else if (213 == TasmotaGlobal.restart_flag) { SettingsSdkErase(); // Erase flash SDK parameters - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } - else if (212 == restart_flag) { + else if (212 == TasmotaGlobal.restart_flag) { SettingsErase(0); // Erase all flash from program end to end of physical flash - restart_flag = 211; + TasmotaGlobal.restart_flag = 211; } - if (211 == restart_flag) { + if (211 == TasmotaGlobal.restart_flag) { SettingsDefault(); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } - if (2 == restart_flag) { + if (2 == TasmotaGlobal.restart_flag) { SettingsSaveAll(); } - restart_flag--; - if (restart_flag <= 0) { + TasmotaGlobal.restart_flag--; + if (TasmotaGlobal.restart_flag <= 0) { AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "%s"), (restart_halt) ? "Halted" : D_RESTARTING); EspRestart(); } @@ -1173,7 +1173,7 @@ void Every250mSeconds(void) #ifdef FIRMWARE_MINIMAL if (1 == RtcSettings.ota_loader) { RtcSettings.ota_loader = 0; - ota_state_flag = 3; + TasmotaGlobal.ota_state_flag = 3; } #endif // FIRMWARE_MINIMAL @@ -1334,10 +1334,10 @@ void SerialInput(void) delay(0); serial_in_byte = Serial.read(); - if (0 == serial_in_byte_counter) { + if (0 == TasmotaGlobal.serial_in_byte_counter) { serial_buffer_overrun = false; } - else if ((serial_in_byte_counter == INPUT_BUFFER_SIZE) + else if ((TasmotaGlobal.serial_in_byte_counter == INPUT_BUFFER_SIZE) #ifdef ESP8266 || Serial.hasOverrun() #endif @@ -1356,7 +1356,7 @@ void SerialInput(void) /*-------------------------------------------------------------------------------------------*/ if (XdrvCall(FUNC_SERIAL)) { - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; Serial.flush(); return; } @@ -1364,14 +1364,14 @@ void SerialInput(void) /*-------------------------------------------------------------------------------------------*/ if (serial_in_byte > 127 && !Settings.flag.mqtt_serial_raw) { // Discard binary data above 127 if no raw reception allowed - CMND_SERIALSEND3 - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; Serial.flush(); return; } if (!Settings.flag.mqtt_serial) { // SerialSend active - CMND_SERIALSEND and CMND_SERIALLOG if (isprint(serial_in_byte)) { // Any char between 32 and 127 - if (serial_in_byte_counter < INPUT_BUFFER_SIZE -1) { // Add char to string if it still fits - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; + if (TasmotaGlobal.serial_in_byte_counter < INPUT_BUFFER_SIZE -1) { // Add char to string if it still fits + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; } else { serial_buffer_overrun = true; // Signal overrun but continue reading input to flush until '\n' (EOL) } @@ -1383,12 +1383,12 @@ void SerialInput(void) ((Settings.serial_delimiter == 128) && !isprint(serial_in_byte))) && // Any char not between 32 and 127 !Settings.flag.mqtt_serial_raw; // In raw mode (CMND_SERIALSEND3) there is never a delimiter - if ((serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ... + if ((TasmotaGlobal.serial_in_byte_counter < INPUT_BUFFER_SIZE -1) && // Add char to string if it still fits and ... !in_byte_is_delimiter) { // Char is not a delimiter - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; } - if ((serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ... + if ((TasmotaGlobal.serial_in_byte_counter >= INPUT_BUFFER_SIZE -1) || // Send message when buffer is full or ... in_byte_is_delimiter) { // Char is delimiter serial_polling_window = 0; // Reception done - send mqtt break; @@ -1404,9 +1404,9 @@ void SerialInput(void) \*-------------------------------------------------------------------------------------------*/ if (SONOFF_SC == my_module_type) { if (serial_in_byte == '\x1B') { // Sonoff SC status from ATMEGA328P - serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed SonoffScSerialInput(serial_in_buffer); - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; Serial.flush(); return; } @@ -1415,7 +1415,7 @@ void SerialInput(void) /*-------------------------------------------------------------------------------------------*/ if (!Settings.flag.mqtt_serial && (serial_in_byte == '\n')) { // CMND_SERIALSEND and CMND_SERIALLOG - serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed seriallog_level = (Settings.seriallog_level < LOG_LEVEL_INFO) ? (uint8_t)LOG_LEVEL_INFO : Settings.seriallog_level; if (serial_buffer_overrun) { AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "Serial buffer overrun")); @@ -1423,15 +1423,15 @@ void SerialInput(void) AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_COMMAND "%s"), serial_in_buffer); ExecuteCommand(serial_in_buffer, SRC_SERIAL); } - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; serial_polling_window = 0; Serial.flush(); return; } } - if (Settings.flag.mqtt_serial && serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { // CMND_SERIALSEND and CMND_SERIALLOG - serial_in_buffer[serial_in_byte_counter] = 0; // Serial data completed + if (Settings.flag.mqtt_serial && TasmotaGlobal.serial_in_byte_counter && (millis() > (serial_polling_window + SERIAL_POLLING))) { // CMND_SERIALSEND and CMND_SERIALLOG + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter] = 0; // Serial data completed bool assume_json = (!Settings.flag.mqtt_serial_raw && (serial_in_buffer[0] == '{')); Response_P(PSTR("{\"" D_JSON_SERIALRECEIVED "\":")); @@ -1440,8 +1440,8 @@ void SerialInput(void) } else { ResponseAppend_P(PSTR("\"")); if (Settings.flag.mqtt_serial_raw) { - char hex_char[(serial_in_byte_counter * 2) + 2]; - ResponseAppend_P(ToHex_P((unsigned char*)serial_in_buffer, serial_in_byte_counter, hex_char, sizeof(hex_char))); + char hex_char[(TasmotaGlobal.serial_in_byte_counter * 2) + 2]; + ResponseAppend_P(ToHex_P((unsigned char*)serial_in_buffer, TasmotaGlobal.serial_in_byte_counter, hex_char, sizeof(hex_char))); } else { ResponseAppend_P(EscapeJSONString(serial_in_buffer).c_str()); } @@ -1450,7 +1450,7 @@ void SerialInput(void) ResponseJsonEnd(); MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_SERIALRECEIVED)); - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; } } diff --git a/tasmota/support_udp.ino b/tasmota/support_udp.ino index cccb64b4e..0000622e0 100644 --- a/tasmota/support_udp.ino +++ b/tasmota/support_udp.ino @@ -79,7 +79,7 @@ bool UdpDisconnect(void) bool UdpConnect(void) { - if (!udp_connected && !restart_flag) { + if (!udp_connected && !TasmotaGlobal.restart_flag) { // Simple Service Discovery Protocol (SSDP) #ifdef ESP8266 UdpCtx.reset(); diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 9ed57f886..629fd36c1 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -99,7 +99,7 @@ void WifiConfig(uint8_t type) Wifi.counter = Wifi.config_counter +5; blinks = 1999; if (WIFI_RESTART == Wifi.config_type) { - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } else if (WIFI_SERIAL == Wifi.config_type) { AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_WCFG_6_SERIAL " " D_ACTIVE_FOR_3_MINUTES)); @@ -503,7 +503,7 @@ void WifiCheck(uint8_t param) } if (!Wifi.config_counter) { // SettingsSdkErase(); // Disabled v6.1.0b due to possible bad wifi connects - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } else { if (Wifi.scan_state) { WifiBeginAfterScan(); } diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index a6374cfb8..1a2406055 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -78,12 +78,12 @@ WiFiUDP PortUdp; // UDP Syslog and Alexa struct { + uint32_t global_update; // Timestamp of last global temperature and humidity update 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 @@ -94,15 +94,17 @@ struct { power_t blink_powersave; // Blink start power save state power_t blink_mask; // Blink relay active mask + int serial_in_byte_counter; // Index in receive buffer + int ota_state_flag; // OTA state flag + int restart_flag; // Tasmota restart flag + float temperature_celsius; // Provide a global temperature to be used by some sensors float humidity; // Provide a global humidity to be used by some sensors float pressure_hpa; // Provide a global pressure to be used by some sensors + } TasmotaGlobal; -int serial_in_byte_counter = 0; // Index in receive buffer -int ota_state_flag = 0; // OTA state flag -int restart_flag = 0; // Tasmota restart flag int wifi_state_flag = WIFI_RESTART; // Wifi state flag int blinks = 201; // Number of LED blinks uint16_t tele_period = 9999; // Tele period timer diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 594088b8c..df9458abf 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1282,7 +1282,7 @@ void WebRestart(uint32_t type) WSContentStop(); ShowWebSource(SRC_WEBGUI); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } /*********************************************************************************************/ @@ -2662,7 +2662,7 @@ void HandleUploadDone(void) char error[100]; WifiConfigCounter(); - restart_flag = 0; + TasmotaGlobal.restart_flag = 0; MqttRetryCounter(0); #ifdef USE_COUNTER CounterInterruptDisable(false); @@ -2697,14 +2697,14 @@ void HandleUploadDone(void) stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location } else { WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "
"), WebColor(COL_TEXT_SUCCESS)); - restart_flag = 2; // Always restart to re-enable disabled features during update + TasmotaGlobal.restart_flag = 2; // Always restart to re-enable disabled features during update #ifdef USE_TASMOTA_CLIENT if (TasmotaClient_GetFlagFlashing()) { WSContentSend_P(PSTR("
" D_TRANSFER_STARTED " ...
")); - restart_flag = 0; // Hold restart as code still needs to be transferred to Atmega + TasmotaGlobal.restart_flag = 0; // Hold restart as code still needs to be transferred to Atmega } #endif // USE_TASMOTA_CLIENT - if (restart_flag) { + if (TasmotaGlobal.restart_flag) { WSContentSend_P(HTTP_MSG_RSTRT); ShowWebSource(SRC_WEBGUI); } @@ -2736,7 +2736,7 @@ void HandleUploadLoop(void) // ***** Step1: Start upload file if (UPLOAD_FILE_START == upload.status) { - restart_flag = 60; + TasmotaGlobal.restart_flag = 60; if (0 == upload.filename.c_str()[0]) { Web.upload_error = 1; // No file selected return; @@ -2986,7 +2986,7 @@ void HandleUploadLoop(void) // ***** Step4: Abort upload file else if (UPLOAD_FILE_ABORTED == upload.status) { - restart_flag = 0; + TasmotaGlobal.restart_flag = 0; MqttRetryCounter(0); #ifdef USE_COUNTER CounterInterruptDisable(false); @@ -3355,7 +3355,7 @@ void CmndEmulation(void) #endif #endif Settings.flag2.emulation = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } #endif ResponseCmndNumber(Settings.flag2.emulation); diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index e98791c1e..cbcf85672 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -810,7 +810,7 @@ void CmndMqttFingerprint(void) Settings.mqtt_fingerprint[XdrvMailbox.index -1][i] = strtol(p, &p, 16); } } - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndIdxChar(ToHex_P((unsigned char *)Settings.mqtt_fingerprint[XdrvMailbox.index -1], 20, fingerprint, sizeof(fingerprint), ' ')); } @@ -821,7 +821,7 @@ void CmndMqttUser(void) { if (XdrvMailbox.data_len > 0) { SettingsUpdateText(SET_MQTT_USER, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_USER : XdrvMailbox.data); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndChar(SettingsText(SET_MQTT_USER)); } @@ -831,7 +831,7 @@ void CmndMqttPassword(void) if (XdrvMailbox.data_len > 0) { SettingsUpdateText(SET_MQTT_PWD, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_PASS : XdrvMailbox.data); ResponseCmndChar(SettingsText(SET_MQTT_PWD)); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } else { Response_P(S_JSON_COMMAND_ASTERISK, XdrvMailbox.command); } @@ -849,7 +849,7 @@ void CmndMqttHost(void) { if (XdrvMailbox.data_len > 0) { SettingsUpdateText(SET_MQTT_HOST, (SC_CLEAR == Shortcut()) ? "" : (SC_DEFAULT == Shortcut()) ? MQTT_HOST : XdrvMailbox.data); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndChar(SettingsText(SET_MQTT_HOST)); } @@ -858,7 +858,7 @@ void CmndMqttPort(void) { if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 65536)) { Settings.mqtt_port = (1 == XdrvMailbox.payload) ? MQTT_PORT : XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndNumber(Settings.mqtt_port); } @@ -893,7 +893,7 @@ void CmndMqttClient(void) { if (!XdrvMailbox.grpflg && (XdrvMailbox.data_len > 0)) { SettingsUpdateText(SET_MQTT_CLIENT, (SC_DEFAULT == Shortcut()) ? MQTT_CLIENT_ID : XdrvMailbox.data); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndChar(SettingsText(SET_MQTT_CLIENT)); } @@ -909,7 +909,7 @@ void CmndFullTopic(void) Response_P((Settings.flag.mqtt_offline) ? S_LWT_OFFLINE : ""); // SetOption10 - Control MQTT LWT message format MqttPublishPrefixTopic_P(TELE, S_LWT, true); // Offline or remove previous retained topic SettingsUpdateText(SET_MQTT_FULLTOPIC, stemp1); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } ResponseCmndChar(SettingsText(SET_MQTT_FULLTOPIC)); @@ -925,7 +925,7 @@ void CmndPrefix(void) MakeValidMqtt(0, XdrvMailbox.data); SettingsUpdateText(SET_MQTTPREFIX1 + XdrvMailbox.index -1, (SC_DEFAULT == Shortcut()) ? (1==XdrvMailbox.index) ? SUB_PREFIX : (2==XdrvMailbox.index) ? PUB_PREFIX : PUB_PREFIX2 : XdrvMailbox.data); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndIdxChar(SettingsText(SET_MQTTPREFIX1 + XdrvMailbox.index -1)); } @@ -996,7 +996,7 @@ void CmndGroupTopic(void) } } - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndAll(SET_MQTT_GRP_TOPIC, MAX_GROUP_TOPICS); } @@ -1013,7 +1013,7 @@ void CmndTopic(void) Response_P((Settings.flag.mqtt_offline) ? S_LWT_OFFLINE : ""); // SetOption10 - Control MQTT LWT message format MqttPublishPrefixTopic_P(TELE, S_LWT, true); // Offline or remove previous retained topic SettingsUpdateText(SET_MQTT_TOPIC, stemp1); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } ResponseCmndChar(SettingsText(SET_MQTT_TOPIC)); diff --git a/tasmota/xdrv_06_snfbridge.ino b/tasmota/xdrv_06_snfbridge.ino index 228564a45..17f0524d5 100644 --- a/tasmota/xdrv_06_snfbridge.ino +++ b/tasmota/xdrv_06_snfbridge.ino @@ -216,11 +216,11 @@ void SonoffBridgeReceivedRaw(void) if (0xB1 == serial_in_buffer[1]) { buckets = serial_in_buffer[2] << 1; } // Bucket sniffing ResponseTime_P(PSTR(",\"" D_CMND_RFRAW "\":{\"" D_JSON_DATA "\":\"")); - for (uint32_t i = 0; i < serial_in_byte_counter; i++) { + for (uint32_t i = 0; i < TasmotaGlobal.serial_in_byte_counter; i++) { ResponseAppend_P(PSTR("%02X"), serial_in_buffer[i]); if (0xB1 == serial_in_buffer[1]) { if ((i > 3) && buckets) { buckets--; } - if ((i < 3) || (buckets % 2) || (i == serial_in_byte_counter -2)) { + if ((i < 3) || (buckets % 2) || (i == TasmotaGlobal.serial_in_byte_counter -2)) { ResponseAppend_P(PSTR(" ")); } } @@ -312,35 +312,35 @@ bool SonoffBridgeSerialInput(void) if (SnfBridge.receive_flag) { if (SnfBridge.receive_raw_flag) { - if (!serial_in_byte_counter) { - serial_in_buffer[serial_in_byte_counter++] = 0xAA; + if (!TasmotaGlobal.serial_in_byte_counter) { + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA; } - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; - if (serial_in_byte_counter == 3) { + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; + if (TasmotaGlobal.serial_in_byte_counter == 3) { if ((0xA6 == serial_in_buffer[1]) || (0xAB == serial_in_buffer[1])) { // AA A6 06 023908010155 55 - 06 is receive_len receive_len = serial_in_buffer[2] + 4; // Get at least receive_len bytes } } - if ((!receive_len && (0x55 == serial_in_byte)) || (receive_len && (serial_in_byte_counter == receive_len))) { // 0x55 - End of text + if ((!receive_len && (0x55 == serial_in_byte)) || (receive_len && (TasmotaGlobal.serial_in_byte_counter == receive_len))) { // 0x55 - End of text SonoffBridgeReceivedRaw(); SnfBridge.receive_flag = 0; return 1; } } - else if (!((0 == serial_in_byte_counter) && (0 == serial_in_byte))) { // Skip leading 0 - if (0 == serial_in_byte_counter) { + else if (!((0 == TasmotaGlobal.serial_in_byte_counter) && (0 == serial_in_byte))) { // Skip leading 0 + if (0 == TasmotaGlobal.serial_in_byte_counter) { SnfBridge.expected_bytes = 2; // 0xA0, 0xA1, 0xA2 if (serial_in_byte >= 0xA3) { SnfBridge.expected_bytes = 11; // 0xA3, 0xA4, 0xA5 } if (serial_in_byte == 0xA6) { SnfBridge.expected_bytes = 0; // 0xA6 and up supported by Portisch firmware only - serial_in_buffer[serial_in_byte_counter++] = 0xAA; + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0xAA; SnfBridge.receive_raw_flag = 1; } } - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; - if ((SnfBridge.expected_bytes == serial_in_byte_counter) && (0x55 == serial_in_byte)) { // 0x55 - End of text + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; + if ((SnfBridge.expected_bytes == TasmotaGlobal.serial_in_byte_counter) && (0x55 == serial_in_byte)) { // 0x55 - End of text SonoffBridgeReceived(); SnfBridge.receive_flag = 0; return 1; @@ -349,7 +349,7 @@ bool SonoffBridgeSerialInput(void) serial_in_byte = 0; } if (0xAA == serial_in_byte) { // 0xAA - Start of text - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; serial_in_byte = 0; SnfBridge.receive_flag = 1; receive_len = 0; diff --git a/tasmota/xdrv_07_domoticz.ino b/tasmota/xdrv_07_domoticz.ino index 4018c7cee..4ce7dbe3c 100644 --- a/tasmota/xdrv_07_domoticz.ino +++ b/tasmota/xdrv_07_domoticz.ino @@ -448,7 +448,7 @@ void CmndDomoticzIdx(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_DOMOTICZ_IDX)) { if (XdrvMailbox.payload >= 0) { Settings.domoticz_relay_idx[XdrvMailbox.index -1] = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndIdxNumber(Settings.domoticz_relay_idx[XdrvMailbox.index -1]); } diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino index 0e6212f95..de5144ffe 100644 --- a/tasmota/xdrv_13_display.ino +++ b/tasmota/xdrv_13_display.ino @@ -1339,7 +1339,7 @@ void CmndDisplayModel(void) uint32_t last_display_model = Settings.display_model; Settings.display_model = XdrvMailbox.payload; if (XdspCall(FUNC_DISPLAY_MODEL)) { - restart_flag = 2; // Restart to re-init interface and add/Remove MQTT subscribe + TasmotaGlobal.restart_flag = 2; // Restart to re-init interface and add/Remove MQTT subscribe } else { Settings.display_model = last_display_model; } @@ -1352,7 +1352,7 @@ void CmndDisplayWidth(void) if (XdrvMailbox.payload > 0) { if (XdrvMailbox.payload != Settings.display_width) { Settings.display_width = XdrvMailbox.payload; - restart_flag = 2; // Restart to re-init width + TasmotaGlobal.restart_flag = 2; // Restart to re-init width } } ResponseCmndNumber(Settings.display_width); @@ -1363,7 +1363,7 @@ void CmndDisplayHeight(void) if (XdrvMailbox.payload > 0) { if (XdrvMailbox.payload != Settings.display_height) { Settings.display_height = XdrvMailbox.payload; - restart_flag = 2; // Restart to re-init height + TasmotaGlobal.restart_flag = 2; // Restart to re-init height } } ResponseCmndNumber(Settings.display_height); @@ -1384,7 +1384,7 @@ void CmndDisplayMode(void) Settings.display_mode = XdrvMailbox.payload; if (disp_subscribed != (Settings.display_mode &0x04)) { - restart_flag = 2; // Restart to Add/Remove MQTT subscribe + TasmotaGlobal.restart_flag = 2; // Restart to Add/Remove MQTT subscribe } else { if (last_display_mode && !Settings.display_mode) { // Switch to mode 0 DisplayInit(DISPLAY_INIT_MODE); diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index 9b25e4cf3..e9304dd6a 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -195,7 +195,7 @@ void CmndTuyaMcu(void) { if (TuyaFuncIdValid(parm[0])) { // TuyaAddMcuFunc(parm[0], parm[1]); - // restart_flag = 2; + // TasmotaGlobal.restart_flag = 2; // } else { // AddLog_P2(LOG_LEVEL_ERROR, PSTR("TYA: TuyaMcu Invalid function id=%d"), parm[0]); // } @@ -212,7 +212,7 @@ void CmndTuyaMcu(void) { Settings.flag3.pwm_multi_channels = 1; } else { Settings.flag3.pwm_multi_channels = 0; } TuyaAddMcuFunc(parm[0], parm[1]); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } else { AddLog_P2(LOG_LEVEL_ERROR, PSTR("TYA: TuyaMcu Invalid function id=%d"), parm[0]); } @@ -770,11 +770,11 @@ void TuyaNormalPowerModePacketProcess(void) } if (!Settings.my_gp.io[led1_gpio] && !led1_set) { Settings.my_gp.io[led1_gpio] = AGPIO(GPIO_LED1); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } if (!Settings.my_gp.io[key1_gpio] && !key1_set) { Settings.my_gp.io[key1_gpio] = AGPIO(GPIO_KEY1); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } } TuyaRequestState(0); @@ -796,7 +796,7 @@ bool TuyaModuleSelected(void) SetPin(3, AGPIO(GPIO_TUYA_RX)); Settings.my_gp.io[1] = AGPIO(GPIO_TUYA_TX); Settings.my_gp.io[3] = AGPIO(GPIO_TUYA_RX); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } if (TuyaGetDpId(TUYA_MCU_FUNC_DIMMER) == 0 && TUYA_DIMMER_ID > 0) { diff --git a/tasmota/xdrv_22_sonoff_ifan.ino b/tasmota/xdrv_22_sonoff_ifan.ino index 74f95c139..cbfddd616 100644 --- a/tasmota/xdrv_22_sonoff_ifan.ino +++ b/tasmota/xdrv_22_sonoff_ifan.ino @@ -159,12 +159,12 @@ bool SonoffIfanSerialInput(void) if (SONOFF_IFAN03 != my_module_type) { return false; } if (0xAA == serial_in_byte) { // 0xAA - Start of text - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; ifan_receive_flag = true; } if (ifan_receive_flag) { - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; - if (serial_in_byte_counter == 8) { + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; + if (TasmotaGlobal.serial_in_byte_counter == 8) { // AA 55 01 01 00 01 01 04 - Wifi long press - start wifi setup // AA 55 01 01 00 01 02 05 - Rf and Wifi short press // AA 55 01 04 00 01 00 06 - Fan 0 diff --git a/tasmota/xdrv_23_zigbee_9_serial.ino b/tasmota/xdrv_23_zigbee_9_serial.ino index 4a9141d7f..47fd92a0f 100644 --- a/tasmota/xdrv_23_zigbee_9_serial.ino +++ b/tasmota/xdrv_23_zigbee_9_serial.ino @@ -545,7 +545,7 @@ void ZigbeeEZSPSendDATA(const uint8_t *msg, size_t len) { } EZSP_Serial.to_packets[to_frm] = buf; EZSP_Serial.to_end = (to_frm + 1) & 0x07; // move cursor - + // ZigbeeEZSPSendDATA_frm(send_cancel, to_frm, EZSP_Serial.from_ack); // increment to_frame @@ -672,14 +672,14 @@ int32_t ZigbeeProcessInputRaw(class SBuffer &buf) { // ERROR EZ_ERROR(buf.get8(2)); zigbee.active = false; // stop all zigbee activities - restart_flag = 2; // there is nothing more we can do except restart + TasmotaGlobal.restart_flag = 2; // there is nothing more we can do except restart } else { // Unknown AddLog_P2(LOG_LEVEL_DEBUG, PSTR("ZIG: Received unknown control byte 0x%02X"), control_byte); } } else { // DATA Frame - + // adjust to latest acked packet uint8_t new_ack = control_byte & 0x07; EZSP_HandleAck(new_ack); diff --git a/tasmota/xdrv_23_zigbee_9a_upload.ino b/tasmota/xdrv_23_zigbee_9a_upload.ino index e3c233152..ec7697566 100644 --- a/tasmota/xdrv_23_zigbee_9a_upload.ino +++ b/tasmota/xdrv_23_zigbee_9a_upload.ino @@ -445,7 +445,7 @@ bool ZigbeeUploadXmodem(void) { if (1 == ssleep) { ssleep = Settings.sleep; // Restore loop sleep } -// restart_flag = 2; // Restart to disable bootloader and use new firmware +// TasmotaGlobal.restart_flag = 2; // Restart to disable bootloader and use new firmware ZbUpload.ota_step = ZBU_FINISH; // Never return to zero without a restart to get a sane Zigbee environment break; } diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index f96679c75..2509c4eb8 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -126,7 +126,7 @@ void CmndZbReset(void) { eraseZigbeeDevices(); case 2: // fall through Settings.zb_txradio_dbm = - abs(Settings.zb_txradio_dbm); - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; #ifdef USE_ZIGBEE_ZNP ResponseCmndChar_P(PSTR(D_JSON_ZIGBEE_CC2530 " " D_JSON_RESET_AND_RESTARTING)); #endif // USE_ZIGBEE_ZNP @@ -1475,7 +1475,7 @@ void CmndZbData(void) { } else { snprintf_P(key, sizeof(key), "?%02X", data_elt.getEndpoint()); } - + Z_Data_Type data_type = data_elt.getType(); key[0] = Z_Data::DataTypeToChar(data_type); switch (data_type) { @@ -1559,7 +1559,7 @@ void CmndZbConfig(void) { Settings.zb_precfgkey_l = zb_precfgkey_l; Settings.zb_precfgkey_h = zb_precfgkey_h; Settings.zb_txradio_dbm = zb_txradio_dbm; - restart_flag = 2; // save and reboot + TasmotaGlobal.restart_flag = 2; // save and reboot } } diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index be97cd02d..ea75f4436 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -747,7 +747,7 @@ void ShutterButtonHandler(void) if (Button.window_timer[button_index]) { Button.window_timer[button_index]--; } else { - if (!restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0)) { + if (!TasmotaGlobal.restart_flag && !Button.hold_timer[button_index] && (Button.press_counter[button_index] > 0)) { if (Button.press_counter[button_index]<99) { // check for simultaneous shutter button press uint32 min_shutterbutton_press_counter = -1; // -1 == max(uint32) diff --git a/tasmota/xdrv_31_tasmota_client.ino b/tasmota/xdrv_31_tasmota_client.ino index 89402b408..be946b1fa 100644 --- a/tasmota/xdrv_31_tasmota_client.ino +++ b/tasmota/xdrv_31_tasmota_client.ino @@ -347,7 +347,7 @@ void TasmotaClient_Flash(void) { if (!TasmotaClient_SetupFlash()) { AddLog_P2(LOG_LEVEL_INFO, PSTR("TCL: Flashing aborted!")); TClient.flashing = false; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; return; } @@ -385,7 +385,7 @@ void TasmotaClient_Flash(void) { TasmotaClient_exitProgMode(); AddLog_P2(LOG_LEVEL_INFO, PSTR("TCL: Flash done!")); TClient.flashing = false; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } void TasmotaClient_SetFlagFlashing(bool value) { diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index 66f0efeaf..c7348e62e 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -690,7 +690,7 @@ void CmndPWMDimmerPWMs(void) { if (XdrvMailbox.data_len > 0 && XdrvMailbox.payload <= 5) { Settings.pwm_dimmer_cfg.pwm_count = XdrvMailbox.payload - 1; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } Response_P(PSTR("{\"" D_CMND_PWM_DIMMER_PWMS "\":%u}"), Settings.pwm_dimmer_cfg.pwm_count + 1); } diff --git a/tasmota/xdrv_37_sonoff_d1.ino b/tasmota/xdrv_37_sonoff_d1.ino index cd1bdd4b2..77d69048d 100644 --- a/tasmota/xdrv_37_sonoff_d1.ino +++ b/tasmota/xdrv_37_sonoff_d1.ino @@ -44,7 +44,7 @@ struct SONOFFD1 { void SonoffD1Received(void) { - if (serial_in_byte_counter < 8) { return; } // Received ack from Rf chip (aa 55 01 04 00 00 05) + if (TasmotaGlobal.serial_in_byte_counter < 8) { return; } // Received ack from Rf chip (aa 55 01 04 00 00 05) uint8_t action = serial_in_buffer[6] & 1; if (action != SnfD1.power) { @@ -81,15 +81,15 @@ void SonoffD1Received(void) bool SonoffD1SerialInput(void) { if (0xAA == serial_in_byte) { // 0xAA - Start of text - serial_in_byte_counter = 0; + TasmotaGlobal.serial_in_byte_counter = 0; SnfD1.receive_len = 7; } if (SnfD1.receive_len) { - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; - if (6 == serial_in_byte_counter) { + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; + if (6 == TasmotaGlobal.serial_in_byte_counter) { SnfD1.receive_len += serial_in_byte; // 8 or 17 } - if (serial_in_byte_counter == SnfD1.receive_len) { + if (TasmotaGlobal.serial_in_byte_counter == SnfD1.receive_len) { // Sonoff D1 codes // aa 55 01 04 00 0a 01 01 ff ff ff ff ff ff ff ff 09 - Power On, Dimmer 1% diff --git a/tasmota/xdrv_82_ethernet.ino b/tasmota/xdrv_82_ethernet.ino index fde8a417a..0a421ac9f 100644 --- a/tasmota/xdrv_82_ethernet.ino +++ b/tasmota/xdrv_82_ethernet.ino @@ -164,7 +164,7 @@ void CmndEthernet(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { Settings.flag4.network_ethernet = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndStateText(Settings.flag4.network_ethernet); } @@ -173,7 +173,7 @@ void CmndEthAddress(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 31)) { Settings.eth_address = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndNumber(Settings.eth_address); } @@ -182,7 +182,7 @@ void CmndEthType(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 2)) { Settings.eth_type = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndNumber(Settings.eth_type); } @@ -191,7 +191,7 @@ void CmndEthClockMode(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) { Settings.eth_clk_mode = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } ResponseCmndNumber(Settings.eth_clk_mode); } diff --git a/tasmota/xdrv_99_debug.ino b/tasmota/xdrv_99_debug.ino index 7471d3095..25bd2bf4c 100644 --- a/tasmota/xdrv_99_debug.ino +++ b/tasmota/xdrv_99_debug.ino @@ -487,7 +487,7 @@ void CmndSetSensor(void) if (XdrvMailbox.payload >= 0) { bitWrite(Settings.sensors[XdrvMailbox.index / 32], XdrvMailbox.index % 32, XdrvMailbox.payload &1); if (1 == XdrvMailbox.payload) { - restart_flag = 2; // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle + TasmotaGlobal.restart_flag = 2; // To safely re-enable a sensor currently most sensor need to follow complete restart init cycle } } Response_P(PSTR("{\"" D_CMND_SETSENSOR "\":")); diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 295330142..ee46f1a37 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -67,14 +67,14 @@ void SnfL1SerialSendOk(void) bool SnfL1SerialInput(void) { if (serial_in_byte != 0x1B) { - if (serial_in_byte_counter >= 140) { - serial_in_byte_counter = 0; + if (TasmotaGlobal.serial_in_byte_counter >= 140) { + TasmotaGlobal.serial_in_byte_counter = 0; } - if (serial_in_byte_counter || (!serial_in_byte_counter && ('A' == serial_in_byte))) { // A from AT - serial_in_buffer[serial_in_byte_counter++] = serial_in_byte; + if (TasmotaGlobal.serial_in_byte_counter || (!TasmotaGlobal.serial_in_byte_counter && ('A' == serial_in_byte))) { // A from AT + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = serial_in_byte; } } else { - serial_in_buffer[serial_in_byte_counter++] = 0x00; + serial_in_buffer[TasmotaGlobal.serial_in_byte_counter++] = 0x00; // AT+RESULT="sequence":"1554682835320" // AT+UPDATE="sequence":"34906","switch":"on","light_type":1,"colorR":0,"colorG":16,"colorB":0,"bright":6,"mode":1 diff --git a/tasmota/xsns_13_ina219.ino b/tasmota/xsns_13_ina219.ino index 854cca5cd..be651acbb 100644 --- a/tasmota/xsns_13_ina219.ino +++ b/tasmota/xsns_13_ina219.ino @@ -233,7 +233,7 @@ bool Ina219CommandSensor(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 255)) { Settings.ina219_mode = XdrvMailbox.payload; - restart_flag = 2; + TasmotaGlobal.restart_flag = 2; } Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_13, Settings.ina219_mode); diff --git a/tasmota/xsns_54_ina226.ino b/tasmota/xsns_54_ina226.ino index 81c4bafc3..77904f374 100644 --- a/tasmota/xsns_54_ina226.ino +++ b/tasmota/xsns_54_ina226.ino @@ -417,8 +417,8 @@ bool Ina226CommandSensor() break; case 2: // Save and restart - restart_flag = 2; - Response_P(PSTR("{\"Sensor54-Command-Result\":{\"Restart_flag\":%d}}"),restart_flag); + TasmotaGlobal.restart_flag = 2; + Response_P(PSTR("{\"Sensor54-Command-Result\":{\"Restart_flag\":%d}}"),TasmotaGlobal.restart_flag); break; default: