Software over the Air (wired in this case) update. This program demonstrates the SW Update library.
Dependencies: mbed HTTPClient SWUpdate mbed-rtos Watchdog EthernetInterface
Demonstrator for the SWUpdate Library library.
Steps to test and use it
- Revise the test program for your environment. The following lines may need to be changed:
- const char *url = "http://192.168.1.201/mbed";
- const char *name = "SWUp";
- pc.baud(460800); fast, because I like a snappy terminal!
- Enable debug to monitor progress.
- HTTPClient.cpp: Remove leading "" on line #define DEBUG "HTCL"
- HTTPFile.cpp: Remove leading "" on line #define DEBUG "HTfi"
- Compile this program.
- Copy the bin file to the mbed (if this is the very first execution of this program).
- Save the bin file to an accessible web server (simplifying the filename is ok).
- Create the companion text file, which contains the version, checksum, and size of the binary. Save on the web server.
- Use a serial program (e.g. Tera Term), set for a matching baud-rate as configured in the program (e.g. 460.8K).
- Reset the mbed so the program runs.
- Program prints its startup banner, which includes the compile time date(and time) stamp.
- Press 's', which is the command for 's'oftware update check.
- SWUpdate library queries the server for the .txt file, assesses if there is a newer version.
- SWUpdate downloads the new version.
- SWUpdate compares the size and checksum to assess validity.
- SWUpdate removes all other .bin files if the new version is good.
- Reports the installation of the new version and reboots to activate it.
Sample Report - Debug Enabled
SW Update: Mar 8 2015, 16:57:43 *** Initializing network interface... Connecting to network... Ethernet connected as 192.168.1.119 Connected at 100 Mb/s
User now presses 's' to initiate the software update check.
SoftwareUpdateCheck (http://192.168.1.201/mbed) (SWUp) [INF HTCL 94] url: http://192.168.1.201/mbed/SWUp.txt, timeout: 15000 [INF HTCL 88] url: http://192.168.1.201/mbed/SWUp.txt, timeout: 15000 [INF HTCL 148] connect(http://192.168.1.201/mbed/SWUp.txt,0,...,15000) [INF HTCL 170] parse: [http://192.168.1.201/mbed/SWUp.txt] ...
The server should have two files (of interest):
- SWUp.txt First it sought the SWUp.txt file to assess if the currently installed version is old.
... [DBG HTCL 412] Receiving data [DBG HTCL 461] Retrieving 16 bytes [INF HTCL 464] write 16,16: 26,3947,80472 [DBG HTCL 502] Completed HTTP transaction ...
It determines that the local version is out of date, so it prepares to pull down the newer version.
... [INF HTfi 18] HTTPFile /local/SWUp26.BIN [INF HTCL 88] url: http://192.168.1.201/mbed/SWUp.bin, timeout: 15000 [INF HTCL 148] connect(http://192.168.1.201/mbed/SWUp.bin,0,...,15000) ...
It forms the command to get the binary, and sends that to the server.
... [DBG HTCL 557] send(GET /mbed/SWUp.bin HTTP/1.1 Host: 192.168.1.201:80 Connection: keep-alive ,77) ...
In response to that "GET" command, the server replies.
... [DBG HTCL 374] Read header : Content-Length: 80472 [INF HTfi 66] setDataLen(80472) ...
Soon after this, the console shows the streaming process of pulling down the data and writing it to a file. As the data is binary, the console shows a combination of text and binary. Some of this garbage fools the terminal program (which was running in VT100 mode) into continuing to show binary.
... [DBG HTCL 546] Read 213 bytes [INF HTCL 464] write 213,78679: ¥àIÕ¥$à [INF HTfi 40] write(213,¥àIÕ¥$à) m_len(80472), chunk 0 [INF HTfi 43] writ:213, ftell: 1998 ...
Eventually, we get to the end of this.
... [INF HTfi 45] closing [INF HTfi 24] close() [DBG HTCL 502] Completed HTTP transaction Update installed, rebooting ...
And the new version is installed and activated. When the SWUpdate is working as intended, debug can be disabled.
This text is all emitted from the sample program, not the SWUpdate library, after 's' is pressed to initiate the software update check.
SoftwareUpdateCheck (http://192.168.1.201/mbed) (SWUp) Update installed, rebooting ... SW Update: Mar 8 2015, 17:47:50 *** Initializing network interface... Connecting to network... Ethernet connected as 192.168.1.119 Connected at 100 Mb/s
Files at revision 3:2c9d1d0a89de