Skip to content

goliothlabs/esp32-openthread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ccc1e76 · Feb 26, 2025

History

12 Commits
Feb 26, 2025
Oct 5, 2024
Feb 25, 2025
Oct 4, 2024
Oct 4, 2024
Oct 4, 2024
Oct 4, 2024
Oct 7, 2024
Oct 4, 2024
Oct 5, 2024

Repository files navigation

Golioth ESP32-C6 OpenThread Example

Overview

This sample application demonstrates how to connect an ESP32-C6 to Golioth over OpenThread communication protocol. The application implements Golioth's Application Services and Device Management capabilities.

Requirements

  • Golioth device PSK credentials
  • A running Thread Border Router with NAT64 translation (we will be using the commercially available off-the-shelf GL-S200 Thread Border Router)
  • Thread Network Name, Network Key and PAN ID
  • ESP-IDF Release v5.3

Local set up

git clone --recursive git@github.com:goliothlabs/esp32-openthread.git

Or, if you've already cloned but forgot the --recursive, you can update and initialize submodules with this command:

cd esp32-openthread/golioth-firmware-sdk
git submodule update --init --recursive

Building and Running

Configure Thread Network

Configure the following options in sdkconfig.defaults file:

  • OPENTHREAD_NETWORK_NAME - Name of your Thread network
  • OPENTHREAD_NETWORK_CHANNEL - Thread Network Channel
  • OPENTHREAD_NETWORK_PANID - Thread network PAN ID
  • OPENTHREAD_NETWORK_MASTERKEY - Network Key of your Thread network

Important

Make sure the Thread Network Name, Thread Network Key, Thread Channel and PAN ID match your Border Router configuration.

Command-line

Setup the environment, this step assumes you've installed esp-idf v5.3 to ~/esp/esp-idf. If you haven't, follow the initial steps in examples/esp_idf/README.md

source ~/esp/esp-idf/export.sh

From the esp32-openthread directory, set target chip to ESP32-C6:

idf.py set-target esp32c6

build, flash and monitor the console output.

idf.py build
idf.py flash
idf.py monitor

Shell Credentials

settings set golioth/psk-id "YourGoliothDevicePSK-ID"
settings set golioth/psk "YourGoliothDevicePSK"

Type reset to restart the app with the new credentials.

Important

Wait until the device is connected to the Thread network and receives the NAT64 prefix required to synthesize Golioth System Server IPv6 address.

Add Pipeline to Golioth

Head over to Golioth Console to add Pipelines to route stream data. Pipelines give you the 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 and pipelines/json-to-lightdb.yml create two new pipelines as follows (note that cbor-to-lightdb.yml is the default pipeline for new projects and may already be present):

  1. Navigate to your project on the Golioth web console.
  2. Select Pipelines from the left sidebar and click the Create button.
  3. Give your new pipeline a name and paste the pipeline configuration into the editor.
  4. Click the toggle in the bottom right to enable the pipeline and then click Create.

All data streamed to Golioth in CBOR or JSON 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 the pipeline entry.

Golioth Features

This firmware implements the following features from the Golioth Zephyr SDK:

Settings Service

The following settings should be set in the Device Settings menu of the Golioth Console.

LOOP_DELAY_S

Adjusts the delay between sensor readings. Set to an integer value (seconds).

Default value is 60 seconds.

Remote Procedure Call (RPC) Service

The following RPCs can be initiated in the Remote Procedure Call menu of the Golioth Console.

reboot
Reboot the system.
set_log_level

Set the log level.

The method takes a single parameter which can be one of the following integer values:

  • 0: ESP_LOGE - Error (lowest)
  • 1: ESP_LOGW - Warning
  • 2: ESP_LOGI - Info
  • 3: ESP_LOGD - Debug
  • 4: ESP_LOGV - Verbose (highest)

LightDB State and LightDB Stream data

Time-Series Data (LightDB Stream)

An up-counting counter is periodically sent to the cbor/counter and json/counter endpoints of the LightDB Stream service to simulate sensor data. Sending period is based on the LOOP_DELAY_S settings.

Stateful Data (LightDB State)

The concept of Digital Twin is demonstrated with the LightDB State example_int0 and example_int1 variables that are members of the desired and state endpoints.

  • desired values may be changed from the cloud side. The device will recognize these, validate them for [0..65535] bounding, and then reset these endpoints to -1
  • state values will be updated by the device whenever a valid value is received from the desired endpoints. The cloud may read the state endpoints to determine device status, but only the device should ever write to the state endpoints.

OTA Firmware Update

This sample application demonstrates how to perform a Firmware Update using Golioth's Over-the-Air (OTA) update service. This is a two step process:

  • Build initial firmware and flash it to the device.
  • Build new firmware to use as the upgrade and upload it to Golioth.

Edit the app_main.c file and update the firmware version number:

static const char *_current_version = "1.0.1";

Build the firmware update but do not flash it to the device. The binary update file esp_c6_openthread.bin located in the build directory needs to be uploaded to Golioth for the OTA update as an Artifact. After uploading the artifact, you can create a new release using that artifact.

Visit the Golioth Docs OTA Firmware Upgrade page for more info and follow the steps from Zephyr Firmware Update Example Walkthrough.

Important

Update Example Walkthrough is based on Zephyr RTOS and not ESP-IDF.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published