Bluetooth Mesh NLC: HVAC Integration (Sensor observer)

The Bluetooth® Mesh NLC HVAC Integration sample demonstrates how to set up a basic Bluetooth Mesh Sensor Client model application that gets sensor data from one Sensor Server model. Eight different sensor types are used to showcase different ways for the server to publish data. In addition, the samples demonstrate usage of both single-channel sensor types and sensor series types, as well as how to add and write to a sensor setting.

This sample also demonstrates how to implement the HVAC Integration NLC Profile (see Bluetooth Networked Lighting Control profiles).

Note

This sample must be paired with Bluetooth Mesh NLC: Ambient Light Sensor/Occupancy Sensor to show any functionality. The observer has no sensor data, and is dependent on a mesh sensor to provide it.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF54LM20 DK

PCA10184

nrf54lm20dk

nrf54lm20dk/nrf54lm20a/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nRF54L15 DK (emulating nRF54L10)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l10/cpuapp

nRF54L15 DK (emulating nRF54L05)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l05/cpuapp

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nRF21540 DK

PCA10112

nrf21540dk

nrf21540dk/nrf52840

The sample also requires a smartphone with Nordic Semiconductor’s nRF Mesh mobile app installed in one of the following versions:

Additionally, the sample requires the Bluetooth Mesh NLC: Ambient Light Sensor/Occupancy Sensor sample application, programmed on a separate development kit and configured according to mesh sensor sample’s testing guide.

Overview

The following Bluetooth Mesh sensor types, and their settings, are used in this sample:

Provisioning

The provisioning is handled by the Bluetooth Mesh provisioning handler for Nordic DKs. It supports four types of out-of-band (OOB) authentication methods, and uses the Hardware Information driver to generate a deterministic UUID to uniquely represent the device.

Use nRF Mesh mobile app for provisioning and configuring of models supported by the sample.

Models

The following table shows the mesh sensor observer composition data for this sample:

Element 1

Config Server

Health Server

Sensor Client

The models are used for the following purposes:

  • Config Server allows configurator devices to configure the node remotely.

  • Health Server provides attention callbacks that are used during provisioning to call your attention to the device. These callbacks trigger blinking of the LEDs.

  • Sensor Client gets sensor data from one or more Sensor Servers.

The model handling is implemented in src/model_handler.c. Sensor data can be periodically requested using a k_work_delayable loop, which can be started and stopped with a button press.

User interface

Buttons:

Can be used to input the OOB authentication value during provisioning. All buttons have the same functionality during the provisioning procedure.

Once the provisioning procedure has completed, the buttons will have the following functionality:

Button 1:

Toggles the periodic Sensor Get data loop on/off.

Button 2:

Sends a get message for the bt_mesh_sensor_dev_op_temp_range_spec setting of the bt_mesh_sensor_present_dev_op_temp sensor.

Button 3:

Sends a set message for the bt_mesh_sensor_dev_op_temp_range_spec setting of the bt_mesh_sensor_present_dev_op_temp sensor, switching between the ranges specified in the temp_ranges variable.

Button 4:

Sends a set message for the bt_mesh_sensor_motion_threshold setting of the bt_mesh_sensor_presence_detected sensor, switching between the ranges specified in the presence_motion_threshold variable.

Terminal:

All sensor values gathered from the server are printed over UART. For more details, see Testing and optimization.

Note

Some sensor and setting values need to be get/set through shell commands, as there is not enough buttons on the board for all sensor and setting values.

Configuration

See Configuring and building for information about how to permanently or temporarily change the configuration.

Source file setup

This sample is split into the following source files:

  • A main.c file to handle initialization.

  • One additional file for handling Bluetooth Mesh models, model_handler.c.

FEM support

You can add support for the nRF21540 front-end module to this sample by using one of the following options, depending on your hardware:

  • Build the sample for one board that contains the nRF21540 FEM, such as nRF21540 DK.

  • Manually create a devicetree overlay file that describes how the nRF21540 FEM is connected to the SoC. See Configuring devicetree for different ways of adding the overlay file.

  • Provide nRF21540 FEM capabilities by using a shield, for example the nRF21540 EK shield that is available in the nRF Connect SDK. In this case, build the project for a board connected to the shield you are using with an appropriate variable included in the build command, for example -DSHIELD=nrf21540ek. This variable instructs the build system to append the appropriate devicetree overlay file.

    To build the sample in nRF Connect for VS Code for an nRF52840 DK with the nRF21540 EK attached, add the shield variable in the build configuration’s Extra CMake arguments and rebuild the build configuration. For example: -DSHIELD=nrf21540ek.

    See How to work with build configurations in the nRF Connect for VS Code documentation for more information.

    See Programming nRF21540 EK for information about how to program when you are using a board with a network core, for example the nRF5340 DK.

Each of these options adds the description of the nRF21540 FEM to the devicetree. See Developing with Front-End Modules for more information about FEM in the nRF Connect SDK.

To add support for other front-end modules, add the respective devicetree file entries to the board devicetree file or the devicetree overlay file.

Building and running

This sample can be found under samples/bluetooth/mesh/sensor_client in the nRF Connect SDK folder structure.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

Note

The mesh sensor observer sample cannot demonstrate any functionality on its own, and needs a device with the Bluetooth Mesh NLC: Ambient Light Sensor/Occupancy Sensor sample running in the same mesh network. Before testing the mesh sensor observer, go through the mesh sensor’s testing guide with a different development kit.

After programming the sample to your development kit, you can test it by using a smartphone with nRF Mesh mobile app installed. Testing consists of provisioning the device and configuring it for communication with the mesh models.

All sensor values gathered from the server are printed over UART. For more details, see Testing and optimization.

Provisioning the device

The provisioning assigns an address range to the device, and adds it to the mesh network. Complete the following steps in the nRF Mesh app:

  1. Tap Add node to start scanning for unprovisioned mesh devices.

  2. Select the Mesh Sensor Observer device to connect to it.

  3. Tap Identify, and then Provision, to provision the device.

  4. When prompted, select an OOB method and follow the instructions in the app.

Once the provisioning is complete, the app returns to the Network screen.

Configuring models

See Configuring Bluetooth Mesh models using the nRF Mesh mobile app for details on how to configure the mesh models with the nRF Mesh mobile app.

Configure the Sensor Client model on the Mesh Sensor Observer node:

  • Bind the model to Application Key 1.

  • Set the publication parameters:

    • Destination/publish address: Select an existing group or create a new one, but make sure that the Sensor Server subscribes to the same group.

    • Retransmit count: Set the count to zero (Disabled), to avoid duplicate logging in the UART terminal.

  • Set the subscription parameters: Select an existing group or create a new one, but make sure that the Sensor Server publishes to the same group.

The Sensor Client model is now configured and able to receive data from the Sensor Server.

Interacting with the sample through shell

  1. Connect the development kit to the computer using a USB cable. The development kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the nrfutil device list command. Alternatively, check your operating system’s device manager or its equivalent.

  2. Connect to the kit that runs this sample with a terminal emulator that supports VT100/ANSI escape characters (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.

  3. Enable local echo in the terminal to see the text you are typing.

  4. Enable mesh shell by typing mesh init

After completing the steps above, a command can be given to the client. See Sensor Client and Bluetooth Mesh Shell for information about shell commands.

SensorID/SettingID used in the shell commands are:

For example, to set the sensor gain for present ambient light level to 1.1, write the following:

mesh models sensor setting-set 0x004E 0x0074 1.1

External flash for settings partition

This sample supports relocating mesh settings to external flash on nrf52840dk/nrf52840, nrf54l15dk/nrf54l15/cpuapp, nrf54l15dk/nrf54l10/cpuapp, and nrf54l15dk/nrf54l05/cpuapp board targets. See the nRF52840 DK User Guide or the nRF54L15 DK User Guide for details about the external flash memory available on the board. This provides additional storage space for mesh persistent data.

To enable external flash settings storage, set FILE_SUFFIX to settings_ext_flash when building the sample.

Build the sample using the following command:

west build -p -b *board_target* -- -DFILE_SUFFIX=settings_ext_flash

Note

The external flash is not erased during the internal flash erasing procedure. See nRF Util for more information on how to erase the external flash.

The settings subsystem requires allocating some persistent memory area, which is done through the settings subsystem backend configuration in the form of an allocated number of sectors.

For NVS backend:

For ZMS backend:

The sector size depends on the flash memory layout.

Apart from this, the allocated partitions are defined in a devicetree (DTS) overlay file. The size of the storage_partition node defined in the DTS overlay must be equal to the memory size configured for the settings subsystem.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries: