With Arduino Sketch development mode, you typically deploy over USB serial. What about deploying OTA, via local WiFi?

About

The Earle Philhower III RPi Pico W repository, as on GitHub, contains an implementation of OTA, over-the-air download of a sketch from the Arduino IDE. That is, rather than downloading via USB-Serial, you can download an updated built sketch over local WiFi. The object here is to enable updates of Softata OTA.

Issues

  • You need to do an initial download over USB-Serial. You then configure to use the network delivery that now is available from the IDE’s Port menu.
  • You have to assign storage on the device, via the IDE menu where the download is stored.
  • When running from an OTA download, the Serial.Write etc command are no long functional. Whilst they can be ignored, any wait for Serial commands will be blocking. You will need to remove these unless you open the USB-Serial in, say, Putty.

Actions

  • You need to enable storage from the Tools menu. Select Flash Size, and choose a suitable partition size. (You might need to “experiment” with different sizes):
  • Download the sketch over USB-Serial. Wait a short period. Then when the device has booted, select the Port from the Tools menu in the Arduino IDE as the relevant Network. For example, as circled in green:
  • If the network option doesn’t show, wait a while and try again. Unplugging and rebooting the device might help.

  • If you get Failed uploading error or similar, use a larger partition.
  • Upon fixing that, you first download again over USB-Serial, then can use OTA gain if the partition size is sufficient.

  • In the sample sketch OTALedFlash (first link above) there is a header file OTALedFlash.h that sets what flash sequence there is for each event in terms of number of flashes and the period of each:
#ifndef STASSID
#define STASSID "<WiFi SSID>"
#define STAPSK "<SSID Password>"
#endif

#define SHORTPULSE 500
#define ULTRA_SHORTPULSE 250
#define LONGPULSE 1000
#define EXTRA_LONGPULSE 1000

#define BOOTING_NUMFLASHES  5
#define BOOTING_PERIOD SHORTPULSE

#define WIFI_STARTED_NUMFLASHES  3
#define WIFI_STARTED_PERIOD LONGPULSE

#define OTA_ON_START_NUMFLASHES  4
#define OTA_ON_START_PERIOD ULTRA_SHORTPULSE

#define OTA_ON_END_NUMFLASHES  4
#define OTA_ON_END_PERIOD LONGPULSE

#define OTA_ON_ERROR_NUMFLASHES  6
#define OTA_ON_ERROR__PERIOD EXTRA_LONGPULSE

#define READY_NUMFLASHES  8
#define READY_PERIOD ULTRA_SHORTPULSE

Softata Integration of OTA

Integrating this into the Softata sketch has some issues:

  • USB-Serial: If not physically used/opened/connected, there are a lot of Serial debug write messages. RTS/CTS are not used so these messages won’t be sent and won’t be blocking. If there are any while(!Serial) waits for Serial, these would be blocking.
    • So probably best to start with a #define such as #define USE_USB_SERIAL.
      • Then in code where there is a while(!Serial) use an #ifdef ... #endif wrapper to include it,
      • Or get a boolean such as bool useSerial= USE_USB_SERIAL then wrapper each such while(!Serial) with if(useSerial){ }.
      • Could use either of these with all Serial writes.
      • May want to replace if(Serial)with a delay if not required.
      • Also might replace Serial.Write with a macro such as SERIAL_WRITE that then has conditional compile code that if USE_USB_SERIAL is true is Serial.Write or if not is no code.
  • The size of the Softata image is also of interest. The Pico has 2MB of flash storage which has to be partitioned. Probably makes sense to partition it in half. The downloaded image gets stored in the file system in the second half partition which then gets copied into the first part of the partition to run.
    • A build of Softata returns
      630120 bytes (31%) of program storage space
    • A build of the samp-e above returns
      402716 bytes (38%)
      • The OTA capability inflates an image quite a lot!
    • Hopefully an OTA version of Softata should fit into a 1MB partition???

 TopicSubtopic
<  Prev:   Microsoft MVP
   
 This Category Links 
Category:Softata Index:Softata
  Next: > Softata
<  Prev:   Softata