Bluetooth Mesh: Light
The Bluetooth® Mesh light sample demonstrates how to set up a mesh server model application, and control LEDs with Bluetooth Mesh using the Generic OnOff models.
Note
This sample is self-contained, and can be tested on its own. However, it is required when testing the Bluetooth Mesh: Light switch sample.
This sample also provides support for point-to-point Device Firmware Update (DFU) over the Simple Management Protocol (SMP).
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA20053 |
|
||
PCA10156 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
||
PCA10100 |
|
||
PCA10112 |
|
The sample also requires a smartphone with Nordic Semiconductor’s nRF Mesh mobile app installed in one of the following versions:
Note
If you build this application for Thingy:53, it enables additional features. See Application guide for Thingy:53 for details.
When built for a board target with the */ns
variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
DFU requirements
The configuration overlay file overlay-dfu.conf
and the sysbuild configuration file sysbuild-dfu.conf
enable DFU support in the application, and apply to the following platforms:
nrf52840dk/nrf52840
nrf21540dk/nrf52840
nrf54l15pdk/nrf54l15/cpuapp
While this overlay configuration is only applicable for the mentioned platforms in this sample, DFU over Bluetooth Low Energy may be used on other platforms as well.
Take the flash size into consideration when using DFU over Bluetooth LE on other platforms. For example, both nRF52832 and nRF52833 have limited flash size.
Note
Point-to-point DFU over Bluetooth Low Energy for Thingy:53 is supported by default. See Updating firmware image for Thingy:53 for more information about updating firmware image on Thingy:53.
The DFU feature also requires a smartphone with Nordic Semiconductor’s nRF Device Manager mobile app installed in one of the following versions:
Overview
The mesh light sample is a Generic OnOff Server with a provisionee role in a mesh network. There can be one or more servers in the network, for example light bulbs.
The sample instantiates up to four instances of the Generic OnOff Server model for controlling LEDs. The number of OnOff Server instances depends on available LEDs, as defined in board DTS file.
Provisioning is performed using the nRF Mesh mobile app. This mobile application is also used to configure key bindings, and publication and subscription settings of the Bluetooth Mesh model instances in the sample. After provisioning and configuring the mesh models supported by the sample in the nRF Mesh mobile app, you can control the LEDs on the development kit from the app.
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.
Models
The following table shows the mesh light composition data for this sample:
Element 1 |
Element 2 |
Element 3 |
Element 4 |
---|---|---|---|
Config Server |
Gen. OnOff Server |
Gen. OnOff Server |
Gen. OnOff Server |
Health Server |
|||
Gen. OnOff Server |
Note
When used with Thingy:53, Element 4 is not available. Thingy:53 supports only one RGB LED, and treats each RGB LED channel as a separate LED.
The models are used for the following purposes:
Generic OnOff Server instances in elements 1 to N, where N is number of on board LEDs, each control LEDs 1 to N, respectively.
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.
The model handling is implemented in src/model_handler.c
, which uses the DK Buttons and LEDs library to control each LED on the development kit according to the matching received messages of Generic OnOff Server.
User interface
- Buttons:
Can be used to input the OOB authentication value during provisioning. All buttons have the same functionality during this procedure.
- LEDs:
Show the OOB authentication value during provisioning if the “Push button” OOB method is used. Show the OnOff state of the Generic OnOff Server of the corresponding element.
Configuration
See Configuring and building an application for information about how to permanently or temporarily change the configuration.
For nRF5340 and Thingy:53, the extended advertiser has to be set manually for the network core, because the Bluetooth® Low Energy does not know that the Bluetooth Mesh is enabled when built for this core. This is already done for this sample by setting CONFIG_BT_EXT_ADV=y
for the network core.
Source file setup
This sample is split into the following source files:
main.c
used to handle initialization.model_handler.c
used to handle mesh models.
DFU configuration
To enable the DFU feature for the nRF52840 and nRF54L15 development kits, set SB_CONF_FILE to sysbuild-dfu.conf
and EXTRA_CONF_FILE to overlay-dfu.conf
when building the sample.
For example, when building from the command line, use the following command, where board_target is the target for the development kit for which you are building:
west build -b board_target -p -- -DSB_CONF_FILE="sysbuild-dfu.conf" -DEXTRA_CONF_FILE="overlay-dfu.conf"
The configuration overlay file overlay-dfu.conf
and the sysbuild configuration file sysbuild-dfu.conf
enable the DFU feature.
To review the required configuration alterations, open and inspect the two files.
To enable the DFU feature for the nRF5340 development kit, set SB_CONF_FILE to sysbuild-dfu.conf
and EXTRA_CONF_FILE to overlay-dfu.conf
when building the sample.
Additionally, you need to set the EXTRA_CONF_FILE for the ipc_radio network image to overlay-dfu.conf
as well.
This is an additional network image specific configuration overlay file, which allocates the necessary resources to enable the DFU feature.
For example, when building from the command line, use the following command, where board_target is the target for the development kit for which you are building:
west build -b board_target -p -- -DSB_CONF_FILE="sysbuild-dfu.conf" -DEXTRA_CONF_FILE="overlay-dfu.conf" -Dipc_radio_EXTRA_CONF_FILE="overlay-dfu.conf"
Note
Currently, the nRF5340 development kit only supports DFU for the application core. This implies that all application DFU images must be compatible with the network core image running on the device.
For more information about using configuration overlay files, see Important Build System Variables in the Zephyr documentation. For more information about selecting a sysbuild configuration file, see the sysbuild Kconfig file section on the Sysbuild (System build) page in the Zephyr documentation.
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 nrf21540dk/nrf52840.
Manually create a devicetree overlay file that describes how FEM is connected to the nRF5 SoC in your device. See Set devicetree overlays for different ways of adding the overlay file.
Provide nRF21540 FEM capabilities by using a shield, for example the Developing with 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
SHIELD=nrf21540ek
. This variable instructs the build system to append the appropriate devicetree overlay file.To build the sample in the nRF Connect for VS Code IDE 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 nRF Connect for VS Code extension pack documentation for more information.
To build the sample from the command line for an nRF52840 DK with the nRF21540 EK attached, use the following command within the sample directory:
west build -b nrf52840dk/nrf52840 -- -DSHIELD=nrf21540ek
See Programming nRF21540 EK for information about how to program when you are using a board with a network core, for example 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/light
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
To build the sample, follow the instructions in Configuring and 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
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.
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:
Tap Add node to start scanning for unprovisioned mesh devices.
Select the Mesh Light device to connect to it.
Tap Identify, and then Provision, to provision the device.
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 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 Generic OnOff Server model on each element on the Mesh Light node:
Bind the model to Application Key 1.
Once the model is bound to the application key, you can control the first LED on the device.
In the model view, tap ON (one of the Generic On Off Controls) to light up the first LED on the development kit.
Make sure to complete the configuration on each of the elements on the node to enable controlling each of the remaining three LEDs.
Running DFU
After the sample is built with the overlay-dfu.conf
file and the sysbuild-dfu.conf
file, and programmed to your development kit, support for FOTA update is enabled.
See FOTA over Bluetooth Low Energy for instructions on how to perform FOTA update and initiate the DFU process.
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the following Zephyr libraries:
include/drivers/hwinfo.h
-
include/kernel.h
API:
include/bluetooth/bluetooth.h
-
include/bluetooth/mesh.h
The sample also uses the following secure firmware component: