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

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sun Jul 14 01:43:17 2019 +0000
Parent:
2:0b4d91a6e3ac
Commit message:
Minor update to clarify when selected file is missing

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
SWUpdate.lib Show annotated file Show diff for this revision Revisions of this file
Watchdog.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 0b4d91a6e3ac -r 2c9d1d0a89de EthernetInterface.lib
--- a/EthernetInterface.lib	Sun Mar 08 17:51:28 2015 +0000
+++ b/EthernetInterface.lib	Sun Jul 14 01:43:17 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#65b0d840274c
+http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
diff -r 0b4d91a6e3ac -r 2c9d1d0a89de HTTPClient.lib
--- a/HTTPClient.lib	Sun Mar 08 17:51:28 2015 +0000
+++ b/HTTPClient.lib	Sun Jul 14 01:43:17 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/HTTPClient/#3556275bebf3
+http://mbed.org/users/WiredHome/code/HTTPClient/#c5abb7ae070b
diff -r 0b4d91a6e3ac -r 2c9d1d0a89de SWUpdate.lib
--- a/SWUpdate.lib	Sun Mar 08 17:51:28 2015 +0000
+++ b/SWUpdate.lib	Sun Jul 14 01:43:17 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/SWUpdate/#cf73b0d75bb7
+http://mbed.org/users/WiredHome/code/SWUpdate/#3d3089b8212d
diff -r 0b4d91a6e3ac -r 2c9d1d0a89de Watchdog.lib
--- a/Watchdog.lib	Sun Mar 08 17:51:28 2015 +0000
+++ b/Watchdog.lib	Sun Jul 14 01:43:17 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/Watchdog/#22c5c4aa4661
+http://mbed.org/users/WiredHome/code/Watchdog/#e0f547e22dd5
diff -r 0b4d91a6e3ac -r 2c9d1d0a89de main.cpp
--- a/main.cpp	Sun Mar 08 17:51:28 2015 +0000
+++ b/main.cpp	Sun Jul 14 01:43:17 2019 +0000
@@ -62,7 +62,7 @@
     } else if (SWUP_SAME_VER == su) {
         pc.printf("  no update available.\r\n");
     } else {
-        pc.printf("  update failed %04X\r\n", su);
+        pc.printf("  update failed %04X - %s\r\n", (int)su, SoftwareUpdateGetHTTPErrorMsg(su));
     }
 }
 
@@ -80,6 +80,13 @@
 }
 
 
+void ShowMenu() {
+    pc.printf("Menu:\r\n");
+    pc.printf("  r - reset\r\n");
+    pc.printf("  s - software update check\r\n");
+    pc.printf("\r\n");
+}
+
 // Only 2 items in this menu - check for software updates and reset!
 void CheckConsoleInput(void)
 {
@@ -94,6 +101,7 @@
                 break;
             default:
                 pc.printf("unknown command '%c'\r\n", c);
+                ShowMenu();
                 break;
         }
     }
@@ -125,6 +133,7 @@
                 ShowIPAddress(true);
                 int speed = get_connection_speed();
                 pc.printf("Connected at %d Mb/s\r\n", speed);
+                ShowMenu();
                 while (NetworkIsConnected()) {
                     Thread::wait(500);
                     CheckConsoleInput();