AE-CLOUD1 OTA Tutorial

LEVEL 2: INTERMEDIATE |

This guide is a continuation of the Synergy AE-CLOUD1 IoT Fast Prototyping Kit with Synergy SSP 1.3.2 and wifi tutorial. Please complete that guide before starting this one. This tutorial also assumes you have E2 Studio and Synergy Software Package (SSP) installed.

The AE-CLOUD1 kit with Synergy SSP 1.3.2 also has OTA (over-the-air) firmware update capability. The kit originally came with firmware version “1.0.” This guide will show you how to do OTA update to firmware version “1.1” instead of manually dragging the .srec files onto the board.

Throughout this guide, you will create a new .srec file using the e² studio and upload it to a file hosting service. Then, you’ll create a new workflow in Renesas IoT Sandbox to trigger an OTA firmware update.  Here is a summary diagram to describe what you’ll be doing in this guide:

 

 

PREREQUISITES:

STEP 1: CHECK FIRMWARE VERSION IN DASHBOARD

If you completed the previous guide, your board should already be connected to your Renesas IoT Sandbox project, and you should be able to view data being sent from the board to the cloud. In this step, you will check what version firmware was loaded onto the board.

Log in to Renesas IoT Sandbox. Once logged in, make sure you are in the correct project on the upper right-hand corner.

If you are not in the correct project, click on the dropdown list next to the symbol and select the correct project name.

Click on the Dashboard and you should see a preset Dashboard with five widgets. In the previous guide, you should’ve selected your user in all these widgets and saved the Dashboard configuration.

The top widget of the Dashboard, the Last Value Table, displays the last value of each tag. Locate ‘Firmware Version’ and verify that the last value is in the format of “xxxxxxxx-1.0”. The “xxxxxxxx” should refer to the date that the .srec file was created and the “1.0” refers to the version number.

This is from the firmware you’ve loaded onto your board in the previous guide.

In the following steps, you will create a new .srec file with different version number and then trigger an OTA update.

 

STEP 2: E2 STUDIO

Now, you will make a small change in the project and save it as version 1.1. First, download the project as a .zip file here. This is the project that came preloaded on your board. 

Before you open e2 studio, check that the required pack file is in your directory. Go to C:/Renesas/e2_studio/internal/projectgen/arm/Packs and make sure that pack ‘Renesas.S5D9_IOT_BOARD.1.3.0.pack’ is present. If not, download it from the above link and move the file to this directory.

 

Open E2 Studio. Click File -> Import.

 

Select “Existing Projects into Workspace” in the Import dialog box, then Next.

Click “Browse” beside the “Select root directory” drop-down.

Browse and select the project that you’ve just downloaded from GitHub.

Then click ‘Finish’ on the Import dialog box to import the project.

Navigate to the file in src > app.h

Locate the line:

#define VERSION_MAJOR 1
#define VERSION_MINOR 0

Change the “0” to a “1”:

#define VERSION_MAJOR 1
#define VERSION_MINOR 1

Save and build the project, right click on the project and select ‘Build Project’.  This will start the build process and could take a few minutes. It will produce a new .srec file, which will be used in the next step.

On a successful build, a new .srec image file was generated. The .srec file is located in Debug directory of this project. You will use it in the next step.

STEP 3: UPLOAD IMAGE TO FILE HOSTING SERVICE

In this guide, we will use this link to upload the new .srec file.

Choose the .srec file you’ve just created in the previous project. Upload the file.

Once done uploading, the page will display a URL that you can use in the next step.

 

STEP 4: CREATE OTA WORKFLOW

In this step, you will create a workflow that will be able to trigger the OTA update.

Back on Renesas IoT Sandbox, click on “Workflow Studio” on the sidebar. This page shows all the workflows in your project. Click “Create.”

This will open a new blank workflow canvas.

In the name text area, type “OTA Firmware Update” and click anywhere else on the canvas to save the name.

Click on the “Tags & Triggers” icon on the right sidebar. This is where you will specify when the workflow will run.

Click on “raw” and then look for “connected.” Click and drag “connected” onto the white canvas. In doing this, you specified that upon the board connects to the cloud, it will check for OTA version.

Next, click on “Modules.” Under “Foundation”, click and drag “Base Python” into the canvas.

Connect the two nodes by clicking and dragging. Your workflow should now look like the picture above.

Double-click on the “Base Python” blue box and a popup should appear with details on that module.

Copy and paste this code into the Script text area:

 

import MQTT

ota_info = {
    'major': 1,
    'minor': 1,
    'url': 'SREC_URL',
    'hash': 'HASH'
}

MQTT.publish_event_to_client('s5d9', 'U{}:{}:{}:{}'.format(ota_info['major'], ota_info['minor'], ota_info['hash'], ota_info['url']))

 

Edit values for ‘url’ and ‘hash’;

  • Replace SREC_URL, with the direct URL to your .srec file from the previous step.
  • Replace HASH with the SHA-256 Hash obtained by running a script on your new .srec file. Download the “sha256.py” script here. The script can be ran using the following command: python sha256.py path/to/new_s5d9_wifi_ota.srec. The output value will be used to replace HASH in the above “Base Python” script.

This workflow sends an MQTT message to the board telling it to check if the board’s firmware version matches the latest firmware version. If it does not match, your board will update automatically OTA.

Click on ‘Save and Activate.’ This workflow is now active.

 

STEP 5: TRIGGER OTA UPDATE AND CONFIRM

In this step, you will confirm that the OTA update works.

First, navigate to the Dashboard on Renesas IoT Sandbox. Your top widget should be the “Last Value Table”. Look for “Firmware Version”. It should currently display the older version format of “xxxxxxxx-1.0”.

Leave the Dashboard open.

Now, to trigger the OTA update, restart your board. Upon connection, the board will check if it has the latest firmware. Since it does not, it will download the latest firmware from URL, calculate SHA-256 to verify it is correct, then start the OTA update. 

Initially, your board will have only its yellow LED on. This signals it has started OTA firmware update. The yellow LED may blink several times. Do not disconnect the board — this process will take around 10 minutes. The board will automatically try to reconnect once done updating. 

Navigate back to the Dashboard on Renesas IoT Sandbox.

Check the Last Value Table and verify that the firmware is now changed to the format of “xxxxxxxx-1.1”. Your firmware is now updated to v1.1.

 

Congrats! You’ve successfully set up OTA with the AE-CLOUD1 kit.