Skip to content

Zephyr Samples for Nordic Thingy53 dev kit OpenThread mesh with json data, BME688 BSEC2 for Air Quality, Light color, RGB Les, Battery

License

Notifications You must be signed in to change notification settings

HomeSmartMesh/sdk-hsm-thingy53

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Zephyr reference samples for Thingy53 dev kit, simple reference samples and sensors server

Features

  • Air quality with BME688 driver and library integrating Bosch's BSEC2 library for IAQ (Indoor Air Quality) measurements.
  • Mesh Network with OpenThread broadcasting UDP packets as client and running a sensors server.
  • C++ application with json inputs for config and outputs for sensors enables direct mapping to MQTT
  • RGB Led, Light color, Battery

SensorsServer

Dev Kit

Below is an open box Nordic Thingy53 attached to USB and j-Link debugger USB Attachments

Hardware

Used Sensors in this repo's samples

Repo structure

Dependencies

Drivers and libraries

The following drivers and libraries have been created in this repo

BME688 Components and Data

BME688DriversLib

Usage

mkdir thingy53
cd thingy53
>west init -m https://github.com/HomeSmartMesh/sdk-hsm-thingy53 --mr main
>west update

building a sample

cd hsm/samples/20_sensors_server
west build
west build -- -DOVERLAY_CONFIG="overlay-logging.conf"

flashing using an attached debugger

>west flash

recover by deleting flash

>west flash --recover

flashing manually

  • connect to USB
  • power on while holding SW2 down, see details on updating thingy53 through USB
  • with nRFConnect Programmer flash hsm\samples\20_sensors_server\build\zephyr\dfu_application.zip

Serial Port

  • USB Serial Port : with the config CONFIG_STDOUT_CONSOLE=y this board creates a UAB virtual COM port of stdout. Note using the nRFSDK Connect Serial Terminal allows auto detection and reconnect of serial ports, very useful to recover automatically after flashing
  • RTT Debugger Serial Port : using CONFIG_USE_SEGGER_RTT=y it is possible to have logs with the attached debugger and without using the board USB device, this needs rebuild the sample differently though.

joining a thread network

sample with joiner config CONFIG_OPENTHREAD_JOINER_PSKD are 13_ot_joiner, 14_ot_udp_echo_server, 15_udp_json_endpoint and 20_sensors_server Note: Make sure to press the Thingy53 button after the raspberry pi commissioner is started. The button will reset the device and try to join thread networks on the new startup.

joining info:

  • the eui64 can be known by first flashing the logging version with overlay-logging.conf
  • without knowing the eui64 it is also possible to commission with '*' as eui64 parameter

on the raspberry pi

sudo ot-ctl
commissioner start
commissioner joiner add * ABCDE2

Samples details

for convenience and given that this repo is providing samples for thingy53_nrf5340_cpuapp board, it has been configured in the CMakeLists.txt to be taken as default board, it is still possbile to override it with -b option.

01_alive_counter_uart

samples/01_alive_counter_uart

simplest program for checking UART with a live counter

02_rgb_led

samples/02_rgb_led

controlling the colors of the Red Green and Blue LEDs with pwm

  • function for setting x3 float colors
  • function for blinking a color

03_battery

samples/03_battery

  • Power Management Integrated Circuit specification nPM1100_PS_v1.3.pdf
  • Thingy53 schematics PCA20053_Schematic_And_PCB.pdf

used pios

  • Battery Measure ENABLE P0.16 vbatt.power-gpio in thingy53_nrf5340_common.dts
  • Battery Measure BAT_MEAS P0.06/AIN2 vbatt.io-channels in thingy53_nrf5340_common.dts
  • Battery charging Indicator CHG PMIC_STATUS P1.00 battery-charge-gpios in app.overlay

04_bme680

samples/04_bme680

Note: Do not use this sample, it is for info only, using BME680 driver for BME688 can only fetch temp,hum,press but not gas due to difference in registers config

  • this sample is based on BME680 Zephyr sample from Nordic's fork nRF BME680 Zephyr sample
  • this samples uses the device drivers declaration bosch,bme680 in the thingy53 dts file thingy53_nrf5340_common.dts used for
    • Temperature
    • Air pressure
    • Humidity

05_bme688

samples/05_bme688

  • sample demonstrating the usage of the BME688 C driver wrapper over Zephyr's sensor API and using Bosch's BME68x-Sensor-API
  • config flag CONFIG_BME688=y

Output

del_period = 142590
Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm)
25.24, 95917.63, 40.48, 23992.50
new data , no Gas Index , Gas Meas Valid , Heat Stability

references

06_bme688_parallel

samples/06_bme688_parallel

  • introducing usage additional custom functions to enable usage of BME688 in prallel mode still in C language
  • config flag CONFIG_BME688=y
  • bme688_set_mode_default_conf()
  • bme688_data_get()

07_bme688_parallel_cpp

!! crashing to be fixed !! in the meanwhile and for parallel mode see 06_bme688_parallel

samples/07_bme688_parallel_cpp

  • a C++ wrapper for bme688_server library
  • config flags CONFIG_BME688=y and CONFIG_BME688_SERVER=y
  • set_bme688_config() with temperatures and durations in a json structure
  • start_bme688() with a handler that gets a json structure with temperature, humidity, pressure, gas-0..gas-9

08_bme688_bsec2

samples/08_bme688_bsec2

  • Enables the BSEC2 part of the bme688_server library, Bosch-BSEC2-Library .a vendor's binary integration for IAQ (Indoor Air Quality) measurements https://github.com/boschsensortec/Bosch-BSEC2-Library
  • new flag CONFIG_BME688_BSEC2=y in addition to CONFIG_BME688=y and CONFIG_BME688_SERVER=y
  • returns iaq, iaq_accuracy, co2_eq, breath_voc, stabilization and runin calculated from the bsec2 library

09_bh1749

samples/09_bh1749

  • Color sensor BH1749NUC
    • BH1749NUC Datasheet
    • Measures Red, Green, Blue and IR
    • Illuminance Detection Range 80 klx (0.0125 lux/count)

11_openthread_shell

samples/11_openthread_shell

  • provides a shell on the USB UART interface that allows to manually configure the openthread stack

build

cd thingy53/hsm/samples/11_openthread_shell
>west build

12_ot_udp_client

samples/12_ot_udp_client

  • using a fixed openthread network config allows to hard-code network credentials for testing only (not suited for deployment), even when used for local deployments it is unpractical as the device needs to be flashed everytime the network parameters change
  • loops sending alive counter messages as thread udp packets
  • overlay-logging.conf uses RTT and USB log for openthread state and loop count

build options

>west build
>west build -- -DOVERLAY_CONFIG="overlay-logging.conf"

13_ot_joiner

samples/13_ot_joiner

  • Commissioning with a joiner PSKd (Pre-Shared Key for the Device) ABCDE2
    • needs the commissioner to be ready for this device
  • short SW2 button press < 1 sec : soft reset SYS_REBOOT_WARM
    • will retry joining if not attached
  • long SW2 button press > 1 sec : OpenThread Farctory reset (delete credentials) and SYS_REBOOT_COLD
    • will try joining a new network
  • overlay-logging.conf uses RTT and USB log and prints the following on startup
    • Joiner eui64
    • Joiner pskd built with in the provided config
    • the qrcode text containing the eui64 and pskd as parameters
    • a url to a generated qrcode image to be used for joining
  • loops sending alive counter messages as thread udp packets

build options

>west build
>west build -- -DOVERLAY_CONFIG="overlay-logging.conf"

14_ot_udp_echo_server

samples/14_ot_udp_echo_server

  • OpenThread broadcasts udp packet
  • separate udp_rx_handler thread
  • binds to port 4242 and echoes back received characters (printed as text)

15_udp_json_endpoint

samples/15_udp_json_endpoint

  • OpenThread server endpoint can receive json commands and send back responses

20_sensors_server

samples/20_sensors_server

  • OpenThread Joiner device
  • OpenThread mesh client broadcasts udp json packet with Voltage, Alive counter, Charging status, ambient light RGB IR, Temperature, pressure, humidity and Indoor Air Quality
  • OpenThread server endpoint can receive json commands and send back responses

on rasp

>sudo ot-ctl
udp open
udp send ff02::1 4242 hi_there_now

Plan

  • MQTT publish sample
  • reliable ot tx rx, e.g. tcp, websocket, session,... for packet request response
  • Python MQTT Translator for request response with json bodies
  • RGB Led notification service
  • sensors json logger service (configurable sensors and rates)
  • ot lifecycle, if not connected, restart after timeout, which will retry join
  • system lifecycle, watchdog restart
  • power measurements
  • microhpone streaming
  • microphone local

Deveopment guide

This repository is a Zephyr workspace application that contains the samples source code only therefore lightweight to clone and manage, yet it tracks an exact reference of all dependencies that get deployed once initialized with west init

Hints and Tricks

  • k_sleep in interrupt functions might lead to os crash, usage of LOG effect unclear so to be avoided
  • Fifo, Lifo, Queue take pointers only, user allocates the data but there's also k_fifo_alloc_put
  • Message Queues copy the data provided in a ring buffer, (overwrite oldest)
  • Work queues are used to delay functions execution or order multiple functions execution

How was this repo created

This repository is targetting an nRF dev kit, thereforeit is safer to derive it from nRF's fork of Zephyr and other dependencies. the steps are :

  • west.yml dependencies taken from https://github.com/nrfconnect/sdk-nrf/blob/main/west.yml
  • the default remote is hsm instead of ncs, therefore in the projects: the remote ncs needs to be added where applicable
  • in the application zephyr, the name-allowlist helps reduce the dependencies from Zephyr
  • note also some Zephyr dependencies can be replaced with top level projects such as mbedtls which is then taken from nRF fork and not from Zephyr
  • in case of Kconfig wanrings, it is necessary to compare with the original repo (ncs/nrf) and find the directory (dependency) where that flag is used e.g. missing config for NRF_MODEM_LIB_SHMEM_CTRL_SIZE which default is NRF_MODEM_SHMEM_CTRL_SIZE defined in nrfxlib\nrf_modem\Kconfig that shows a dependency from nrfconnect/nrf to nrfconnect/nrfxlib

Zephyr references

Project references