Sensor monitoring

This sample demonstrates how a temperature sensor communicates over the secure Sidewalk network, which is a simple Sidewalk-based IoT use case. It requires an edge device (a sensor). You can find an application server (cloud backend with web UI) compatible with this sample in the Amazon Sidewalk Sample IoT App repository.

Source file setup

The application consists of the following source files:

  • app.c (app.h) – The main application file starts the TX and RX thread, assigns button actions to the buttons on the board, and adds received messages to the received message queue.

  • app_sensor.c, app_button.c, app_led.c – The files implement interface between the hardware and sample application.

  • app_rx.c (app.h) – RX thread reads messages from the received messages queue, deserializes them, and triggers actions.

  • app_tx.c (app.h) – TX thread sends messages from the device to cloud. Depending on the actual state of the device, it sends capability messages or sensor data notifications.

Application TX thread state machine

Application TX thread state machine.

Configuration options

Before building the Sensor monitoring application variant of the Sidewalk end device, ensure you have enabled the OVERLAY_CONFIG="overlay-demo.conf" configuration.

The sample variant supports the following Kconfig options:

  • CONFIG_SIDEWALK – Enables support for the Sidewalk protocol and its dependencies.

  • CONFIG_SIDEWALK_SUBGHZ_SUPPORT – Enables using Sidewalk libraries with Bluetooth LE, LoRa and FSK support. Disabling this option results in using Sidewalk libraries with only Bluetooth LE support. While this results in a smaller memory footprint for the application, it also limits its functionality, as connectivity over LoRa or FSK is not available.

  • CONFIG_SIDEWALK_DFU – Enables the nRF Connect SDK bootloader and DFU service over Bluetooth LE.

  • CONFIG_SID_END_DEVICE – Switches between the application variants.

    • CONFIG_SID_END_DEVICE_HELLO – Enables the Hello Sidewalk application. This is the default option. For more details, see the Hello Sidewalk page.

    • CONFIG_SID_END_DEVICE_SENSOR_MONITORING – Enables the Sidewalk Sensor monitoring application. For more details, see the Sensor monitoring page.

    • CONFIG_SID_END_DEVICE_DUT – Enables the Sidewalk device under test application. For more details, see the Device Under Test (DUT) page.

  • CONFIG_SID_END_DEVICE_CLI – Enables Sidewalk CLI. To see the list of available commands, flash the sample and type sid help.

  • CONFIG_SIDEWALK_ON_DEV_CERT – Enables the on-device certification Shell.

  • CONFIG_SID_END_DEVICE_AUTO_START – Enables an automatic Sidewalk initialization and start.

  • CONFIG_SID_END_DEVICE_AUTO_CONN_REQ – Enables an automatic connection request before sending a message. If needed, the Bluetooth LE connection request is sent automatically.

  • SID_END_DEVICE_PERSISTENT_LINK_MASK - Enables persistent link mask.

  • CONFIG_SID_END_DEVICE_NOTIFY_DATA_PERIOD_MS – Enables the notify period of the sensor monitoring end device app in milliseconds.

You can build the sensor_monitoring end device application with Bluetooth LE only libraries by running the following command in the project directory:

$ west build -b build_target -- -DCONFIG_SID_END_DEVICE_SENSOR_MONITORING=y -DCONFIG_SIDEWALK_SUBGHZ_SUPPORT=n

For example:

$ west build -b nrf5340dk_nrf5340_cpuapp -- -DCONFIG_SID_END_DEVICE_SENSOR_MONITORING=y -DCONFIG_SIDEWALK_SUBGHZ_SUPPORT=n

User Interface

Button 1 (long press):

Enter DFU state - This action disables the Sidewalk stack and starts the Bluetooth LE SMP Server. You can update the firmware image using the nRF Connect for mobile application. To exit the DFU state, long press Button 1.

Button 2 (long press):

Factory reset - The application informs the Sidewalk stack about the factory reset event. The Sidewalk library clears its configuration from the non-volatile storage. After a successful reset, the device needs to be registered with the cloud services again.

Button 3 (long press):

Toggles the Sidewalk link mask - This action switches from Bluetooth LE to FSK, from FSK to LoRa, and from LoRa to Bluetooth LE. A log message informs about the link mask switch and the status of the operation.

Button 1-4 (short press):

Send button action message - This action works after the application successfully sends capability message.

LED 1-4:

Notify LED action message - Works after the application successfully sends capability message.

Building and running

This sample can be found under samples/sid_end_device.

Note

Before you flash your Sidewalk sample, make sure you have completed the following:

This step needs to be completed only once. You do not have to repeat it for every sample rebuild.

To build the sample, follow the steps in the Building and programming an application documentation.

Testing

Note

For the full installation guidelines and the application overview, refer to the Amazon Sidewalk Sample IoT App repository. Flash the Nordic device with the end device sensor monitoring application instead of the prebuilt HEX file provided in the cloud application repository.

See Testing and debugging an application for information on testing and debugging in the nRF Connect SDK.

After successfully building the sample and flashing manufacturing data, the sample is ready to use. To refresh the logs, restart the program by pressing the RESET button on your development kit. You should see the following output:

*** Booting nRF Connect SDK 883c3709f9c8 ***
----------------------------------------------------------------
sidewalk             v2.5.0-3-g1232aabb
nrf                  v2.5.0-g271e80422
zephyr               883c3709f9
----------------------------------------------------------------
sidewalk_fork_point = af5d608303eb03465f35e369ef22ad6c02564ac6
build time          = 2023-03-14 15:00:00.000000+00:00
board               = nrf52840dk_nrf52840
----------------------------------------------------------------
[00:00:00.001,373] <inf> application_state: working = true
[00:00:00.055,480] <inf> sidewalk_app: Sidewalk link switch to BLE

Testing Device Firmware Update (DFU)

  1. To enter the DFU mode, long press Button 1 on your development kit. This action sets the device in the DFU mode, in which only the Zephyr SMP Server is running and Sidewalk is not operational. When the application is in the DFU mode, all LEDs flash every 500 ms to signal that the application is waiting for a new image.

  2. To perform a firmware update, follow the Bluetooth testing steps from the DevZone DFU guide. When the update starts, the LEDs change the pattern to indicate upload in progress.

  3. To exit the DFU mode, long press Button 1 again when device is in DFU mode. The device will set the device in the Sidewalk mode. If the update completes successfully, the device will start a new image. After using the DFU mode, the first bootup might take up to 60 seconds. During the image swap the application is silent, meaning that LEDs are not blinking and the console does not output any logs. The application, however, is running, so do not reset the device. In case the update fails, the old image is started instead.