Repository navigation
Back off from failed connections and test the firmware natively - #2
Merged
Merged
Conversation
When WiFi was down, v1.1 slept a fixed 6 hours after one failed attempt. That is longer than the ESP8266 can sleep at once (ESP.deepSleepMax(), about 3.5 hours), a single router reboot cost 6 hours of data, and a broker that does not answer was not covered at all: the device stayed awake 25 seconds every 5 minutes. Failed attempts are now counted in RTC memory, and the wait doubles from 10 minutes to at most 2 hours (BACKOFF_MAX_SLEEPTIME). It is made of single 5-minute deep sleeps; a wake that only counts down keeps the radio and the sensor off. A broker timeout counts like a WiFi failure, a connection the access point refuses outright is given up at once, the first transmission reports the failures before it as connectFailures, and OTA mode never waits. The battery percentage is clamped to 0..100 and computed in integers, so a full battery reads 100 instead of 99. src/main.cpp now also runs on the build machine against fakes of the Arduino core and its libraries (test/support/fakes); 23 Unity tests drive the real setup() and loop() and cover 99 % of the lines. CI runs them with a coverage floor and builds the firmware.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1. v1.1 fixed most of the drain; this covers what is left.
Why
v1.1 sleeps a fixed 6 hours after one failed WiFi attempt. Three problems remain:
ESP.deepSleepMax()is 2³¹ RTC ticks, about 3.5 hours.What
BACKOFF_MAX_SLEEPTIME). The first transmission after a failure returns to 5 minutes and reportsconnectFailures.SLEEPTIME.WL_NO_SSID_AVAIL,WL_CONNECT_FAILEDandWL_WRONG_PASSWORDgive up at once instead of after 20 s. The quick connect keeps its 5 s fallback.ESPTEMP_VERSIONisv1.2, and the platform is pinned toespressif8266@4.2.1(core 3.1.2).Tests and CI
src/main.cppnow also runs natively against small fakes of the Arduino core and its libraries (test/support/fakes). 23 Unity tests (pio test -e native) drive the realsetup()andloop(): first boot, quick connect and its fallback, corrupt and unreadable RTC, the full 10/20/40/80/120/120-minute schedule, early abort per status, broker timeout, recovery, counter saturation, low-battery cutoff and its boundary, payload rounding and size, and OTA.ESP.deepSleep().ci.ymlruns the tests with a coverage floor (90 % lines, 80 % branches) and builds the firmware: RAM 36.6 %, flash 31.3 %.Before merge
To test on hardware: switch WiFi off and watch the attempts at 10/20/40/80/120 minutes, then switch it on again (
connectFailuresin the next message). Stop the broker. Check normal operation and OTA.