Softata: Towards OTA Over The Air Sketch Updates - 3 (OTA Implementation)
softata rpipico firmata arduino csharp grove swagger asp.net ota wdt watchdog otapico
Following on from the 2 previous posts in this series, OTA deployment has been added to Softata. Only issue was WatchDog Timer timeout during deployment
Links
(All on GitHub)
- Softata sketch that implements OTA deployment djaus2/Soft-ata/SoftataOTA The Solution!
- The complete Softata repository djaus2/Soft-ata
- Arduino RPi Pico BSP: earlephilhower/arduino-pico/
- BSP Examples: earlephilhower/arduino-pico/libraries/ArduinoOTA/examples
- OA Example: OTA
Discussion
The Over-The-Air (OTA functionality) from the OTA example has been merged into the Softata sketch currently as SoftataOTA sketch. This was done in steps because of the concern that built sketch might exceed the 1M limit (it got to 69%). This limit is imposed because of the Pico’s 2M of flash which has to be partitioned in half. The second half for the OTA download that is then flashed into the first half to run. It was also considered prudent to do it in steps including separable parts and to test build then test run the sketch progressively.
The question was whether to add Softata progressively to the OTA example or viz? Initially adding OTA to Softata was attempted but this was found cumbersome. So the reverse was used. Starting with OTA example softata.ino setup()
- The setup() code from softata.ini file was added to the setup() code for the OTA example.
- The required Softata header includes and global variables from softata.ino were also added to softataOTA.ino.
- The ancillary functions in the softata.ino file were added to the softataOTA.ino.
- The other Softata files including the src directory were added to the OTA sketch project.
- The header file at the bottom of softata.ino was added in the same place to softataOTA.ino.
- This file implements the second CPU’s setup1() and loop1() code.
This version was built and issues resolved. It was then tested including an OTA deployment.
Actually, the OTA setup() was renamed setupOTA and this was called at the start of Softata setup() function.
There was an issue with the WatchDog timer. See later.
The loop() code from Softata was added in a similar manner. Amazingly, it built and ran almost on the first try! The device was then tested against the Console app which worked OK! :)
WatchDog Timer Issue
WatchDog functionality is used to cause a system reboot if the system background processing doesn’t reset a hardware timer within a specific period. This is a brute force approach to trap an errant processor. The loop() function should perform an update to the timer at the start of the loop() function and in any busy loops, or delays.
The WatchDog was set to reset the device if it wasn’t “touched” by the background process after 8 seconds. Maximum is period for the RPi Pico is 8.33 seconds. OTA downloads for the first version (Softata setup() inclusion) took in excess of 14 seconds causing a device reboot and OTA failure. The OTA deployment only got to about 8 seconds. The initial resolution of this was to disable the WatchDog functionality. Some queries on this were posted seeking a workaround.
Issue is discussed here.
Footnote
WatchDog and OTA are now compatible using ArduinoOTA.onProgress()
ArduinoOTA.onProgress([](size_t progresso, size_t total){
//THandlerFunction_Progress fn
#ifdef ENABLE_WATCHDOG
watchdog_update();
#endif
});
## Testing
The Softa-ata Console app has new test #13: TestOTAOrWDT which causes a busy wait in Softata on the device not allowing any WDT updates and precluding OTA packets as there is no
case (byte)'O':
case (byte)'W': //Cause WatchDog or OTA failure with busy wait with no WDT or OTA updates.
{
// Other code excluded for simplicity
for (int i=1;i<100;i++)
{
Serial.printf("WDT count: [%u]sec: ", i);
Serial.println();
delay(1000);
}
}
The relevant code in the Console app to action this is which sens ‘W’):
SendMessageCmd("WDTTimeOut");
Typical output on the device for a WDT failure is:
Generating WDT and/or OTA failure.
If WDT test, should get about: [8] USB serial messages before reboot:
WDT count: [0]sec:
WDT count: [1]sec:
WDT count: [2]sec:
WDT count: [3]sec:
WDT count: [4]sec:
WDT count: [5]sec:
WDT count: [6]sec:
WDT count: [7]sec:
OTA server at: pico-E6613008E35C9E36.local:2040
OTA server at: pico-E6613008E35C9E36.local:2040
OTA server at: pico-E6613008E35C9E36.local:2040
With an OTA failure (without WDT enabled) the attempt to deploy when the busy wait is running on the device is in the Arduino IDE is
19:05:52 [ERROR]: No Answer
Failed uploading: uploading error: exit status 1
Conclusion
The Softata sketch version, SoftataOTA, now implements over-the-air (OTA) updates of Softata running on a RPi Pico W. It can now be used with the WatchDog timer. Whether to use WDT and/or OTA is now defined by #define macros in softata.h.
Initially, as a test, an OTA update was run whilst the console app was running the test 1. DigitalButtonLED on the device. The Console app paused and the OTA completed followed by a system reboot. A specific test 13. TestOTAOrWDT has now been added to the Console app which clearly demonstrates the WDT and OTA errors when activated. :)
Topic | Subtopic | |
This Category Links | ||
Category: | Softata Index: | Softata |
Next: > | Softata | Towards OTA Over The Air Sketch Updates - 5 (KISS Principle) |
< Prev: | Softata | Towards OTA Over The Air Sketch Updates - 2 (Serial Debug Msgs) |