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("