From 5d1f5a40a1a52144ad481aa597a8db4d431c7774 Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Wed, 31 Oct 2018 15:03:47 -0300 Subject: [PATCH 1/2] Reduce CPU usage at boot time If many drivers has been enabled, there is a peak of CPU usage at boot time that it is translated as a peak in power consumption. This address to a wifi connection issue in poor power regulated devices like Sonoff Basic R2. This fix reduces cpu usage making the wifi connection to establish faster. --- sonoff/xdrv_interface.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino index c80bb27d4..a6e917a83 100644 --- a/sonoff/xdrv_interface.ino +++ b/sonoff/xdrv_interface.ino @@ -249,6 +249,9 @@ boolean XdrvCall(byte Function) boolean result = false; for (byte x = 0; x < xdrv_present; x++) { + if (!((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0))) { + delay(1); + } result = xdrv_func_ptr[x](Function); if (result) break; } From 1fc19ccf5ff6c64c275befcbe5aed88a1e2c29bd Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Wed, 31 Oct 2018 15:07:27 -0300 Subject: [PATCH 2/2] Reduce CPU usage at boot time --- sonoff/xsns_interface.ino | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino index 408e68af9..ee3d545da 100644 --- a/sonoff/xsns_interface.ino +++ b/sonoff/xsns_interface.ino @@ -284,6 +284,9 @@ boolean XsnsNextCall(byte Function) { xsns_index++; if (xsns_index == xsns_present) xsns_index = 0; + if (!((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0))) { + delay(1); + } return xsns_func_ptr[xsns_index](Function); } @@ -298,19 +301,21 @@ boolean XsnsCall(byte Function) for (byte x = 0; x < xsns_present; x++) { #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND - uint32_t profile_start_millis = millis(); + uint32_t profile_start_millis = millis(); #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND - + if (!((WL_CONNECTED == WiFi.status()) && (static_cast(WiFi.localIP()) != 0))) { + delay(1); + } result = xsns_func_ptr[x](Function); #ifdef PROFILE_XSNS_SENSOR_EVERY_SECOND - uint32_t profile_millis = millis() - profile_start_millis; - if (profile_millis) { - if (FUNC_EVERY_SECOND == Function) { - snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); - AddLog(LOG_LEVEL_DEBUG); + uint32_t profile_millis = millis() - profile_start_millis; + if (profile_millis) { + if (FUNC_EVERY_SECOND == Function) { + snprintf_P(log_data, sizeof(log_data), PSTR("PRF: At %08u XsnsCall %d to Sensor %d took %u mS"), uptime, Function, x, profile_millis); + AddLog(LOG_LEVEL_DEBUG); + } } - } #endif // PROFILE_XSNS_SENSOR_EVERY_SECOND if (result) break;