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

  1. 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!
  2. Enable debug to monitor progress.
    • HTTPClient.cpp: Remove leading "" on line #define DEBUG "HTCL"
    • HTTPFile.cpp: Remove leading "" on line #define DEBUG "HTfi"
  3. Compile this program.
  4. Copy the bin file to the mbed (if this is the very first execution of this program).
  5. Save the bin file to an accessible web server (simplifying the filename is ok).
  6. Create the companion text file, which contains the version, checksum, and size of the binary. Save on the web server.
  7. Use a serial program (e.g. Tera Term), set for a matching baud-rate as configured in the program (e.g. 460.8K).
  8. Reset the mbed so the program runs.
    1. Program prints its startup banner, which includes the compile time date(and time) stamp.
  9. Press 's', which is the command for 's'oftware update check.
  10. SWUpdate library queries the server for the .txt file, assesses if there is a newer version.
    1. SWUpdate downloads the new version.
    2. SWUpdate compares the size and checksum to assess validity.
    3. SWUpdate removes all other .bin files if the new version is good.
  11. 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.bin
  • 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.

Debug 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