diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 6f1c097f2..306784da2 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.3.0.9 20181118 +/* 6.3.0.10 20181118 + * Add command SetOption36 0..255 milliseconds (10 default) to tune main loop dynamic delay + * + * 6.3.0.9 20181118 * Moved command SetSensorXX to debugging driver freeing user code space * Add dynamic delay to main loop providing time for wifi background tasks * Remove delays introduced in 6.3.0.1 (#4233) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index d683eee79..2a346feb7 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -417,6 +417,7 @@ void SettingsDefaultSet2(void) // Settings.flag.stop_flash_rotate = 0; Settings.save_data = SAVE_DATA; Settings.sleep = APP_SLEEP; + Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY; // Module // Settings.flag.interlock = 0; @@ -853,6 +854,9 @@ void SettingsDelta(void) if (Settings.version < 0x06030004) { memset(&Settings.drivers, 0xFF, 32); // Enable all possible monitors, displays, drivers and sensors } + if (Settings.version < 0x0603000A) { + Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY; + } Settings.version = VERSION; SettingsSave(1); diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 3d6acfaab..98031c402 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -189,8 +189,8 @@ typedef unsigned long power_t; // Power (Relay) type #define KNX_MAX_device_param 30 #define MAX_KNXTX_CMNDS 5 -#define DRIVER_BOOT_DELAY 1 // Number of milliseconds to retard driver cycles during boot-up time to reduce overall CPU load whilst Wifi is connecting -#define LOOP_SLEEP_DELAY 10 // Lowest number of milliseconds to go through the main loop using delay when needed +#define DRIVER_BOOT_DELAY 1 // Number of milliseconds to retard driver cycles during boot-up time to reduce overall CPU load whilst Wifi is connecting +#define LOOP_SLEEP_DELAY 10 // Lowest number of milliseconds to go through the main loop using delay when needed /*********************************************************************************************\ * Enumeration @@ -222,7 +222,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) +enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_LOOP_SLEEP_DELAY, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; @@ -233,7 +233,7 @@ enum LightSubtypes { LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LS enum LightTypes { LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, LT_NU8, LT_SERIAL1, LT_SERIAL2, LT_WS2812, LT_RGBW, LT_RGBWC, LT_NU14, LT_NU15 }; // Do not insert new fields -enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; +enum LightSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX}; enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index ad50c3573..4930fdab4 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2790,5 +2790,5 @@ void loop(void) delay(sleep); // https://github.com/esp8266/Arduino/issues/2021 uint32_t my_activity = millis() - my_sleep; - if (my_activity < LOOP_SLEEP_DELAY) { delay(LOOP_SLEEP_DELAY - my_activity); } // Provide time for background tasks like wifi + if (my_activity < (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]) { delay((uint32_t)Settings.param[P_LOOP_SLEEP_DELAY] - my_activity); } // Provide time for background tasks like wifi } diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 5ccff62e0..78acd0305 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,7 +20,7 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06030009 +#define VERSION 0x0603000A #define D_PROGRAMNAME "Sonoff-Tasmota" #define D_AUTHOR "Theo Arends" diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index a55fdd1fa..a4cf8c137 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -2055,10 +2055,12 @@ boolean Xdrv01(byte function) switch (function) { case FUNC_LOOP: - PollDnsWebserver(); + if (!global_state.wifi_down) { + PollDnsWebserver(); #ifdef USE_EMULATION - if (Settings.flag2.emulation) PollUdp(); + if (Settings.flag2.emulation) PollUdp(); #endif // USE_EMULATION + } break; case FUNC_COMMAND: result = WebCommand(); diff --git a/sonoff/xdrv_02_mqtt.ino b/sonoff/xdrv_02_mqtt.ino index 2da603a99..a67a15d7e 100644 --- a/sonoff/xdrv_02_mqtt.ino +++ b/sonoff/xdrv_02_mqtt.ino @@ -926,7 +926,7 @@ boolean Xdrv02(byte function) break; #endif // USE_WEBSERVER case FUNC_LOOP: - MqttLoop(); + if (!global_state.mqtt_down) { MqttLoop(); } break; case FUNC_COMMAND: result = MqttCommand(); diff --git a/sonoff/xdrv_11_knx.ino b/sonoff/xdrv_11_knx.ino index 69fa558fa..5391cd17c 100644 --- a/sonoff/xdrv_11_knx.ino +++ b/sonoff/xdrv_11_knx.ino @@ -1298,7 +1298,7 @@ boolean Xdrv11(byte function) #endif // USE_KNX_WEB_MENU #endif // USE_WEBSERVER case FUNC_LOOP: - knx.loop(); // Process knx events + if (!global_state.wifi_down) { knx.loop(); } // Process knx events break; case FUNC_EVERY_50_MSECOND: if (toggle_inhibit) {