Bluetooth: Mesh light fixture

The Bluetooth® mesh light fixture sample demonstrates how to set up a light control mesh server model application, and control a dimmable LED with Bluetooth mesh using the Generic OnOff models.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

nrf5340dk_nrf5340_cpuapp_ns

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52833 DK

PCA10100

nrf52833dk_nrf52833

nrf52833dk_nrf52833

nRF52833 DK (emulating nRF52820)

PCA10100

nrf52833dk_nrf52820

nrf52833dk_nrf52820

Thingy:53

PCA20053

thingy53_nrf5340

thingy53_nrf5340_cpuapp

thingy53_nrf5340_cpuapp_ns

nRF21540 DK

PCA10112

nrf21540dk_nrf52840

nrf21540dk_nrf52840

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 Thingy:53 application guide for details.

Overview

This sample can be used to control the state of light sources. In addition to generic on and off functions, it allows changing the light level (brightness) of a LED light.

The sample instantiates the Light Lightness Server model and the Light Lightness Control Server model. As both Light Lightness Server and the Light LC Server extend the Generic OnOff Server, the two models need to be instantiated on separate elements. For more information, see documentation on Light Lightness Control Server.

Devices are nodes with a provisionee role in a mesh network. 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 dimmable LED 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 fixture composition data for this sample:

Element 1

Element 2

Config Server

Gen. OnOff Server

Health Server

Light LC Server

Gen. Level Server

Light LC Setup Server

Gen. OnOff Server

Gen. DTT Server

Gen. Power OnOff Server

Gen. Power OnOff Setup Server

Light Lightness Server

Light Lightness Setup Server

The models are used for the following purposes:

  • The first element contains a Config Server and a Health Server. The Config Server allows configurator devices to configure the node remotely. The 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 seven other models in the first element are the product of a single instance of the Light Lightness Server. The application implements callbacks for the Light Lightness Server to control the first LED on the device using the PWM (pulse width modulation) driver.

  • The three models in the second element are the product of a single instance of the Light Lightness Control (LC) Server. The Light LC Server controls the Light Lightness Server in the first element, deciding on parameters such as fade time, lighting levels for different states, and inactivity timing. In this sample, the Light LC Server is enabled by default at first boot.

Other nodes can control the Light Lightness Server through the Light LC Server, by sending On/Off messages to the Light LC Server or to the Generic OnOff Server in the second element.

Note

It is possible to bypass the Light LC Server by directly communicating with the Light Lightness Server on the first element.

For more details, see Light Lightness Server and Light Lightness Control Server.

The model handling is implemented in src/model_handler.c, which uses the DK Button and LEDs library and the PWM API to control the LEDs on the development kit.

User interface

Buttons:

Can be used to input the out-of-band (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. First LED outputs the current light level of the Light Lightness Server in the first element.

Note

Thingy:53 supports only one RGB LED. Each RGB LED channel is used as separate LED.

Configuration

See Configuring your application 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.

  • A file for handling mesh models, model_handler.c.

  • A file for handling PWM driven control of the dimmable LED, lc_pwm_led.c.

  • A thingy53.c file, used to handle preinitialization of the Thingy:53 board. It is only compiled when the sample is built for the Thingy:53 board.

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 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. This variable instructs the build system to append the appropriate devicetree overlay file. For example, to build the sample from the command line for an nRF52833 DK with the nRF21540 EK attached, use the following command within the sample directory:

    west build -b nrf52833dk_nrf52833 -- -DSHIELD=nrf21540_ek
    

    This command builds the application firmware. 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 Working with RF 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_ctrl in the nRF Connect SDK folder structure.

See Building and programming an application for information about how to build and program the application.

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:

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

  2. Select the Mesh Light Fixture 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 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 Fixture 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.

  • Open the Generic OnOff Server in the second element, then tap ON at the bottom of the Generic On Off Controls.

You should now see the following actions:

  1. The LED fades from 0% to 100% over a defined transition time following the message Standby -> On.

  2. The LED stays at 100% for three seconds On.

  3. The LED fades from 100% to CONFIG_BT_MESH_LIGHT_CTRL_SRV_LVL_PROLONG over five seconds On -> Prolong.

  4. The LED stays at CONFIG_BT_MESH_LIGHT_CTRL_SRV_LVL_PROLONG for three seconds Prolong.

  5. The LED fades from CONFIG_BT_MESH_LIGHT_CTRL_SRV_LVL_PROLONG to 0% over five seconds Prolong -> Standby.

The default value of CONFIG_BT_MESH_LIGHT_CTRL_SRV_LVL_PROLONG is 10000 (~15%).

Light level transitions over time

Light level transitions over time

Note

The configuration of light levels, fade time, and timeouts can be changed by altering the configuration parameters in the prj.conf file, and rebuilding the sample.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries: