This Golioth OpenThread Demo is a Reference Design for a Thread Protocol enabled device using Zephyr and connecting to Golioth over IPv6.
Devices using the Thread protocol work with Golioth thanks to the internet connection available through a border router. This example application shows how to flash and provision a Thread device. Once connected it will periodically stream an up-counting timer value to the cloud to simulate time-series sensors data. The device may be controlled from the Golioth web console to adjust settings (like the frequency of sensor readings), issue RPCs, remotely view device logs, and deploy Over-the-Air firmware updates (OTA).
Business use cases and hardware build details are available on the Golioth Thread Demo Project Page.
This repository contains the firmware source code and pre-built release firmware images.
- Nordic nRF52840-DK
- Adafruit Feather nRF52840 Express
- A running Thread Border Router with NAT64 translation (we will be using the commercially available off-the-shelf GL-S200 Thread Border Router).
This app implements:
- Device Settings Service
- Remote Procedure Call (RPC)
- Stream Client
- LightDB State Client
- Over-the-Air (OTA) Firmware Upgrade
- Backend Logging
The following settings should be set in the Device Settings menu of the Golioth Console.
-
LOOP_DELAY_SAdjusts the delay between sensor readings. Set to an integer value (seconds).Default value is
60seconds.
The following RPCs can be initiated in the Remote Procedure Call menu of the Golioth Console.
-
rebootReboot the system. -
set_log_levelSet the log level.The method takes a single parameter which can be one of the following integer values:
0:LOG_LEVEL_NONE1:LOG_LEVEL_ERR2:LOG_LEVEL_WRN3:LOG_LEVEL_INF4:LOG_LEVEL_DBG
Sensor readings are simulated using an up-counting timer. The value is
periodically sent to the sensor/counter path of the Golioth Stream
service.
{
"counter": 1
}Note
Your Golioth project must have a Pipeline enabled to receive this data. See the Add Pipeline to Golioth section below.
The concept of Digital Twin is demonstrated with the LightDB State
example_int0 and example_int1 variables that are subpaths of the
desired and state paths.
desiredvalues may be changed from the cloud side. The device will recognize these, validate them for [0..65535] bounding, and then reset these values to-1statevalues will be updated by the device to reflect the device's actual stored value. The cloud may read thestateendpoints to determine device status. In this arrangement, only the device should ever write to thestateendpoints.
{
"desired": {
"example_int0": -1,
"example_int1": -1
},
"state": {
"example_int0": 0,
"example_int1": 1
}
}By default the state values will be 0 and 1. Try updating the
desired values and observe how the device updates its state.
This application includes the ability to perform Over-the-Air (OTA) firmware updates. To do so, you need a binary compiled with a different version number than what is currently running on the device.
Note
If a newer release is available than what your device is currently
running, you may download the pre-compiled binary that ends in
_update.bin and use it in step 2 below.
-
Update the version number in the
VERSIONfile and perform a pristine (important) build to incorporate the version change. -
Upload the
build/app/zephyr/zephyr.signed.binfile as a Package for your Golioth project.- Use
mainas the package name. - Use the same version number from step 1.
- Use
-
Create a Cohort and add your device to it.
-
Create a Deployment for your Cohort using the package name and version number from step 2.
-
Devices in your Cohort will automatically upgrade to the most recently deployed firmware.
Visit the Golioth Docs OTA Firmware Upgrade page for more info.
Golioth uses Pipelines to route stream data. This gives you flexibility to change your data routing without requiring updated device firmware.
Whenever sending stream data, you must enable a pipeline in your Golioth
project to configure how that data is handled. Add the contents of
pipelines/cbor-to-lightdb.yml as a new pipeline as follows (note that
this is the default pipeline for new projects and may already be
present):
- Navigate to your project on the Golioth web console.
- Select
Pipelinesfrom the left sidebar and click theCreatebutton. - Give your new pipeline a name and paste the pipeline configuration into the editor.
- Click the toggle in the bottom right to enable the pipeline and
then click
Create.
All data streamed to Golioth in CBOR format will now be routed to LightDB Stream and may be viewed using the web console. You may change this behavior at any time without updating firmware simply by editing this pipeline entry.
Important
Do not clone this repo using git. Zephyr's west meta tool should be
used to set up your local workspace.
cd ~
mkdir golioth-openthread-demo
python -m venv golioth-openthread-demo/.venv
source golioth-openthread-demo/.venv/bin/activate
pip install wheel west ecdsacd ~/golioth-openthread-demo
west init -m [email protected]:golioth/golioth-openthread-demo.git .
west update
west zephyr-export
pip install -r deps/zephyr/scripts/requirements.txtConfigure the following Kconfig options:
OPENTHREAD_NETWORK_NAME: Name of your Thread networkOPENTHREAD_NETWORKKEY: Network Key of your Thread network
by changing these lines in the prj.conf configuration file, e.g.:
CONFIG_OPENTHREAD_NETWORKKEY="00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff"
CONFIG_OPENTHREAD_NETWORK_NAME="golioth-thread"
CONFIG_OPENTHREAD_CHANNEL=26
CONFIG_OPENTHREAD_PANID=34739Note
Make sure the Thread Network Name, Thread Network Key, Thread Channel and Thread PAN ID match your Border Router configuration.
Build the Zephyr sample application for the Nordic nRF52840
DK
(nrf52840dk_nrf52840) from the top level of your project. After a
successful build you will see a new build directory. Note that any
changes (and git commits) to the project itself will be inside the app
folder. The build and deps directories being one level higher
prevents the repo from cataloging all of the changes to the dependencies
and the build (so no .gitignore is needed).
Prior to building, update VERSION file to reflect the firmware version
number you want to assign to this build. Then run the following commands
to build and program the firmware onto the device.
Warning
You must perform a pristine build (use -p or remove the build
directory) after changing the firmware version number in the VERSION
file for the change to take effect.
$ (.venv) west build -p -b nrf52840dk/nrf52840 --sysbuild app
$ (.venv) west flash
Configure PSK-ID and PSK using the device shell based on your Golioth credentials and reboot:
uart:~$ settings set golioth/psk-id <my-psk-id@my-project>
uart:~$ settings set golioth/psk <my-psk>
uart:~$ kernel reboot cold
This reference design may be built for the Adafruit Feather nRF52840 Express board.
$ (.venv) west build -p -b adafruit_feather_nrf52840/nrf52840 --sysbuild app
$ (.venv) west flash
Please get in touch with Golioth engineers by starting a new thread on the Golioth Forum.