Team members Lachlan and Chris discuss an implementation of a Rust code sample with Golioth and the Nordic Semiconductor nRF9160. There is a demo of the code working in the video attached below.

What is Rust?

Rust is a high-level, general-purpose programming language, syntactically similar to C and C++. It is fast and memory-efficient and is specifically designed for performance and safety. It has no runtime or garbage collector, while taking advantage of the higher-level concepts and safety guarantees. Rust can run on embedded devices, and can be easily integrated with other languages, and is ideal for performance-critical services. Rust is still in early days of development, starting in 2010 and only coming to embedded devices a few years ago. The developer community around Rust is passionate and growing. While Rust and C/C++ share similarities, Rust is relatively faster than C/C++ in some cases. Rust also has the benefit of a package management system, which makes implementing different libraries easier than C (which existed long prior to the internet). Easy package management encourages code reuse by allowing libraries to be readily integrated into applications, not to mention building the overall community around Rust.

Why we’re trying it

Golioth was interested in trying out Rust as part of our Golioth Labs segment on GitHub, where the code is currently hosted. It represents one of many trials we have and will take on in order to showcase the Golioth platform. We are committed to showing ways to access Golioth services and APIs outside of our normal recommended path Golioth SDK based on Zephyr RTOS. Not only does this represent the reality for many users, it also showcases how Golioth services are accessible from many different programming paradigms, in addition to a wide range of hardware. Another good example from Golioth Labs is our Arduino SDK discussed in our last article.

We chose to try Rust on the nRF9160 because the hardware represents a key product on the platform. This Nordic part has great support from Golioth and Nordic Semiconductor, and is listed as “Verified + Quickstart” on the Golioth Hardware Catalog. While the quickstart is using Zephyr to get users up and started, it is a well-supported part internally at Golioth. The nRF9160 is also primed for Rust integration: Nordic Semiconductor provides a library for the NRF devices that exposes the API which communicates with the hardware. There is also a Rust binding for it which makes it quite easy to implement the rust code and enables you to connect to Golioth servers and send and receive data. In addition, Rust has some code abstraction features and doesn’t require a debugger.

Video explanation and demonstration

In the demo below, Lachlan shows how he is able to use the library and bindings to connect over CoAP to the Golioth servers and replicate many of the functions that exist in Golioth samples.

In this post and associated video, we’re talking about interfacing hardware to Golioth using popular tools like PlatformIO and Arduino Core (API). Alvaro shows how to use an ESP32 board from Adafruit with the Arduino Core on PlatformIO to talk to the Golioth MQTT endpoint. Golioth has a range of tools and resources for hardware and firmware engineers to get their devices talking to the cloud.

Why PlatformIO?

PlatformIO is a plugin system built on top of VS Code that enables embedded developers to get up and running quickly with different Real Time Operating Systems (RTOS), chipsets, and boards. There is a library manager to help manage dependencies within projects, which removes much of the friction at the beginning of development projects. Currently they do not support Zephyr for ESP32 (a combination previously shown on this blog/channel), but they do support things like the ESP-IDF (based on FreeRTOS) and the Arduino core. Once you pull in the project files from the Golioth Arduino SDK page, PlatformIO will try to download all of the dependencies required to build firmware for a particular board.

What is Arduino Core?

The Arduino Core refers to the APIs that are available on different hardware devices in order to conform to the Arduino ecosystem. In the example below, it refers to Espressif’s Arduino Core port, which means that the ESP32 functions will align with what the Arduino IDE might be asking of that hardware. If you are using platforms outside of the Arduino IDE, you can still interact with many of the underlying functions that were written by hardware and firmware developers to make boards work with Arduino software.

PlatformIO also pulls in other libraries that are useful for processing data coming out of the hardware, such as the Arduino JSON library. So while it’s not the “teal and white IDE” that many people expect, it’s utilizing much of the same work that enabled people to work from within the IDE.

Golioth’s MQTT endpoint

MQTT is now available in preview on Golioth, but should have a similar user experience as other protocols on the platform. Since the early days of Golioth, we have offered device services over CoAP. We chose CoAP as a first offering because it is meant for low-power devices in potentially lossy environments, like cellular networks. MQTT is a popular transport protocol that many engineers use to initially connect their devices to the internet, only to need additional tooling on other platforms. From Golioth’s standpoint, the user doesn’t need to care about which one they’re using. Instead, we provide device services like LightDB, which allows the user to push and pull configuration data and state-based sensor readings from a device. LightDB stream allows for time-series data that needs to be aggregated and displayed on something like a chart. Golioth has other features like firmware updates and logging, that also operate over these protocols.

Showcase video

In the video below, Alvaro shows how the new MQTT endpoint and services from Golioth enable a similar experience that is shown using CoAP in other demos on the platform. What is different now is that we can utilize code from other platforms like Arduino Core, which already had MQTT libraries built-in. Alvaro showcases how he was able to quickly build an Arduino SDK for the Golioth Labs GitHub.