Software Updates

Executing a Software Update

Here is an example of a firmware update. It consists of a firmware binary and a script to install it:

Create a software update


POST /software_updates

{
  "name": "network-firmware-update",
  "device_type_id": "5c0feaee693d3f0001150285",
  "script": "./install.sh"
} 

Upload files

Software updates may be associated with multiple files. There is a 100MB limit on the size each file.

POST /software_updates/{id}/files
file=firmware.bin

POST /software_updates/{id}/files
file=install.sh

Contents of install.sh

URL=$1
TEMP_DIR=/tmp

echo "Downloading firmware file...\n"
wget $URL -O $TEMP_DIR/firmware.bin
if [ $? -ne 0 ]; then
    echo "Error downloading firmware file\n"
    exit 1   
fi

echo "Verifying firmware file...\n"
sysupgrade -v -T $TEMP_DIR/firmware.bin
if [ $? -ne 0 ]; then
    echo "Error verifying firmware file\n"
    exit 1
fi

echo "Starting firmware update..."
sysupgrade -v -c $TEMP_DIR/firmware.bin 
if [ $? -ne 0 ]; then
    echo "Error starting firmware update\n"
    exit 1   
fi

exit 0

Execute the gateway command

POST /devices/{device_id}/gateway_commands

{
  "command_type": "software_update",
  "software_update_id": "5c0feb9a693d3f000115028c"
}

Response:

{
  "_id": "5c26658fcd55d5000169eb8b",
  "origin": "cloud",
  "created_at": "2018-12-28T18:03:59.5588456Z",
  "updated_at": "2018-12-28T18:03:59.5588456Z",
  "company_id": "machineshop",
  "user_id": "5bb3e6d773c6b700018695fa",
  "command_type": "software_update",
  "payload": {
    "name": "network-firmware-update",
    "files": [
      {
        "name": "firmware.bin",
        "link": "https://s3.amazonaws.com/machineshop-files-dev/machineshop/machineshop/software-update-device/5c0feb9a693d3f000115028c/firmware.bin"
      },
      {
         "name": "install.sh",
         "link": "https://s3.amazonaws.com/machineshop-files-dev/machineshop/machineshop/software-update-device/5c0feb9a693d3f000115028c/install.sh"
            }
    ],
    "script": "./install.sh",
    "reboot": false
  },
  "statuses": {
    "example-network-device": {
      "status": "sent",
      "status_message": ""
    }
  },
  "device_id": "5c0feb7f693d3f000115028a",
  "device_type_id": "5c0feaee693d3f0001150285"
}

Monitor status of gateway command

You can use the _id returned from the creation of the gateway command to track the status of the update. The statuses of each targeted device(sent in this example) will be updated after the command is processed. For more information on possible statuses see Gateway Commands.


Did this page help you?