mirror of https://github.com/arendst/Tasmota.git
commit
980e8c3401
|
@ -73,7 +73,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
||||||
uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10)
|
uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10)
|
||||||
uint32_t receive_raw : 1; // bit 8 (v6.3.0.11)
|
uint32_t receive_raw : 1; // bit 8 (v6.3.0.11)
|
||||||
uint32_t hass_tele_as_result : 1; // bit 9 (v6.3.0.13)
|
uint32_t hass_tele_as_result : 1; // bit 9 (v6.3.0.13)
|
||||||
uint32_t spare10 : 1;
|
uint32_t sleep_normal : 1; // SetOption60 - Enable normal sleep instead of dynamic sleep
|
||||||
uint32_t spare11 : 1;
|
uint32_t spare11 : 1;
|
||||||
uint32_t spare12 : 1;
|
uint32_t spare12 : 1;
|
||||||
uint32_t spare13 : 1;
|
uint32_t spare13 : 1;
|
||||||
|
|
|
@ -417,7 +417,6 @@ void SettingsDefaultSet2(void)
|
||||||
// Settings.flag.stop_flash_rotate = 0;
|
// Settings.flag.stop_flash_rotate = 0;
|
||||||
Settings.save_data = SAVE_DATA;
|
Settings.save_data = SAVE_DATA;
|
||||||
Settings.sleep = APP_SLEEP;
|
Settings.sleep = APP_SLEEP;
|
||||||
Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY;
|
|
||||||
|
|
||||||
// Module
|
// Module
|
||||||
// Settings.flag.interlock = 0;
|
// Settings.flag.interlock = 0;
|
||||||
|
@ -855,9 +854,10 @@ void SettingsDelta(void)
|
||||||
if (Settings.version < 0x06030004) {
|
if (Settings.version < 0x06030004) {
|
||||||
memset(&Settings.drivers, 0xFF, 32); // Enable all possible monitors, displays, drivers and sensors
|
memset(&Settings.drivers, 0xFF, 32); // Enable all possible monitors, displays, drivers and sensors
|
||||||
}
|
}
|
||||||
if (Settings.version < 0x0603000A) {
|
if (Settings.version < 0x0603000F) {
|
||||||
Settings.param[P_LOOP_SLEEP_DELAY] = LOOP_SLEEP_DELAY;
|
if (Settings.sleep < 50) {
|
||||||
Settings.sleep = 0; // We do not want sleep enabled when SetOption36 is active
|
Settings.sleep = 50; // Default to 50 for sleep, for now
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Settings.version < 0x0603000E) {
|
if (Settings.version < 0x0603000E) {
|
||||||
Settings.flag2.calc_resolution = CALC_RESOLUTION;
|
Settings.flag2.calc_resolution = CALC_RESOLUTION;
|
||||||
|
|
|
@ -222,7 +222,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED };
|
||||||
|
|
||||||
enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER };
|
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_LOOP_SLEEP_DELAY, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
|
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) - 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};
|
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};
|
||||||
|
|
||||||
|
|
|
@ -587,11 +587,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
||||||
}
|
}
|
||||||
else if (CMND_SLEEP == command_code) {
|
else if (CMND_SLEEP == command_code) {
|
||||||
if ((payload >= 0) && (payload < 251)) {
|
if ((payload >= 0) && (payload < 251)) {
|
||||||
if (payload > 0) {
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("*** WARNING *** - Disabling SetOption36 (Dynamic Sleep) in favour of sleep"));
|
|
||||||
AddLog(LOG_LEVEL_INFO);
|
|
||||||
Settings.param[P_LOOP_SLEEP_DELAY] = 0; // We do not want SetOption36 to be active along with traditional sleep
|
|
||||||
}
|
|
||||||
Settings.sleep = payload;
|
Settings.sleep = payload;
|
||||||
sleep = payload;
|
sleep = payload;
|
||||||
WiFiSetSleepMode();
|
WiFiSetSleepMode();
|
||||||
|
@ -750,6 +745,13 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
||||||
else if (1 == ptype) { // SetOption50 .. 81
|
else if (1 == ptype) { // SetOption50 .. 81
|
||||||
if (payload <= 1) {
|
if (payload <= 1) {
|
||||||
bitWrite(Settings.flag3.data, pindex, payload);
|
bitWrite(Settings.flag3.data, pindex, payload);
|
||||||
|
if (60 == ptype) { // SetOption60 enable or disable traditional sleep
|
||||||
|
if (payload == 0) { // Dynamic Sleep
|
||||||
|
WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
|
||||||
|
} else { // Traditional Sleep //AT
|
||||||
|
WiFiSetSleepMode(); // Update WiFi sleep mode accordingly
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { // SetOption32 .. 49
|
else { // SetOption32 .. 49
|
||||||
|
@ -761,14 +763,6 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
|
||||||
param_low = 1;
|
param_low = 1;
|
||||||
param_high = 250;
|
param_high = 250;
|
||||||
break;
|
break;
|
||||||
case P_LOOP_SLEEP_DELAY:
|
|
||||||
if (payload > 0) {
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR("*** WARNING *** - Disabling sleep in favour of SetOption36 (Dynamic Sleep)"));
|
|
||||||
AddLog(LOG_LEVEL_INFO);
|
|
||||||
Settings.sleep = 0; // We do not want traditional sleep to be enabled along side SetOption36
|
|
||||||
sleep = 0;
|
|
||||||
WiFiSetSleepMode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ((payload >= param_low) && (payload <= param_high)) {
|
if ((payload >= param_low) && (payload <= param_high)) {
|
||||||
Settings.param[pindex] = payload;
|
Settings.param[pindex] = payload;
|
||||||
|
@ -1590,12 +1584,15 @@ void MqttShowState(void)
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_JSON_VCC "\":%s"), mqtt_data, stemp1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Settings.param[P_LOOP_SLEEP_DELAY]) {
|
char _sleepmode[8];
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"LoopSet\":%u"), mqtt_data, (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]); // Add current loop delay target to telemetry
|
if (Settings.flag3.sleep_normal) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"LoadAvg\":%u"), mqtt_data, loop_load_avg); // Add LoadAvg to telemetry data
|
sprintf(_sleepmode,"Normal");
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"Sleep\":%u"), mqtt_data, (uint32_t)sleep); // Add current sleep setting so we know Dynamic Sleep is not enabled
|
sprintf(_sleepmode,"Dynamic");
|
||||||
}
|
}
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"SleepMode\":\"%s\""), mqtt_data, _sleepmode); // Add current sleep mode setting to telemetry
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"Sleep\":%u"), mqtt_data, sleep); // Add current sleep setting to telemetry
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"LoadAvg\":%u"), mqtt_data, loop_load_avg); // Add LoadAvg to telemetry
|
||||||
|
|
||||||
for (byte i = 0; i < devices_present; i++) {
|
for (byte i = 0; i < devices_present; i++) {
|
||||||
if (i == light_device -1) {
|
if (i == light_device -1) {
|
||||||
|
@ -2758,6 +2755,8 @@ void setup(void)
|
||||||
XsnsCall(FUNC_INIT);
|
XsnsCall(FUNC_INIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t _counter = 0;
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
uint32_t my_sleep = millis();
|
uint32_t my_sleep = millis();
|
||||||
|
@ -2800,20 +2799,23 @@ void loop(void)
|
||||||
while (arduino_ota_triggered) ArduinoOTA.handle();
|
while (arduino_ota_triggered) ArduinoOTA.handle();
|
||||||
#endif // USE_ARDUINO_OTA
|
#endif // USE_ARDUINO_OTA
|
||||||
|
|
||||||
|
uint32_t my_activity = millis() - my_sleep;
|
||||||
|
|
||||||
|
if (Settings.flag3.sleep_normal) {
|
||||||
// yield(); // yield == delay(0), delay contains yield, auto yield in loop
|
// yield(); // yield == delay(0), delay contains yield, auto yield in loop
|
||||||
delay(sleep); // https://github.com/esp8266/Arduino/issues/2021
|
delay(sleep); // https://github.com/esp8266/Arduino/issues/2021
|
||||||
|
} else {
|
||||||
uint32_t my_activity = millis() - my_sleep;
|
if (my_activity < (uint32_t)sleep) {
|
||||||
if (my_activity < (uint32_t)Settings.param[P_LOOP_SLEEP_DELAY]) {
|
delay((uint32_t)sleep - my_activity); // Provide time for background tasks like wifi
|
||||||
delay((uint32_t)Settings.param[P_LOOP_SLEEP_DELAY] - my_activity); // Provide time for background tasks like wifi
|
|
||||||
} else {
|
} else {
|
||||||
if (global_state.wifi_down) {
|
if (global_state.wifi_down) {
|
||||||
delay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period
|
delay(my_activity /2); // If wifi down and my_activity > setoption36 then force loop delay to 1/3 of my_activity period
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!my_activity) { my_activity++; } // We cannot divide by 0
|
if (!my_activity) { my_activity++; } // We cannot divide by 0
|
||||||
uint32_t loop_delay = Settings.param[P_LOOP_SLEEP_DELAY];
|
uint32_t loop_delay = sleep;
|
||||||
if (!loop_delay) { loop_delay++; } // We cannot divide by 0
|
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 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;
|
uint32_t this_cycle_ratio = 100 * my_activity / loop_delay;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#ifndef _SONOFF_VERSION_H_
|
#ifndef _SONOFF_VERSION_H_
|
||||||
#define _SONOFF_VERSION_H_
|
#define _SONOFF_VERSION_H_
|
||||||
|
|
||||||
#define VERSION 0x0603000E
|
#define VERSION 0x0603000F
|
||||||
|
|
||||||
#define D_PROGRAMNAME "Sonoff-Tasmota"
|
#define D_PROGRAMNAME "Sonoff-Tasmota"
|
||||||
#define D_AUTHOR "Theo Arends"
|
#define D_AUTHOR "Theo Arends"
|
||||||
|
|
|
@ -181,10 +181,14 @@ void WiFiSetSleepMode(void)
|
||||||
#if defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
#if defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
|
||||||
#else // Enabled in 2.3.0, 2.4.0 and stage
|
#else // Enabled in 2.3.0, 2.4.0 and stage
|
||||||
if (sleep) {
|
if (sleep) {
|
||||||
|
if (Settings.flag3.sleep_normal) {
|
||||||
WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times
|
WiFi.setSleepMode(WIFI_LIGHT_SLEEP); // Allow light sleep during idle times
|
||||||
} else {
|
} else {
|
||||||
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)
|
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
WiFi.setSleepMode(WIFI_MODEM_SLEEP); // Disable sleep (Esp8288/Arduino core and sdk default)
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue