Skip to main content
BlogNewsTop News

Connectig Conexio Stratus to Golioth

By March 31, 2022No Comments

Written by Rajeev Piyare, Founder of Conexio Technologies

Preface

Millions of transactions with vending machines, gas pumps, kiosks, price checkers, and retail point-of-sales stations occur daily from internally run embedded systems. Embedded systems are used actively in the home, medical facilities, and the industrial sector. Embedded systems are also a part of machine-to-machine (M2M) interfaces like processing equipment, controllers, sensors, and robotics/automation equipment.

Uptime is important for embedded devices, but guaranteeing uptime is challenging.

Having embedded devices that can work by themselves is a great time saver because you can leave them to the task that they were designed for. Therefore, remotely located, devices need to be monitored to gain visibility and the status report on the performance of these devices. Such remote management tools can alert administrators when errors occur or devices fail to work at all, so they can identify and resolve the errors quickly.

One such observability platform is Golioth. Golioth allows device makers to deliver on the promise of cloud-connected IoT, enabling hardware developers to build end-to-end IoT-connected products using their choice of hardware and connectivity, all without the need for a team of cloud engineers. From device messaging to security, firmware updates, analytics, and more, the platform provides device services that work with every developer’s hardware and firmware requirements. At the moment, Golioth supports embedded IoT devices running ZephyrRTOS. And the good news is that Golioth is now open to use for developers.

This tutorial….

Covers how to connect your Conexio Stratus device to the Golioth platform. Specifically, this post will demonstrate how to:

  • Setup the toolchains and the Golioth SDK.
  • Connect Stratus kit to the Golioth cloud, periodically send environmental data, and monitor the device.
  • Perform Stratus Device Firmware Upgrade (DFU) procedure over the cellular network.

We have a lot to cover, so let’s dive in.

Golioth SDK is built around ZephyrRTOS and comes as a separate module. Since the Stratus device requires nRF Connect SDK for cellular connectivity, we first need to initialize the nRF Connect SDK as per the Golioth docs. So choose the directory on your machine where you want to install the Golioth SDK with the following command. For this tutorial, we are naming our directory where the Golioth SDK will reside to be “golioth-sdk”.

Once the nRF SDK is fetched, navigate to the west.yml located in `golioth-sdk/nrf` and add the following entry in `manifest/projects/subtree`

After updating the west.yml file, it should now look similar to this:

Now to clone all the required repositories by issuing the following command:

Depending on your network speed, this will take several minutes so sit back tight until the process completes. Upon successful completion, you should see the ‘golioth’ directory under

Bravo. For now, our SDK is all set. Let’s head over to the Golioth cloud to create an account.

Registration and Device Setup on the Golioth Cloud

Join the Golioth and create a user account here. And yes, joining Golioth is Free.

Once your account is created, head over to the “Projects” menu on the left-hand pane and Create a Project as shown:

Give your device a name and click Save.

Note: One can also achieve the steps shown here using the Golioth command-line tools (CLI) as outlined in the documentation. For this tutorial, we will use the Golioth console for setting up our devices and for faster provisioning.

Next, we need to provision our devices and acquire the credentials to connect it to the Golioth platform. Expand the “Management” menu and click Devices. Then, on the right-hand top view, click Create and select Provision with Credentials.

This will pop up a Device fast path Provision window as shown:

Next, choose a name for your device, give your device a tag label (read more about Golioth tags here), choose an identity (ID), or keep the default one generated automatically. Finally, add your pre-shared key (PSK) as per your liking and click Save. Later, we will need this ID and the PSK to authenticate our Stratus device with the Golioth platform.

At this point, we have all the required details to connect and publish data from our Conexio Stratus device to the Golioth. Let’s head over to the device firmware side.

Stratus Sample Application We have extended the Light DB stream sample application provided in the Golioth SDK to connect the Stratus kit to the Golioth and stream sensory data. The extended application periodically samples the environmental data from the onboard SHT4x sensor and publishes it to the /temp and /humidity Light DB stream path.  For the first part of this post, the full application can be found in the conexio-stratus-firmware/samples/golioth/stratus_lightdb_stream repo on GitHub.

Copy the project folder and place it in your Golioth SDK samples directory.

Below is the snapshot of the code’s main loop:

Add Golioth credentials to the Application Code

First, we will have to add the Golioth credentials (ID and PSK) that we configured above using the Golioth console into the application code. You will need to edit samples/stratus_lightdb_stream/prj.conf with your credentials and update the following parameters.

Compiling the Sample Application using nRF Connect for VS Code


Next, open the sample application in your favorite code editor such as Visual Studio Code, or simply use the nRF Connect extension for VS Code for compiling your application. If using the nRF Connect extension, selectandopen the stratus_lightdb_stream project and Add the Build Configuration as shown, and click Build Configuration. Now, you should see the build process kicking in the background and generating the required files and binaries for the sample application.

Once the project is compiled successfully, in the project navigation panel, you will see all the generated files.
Well done! You have successfully managed to compile the sample application using the nRF Connect extension.
 
Compiling the Sample Application using West
 
To compile the application using west, open a terminal window in the application directory (stratus_lightdb_stream) and issue the following command:

In case you do not want to recall the west commands simply command the following in the terminal, and the included python script will take care of the rest.

Flashing the Sample Application

Once the application is compiled successfully using either of the tools above, connect the Stratus device to the USB port and put it into the DFU mode.

Flash the compiled firmware using newtmgr:

Open up a serial console with a baud rate of 115200 and reset the Stratus device. The following serial UART output will be displayed in the terminal.

Once the device is connected to the Golioth cloud, it will start sending the environmental data. To confirm that the Stratus device is actually connected and communicating to the Golioth backend, head over to the Golioth console, and your device Status should now indicate as “online.”

To observe the incoming data from the Stratus device, on the left-hand under the Monitor menu, click Light DB Stream and the Query Response window will appear. One should now see the incoming data from the device as shown below.

If you do “Houston, we have lift-off”… 🚀.

Your device is now connected and communicating with the Golioth cloud.

Explore around the console to see other features currently offered by the Golioth platform. One such feature that is of utmost importance for IoT devices is the ability to update firmware remotely. We will next look into this feature with a sample application.

Device Firmware Update (DFU) using Golioth

Over-the-air (OTA) firmware updates are a vital component of any IoT system. Over-the-air firmware updates refer to the practice of remotely updating the code on an embedded device.

The value of incorporating OTA update capabilities into a connected product include:

  • The ability to add new software features to a product after a device has been deployed in the field to improve functionality over time.
  • The opportunity to rapidly respond to bugs and security vulnerabilities without the need for physical recalls of devices or truck rolls; an expensive task for the business.
  • Ensuring embedded developers can quickly prototype and seamlessly roll out new versions of the device firmware, speeding up innovation cycles.

Recently, Golioth has released a firmware update feature in their latest SDK. Using this, we will demonstrate how to:

  • Generate a new firmware that is compatible and can be updated remotely to the Stratus device.
  • Perform the DFU procedure using the Golioth console by creating Artifacts and Releasing the firmware to the fleet of devices.

Overview of the DFU Sample Application

The DFU sample application extends the Light DB stream example that we have explored above for connecting the Stratus to the Golioth platform with an added ability to periodically check for any firmware updates. This mimics the realistic IoT application where a remote device might be performing some tasks (here, frequently sampling and sending the environmental data) while also being able to be updated remotely with new features or bug fixes.

The sample application for Stratus DFU  resides in the conexio-stratus-firmware/samples/golioth/stratus_dfu repo on GitHub.

Go ahead and copy the project folder and place it in your Golioth SDK samples directory.

Add Golioth credentials to the Application Code

Add your Golioth credentials by editing the samples/stratus_dfu/prj.conf and update the following parameters.

Building and Flashing the Sample Application

Open a terminal window in the application directory (stratus_dfu) and compile the firmware for the Stratus device using:

Once the application is compiled successfully, connect the Stratus device to the USB port and put it into the DFU mode.

Next, flash the compiled firmware using newtmgr:

Open up a serial console and reset the Stratus device. The following sample serial UART output will be displayed:

So far so good. This is similar to our previous example. Next, we will prepare the new firmware version that we would like to update the Stratus device with remotely.

Generating New OTA Firmware

For testing the DFU mechanism, we need to first assign a new firmware version during the image build process to distinguish between the current running firmware (golden image) and the new incoming one.

To generate the new application firmware, execute the following command:

Here, we have named our new image to be version 2.0.0. You can assign a version number to anything you like which makes identifying the firmware release easier.

Creating the OTA Firmware Release

In order to create a new firmware release, two steps are required. First, in the Golioth console, we need to Create an Artifact. An Artifact is simply the actual firmware binary that we have generated above which is compatible with the MCUboot mechanism. MCUboot is a library that can be integrated into a bootloader to securely perform firmware updates.

Under Firmware Updates, click Artifacts, and Creating an Artifact window will open.

Assign a name to the Package, followed by the Version number. Here, we have assigned a name as “main” with firmware version “2.0.0” (same as the version number we used when generating the DFU firmware above).

Under Artifacts, navigate to the build folder of your project and upload the following binary: app_update.bin.

Next, hit Save.

After saving the Artifact, you should now see the Size of the binary that will be transmitted to the device to be updated with Type as mcuboot.

The next step is to create the Release. Creating a Release allows the rolling out of the latest firmware to the targeted fleet of devices. To do so, click Release on the left-hand menu, and set the Release Flag as your choice. Here we have chosen V2.0.0 to indicate that we are releasing version 2.0.0 of the firmware.

Next, assign the Device Tags. Device Tags allows releasing the firmware to the subset of your fleet. In our case, we will only release the latest firmware to those devices that are tagged with “stratus”. You will notice that for this demonstration, our “Affected devices count” is 1, indicating that only one device that has been tagged with “stratus” will be updated out of the entire fleet of devices. Other devices will remain untouched. A cool feature, I think!

Finally, select your Artifacts, which will be the artifact that we created above, and click Save.

Upon saving the release, you should now see all the designated parameters.

At this point, if you are happy with the firmware release, go ahead and enable Rollout by toggling the Rollout button. Enabling rollout allows the Golioth cloud to send down the firmware to the remote device/s, the next time when the devices connect to the Golioth cloud.

As soon as you hit rollout, you will now notice the following activity on the device side.

The Stratus device detects the desired incoming image and starts receiving the new firmware in chunks of 1kb over the cellular network. Once the full image has been received (which might take a minute or two depending on the size) and saved onto the internal flash of the nRF9160 SiP, the device will start the firmware upgrade procedure by commanding a reboot.

At this point, the MCUboot will start fetching the information of the image from the image start address, verify, and mark the images ready to be installed after which it will load the newly downloaded image.

Once the boot process has been successfully completed you will now see the latest firmware running on your Stratus device:

Note that the application running on your device now detects that the current running image version matches with the one on the Golioth cloud.

You have now successfully upgraded your Stratus device firmware using the remote firmware update capability of the Golioth platform. Mission Accomplished!

Conclusion

In this post, we have merely touched on all the features that the Golioth platform offers. However, this tutorial sets a solid foundation for connecting, monitoring, and updating your Stratus devices via the Golioth. As the Golioth team is constantly updating the platform, expect more feature rollouts soon. The full application for this tutorial can be found in the conexio-stratus-firmware repo on GitHub.

For further questions regarding Conexio Stratus or this tutorial, you can  join our Conexio Discord Channel.

If you have any questions or comments in general, please feel free to reach out on the Zephyr Discord Channel.

Zephyr Project