This section talks about how to do an app update and roll back to the previous working version of the app if the update fails. We have provided an example on our Github page. There are four files in the example.

  • hello_app - Prints “Hello from Bytebeam” every 3 seconds.
  • app_update_rollback.sh - This script replaces the old application with the new application. If the new application doesn’t work, this script replaces it with the working version of the application.
  • updater - This is a wrapper script for app_update_rollback.sh script.
  • make_firmware_update.sh - It creates the update tar file.

It is expected that there is a working version of the application on the remote device and is expected to be run by systemd.

To create an update file, with the custom application, follow these steps.

Step1: Prepare update tar

Firstly on your Linux system, we need to create an update tar file for Raspberry Pi. For that, Download all the files mentioned above from GitHub. Next, we need to change the permissions for all these files using chmod command

chmod a+x hello_app
chmod a+x app_update.sh
chmod a+x update.sh
chmod a+x make_firmware_update.sh 

Next run make_firmware_update.sh to create a tar.gz file.

./make_firmware_update.sh

Step 2: upload update Tar

Next, we need to upload the tar to bytebeam cloud. For that go to the device management panel and navigate to the Firmware Versions tab. Then click on Upload New Firmware

Under the Firmware version tab, you will find an option to create a firmware version number and upload your updated tar file.

Enter the new Firmware version number and click on choose file to upload tar file. Then click on Create.

Step 3: Set the application path

In step 1 we have already assumed that you want to update the hello_app that exists on your remote device and we created an update tar accordingly. On the remote device, the app is expected to be in /usr/local/bin location. If it’s not there then create a new hello_app in /usr/local/bin.

#!/bin/bash

while [ 1 ]
        do
                sleep 3
                echo "Hi from Bytebeam"
        done

If the application location and app name are different, set the path in app_update.sh script in Step 1.

APP_NAME=hello_app
APP_BIN_PATH=/usr/local/bin

Step 4: Create systemctl service to debug update changes

To debug your changes after the app update, Let’s create a service that runs hello_app. So, create this service named <App Name>.service and place it in /etc/systemd/system.

[Unit]
Description=Simple Application service
After=network.target auditd.service

[Service]
ExecStart=/usr/bin/bash /usr/local/bin/hello_app
KillMode=process
Restart=on-failure
Type=simple

[Install]
WantedBy=multi-user.target

Reload systemctl daemon and start the service.

sudo systemctl daemon-reload 
sudo systemctl enable app.service
sudo systemctl start app 

Step 5: Trigger the “update firmware” action from bytebeam cloud

Now let’s proceed with our OTA update. For that, Go to Device Management panel and select the device

Next, Click on the update firmware

In the next prompt choose the firmware version and click on next