Bluetooth: Mesh Light

The Bluetooth Mesh Light sample demonstrates how to set up a basic Mesh server model application and control LEDs with the 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 the Bluetooth: Mesh Light Switch sample.

Overview

This sample is split into two source files:

  • A main.c file to handle initialization.

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

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.

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

The models are used for the following purposes:

  • Generic OnOff Server instances in elements 1 to 4 each control LEDs 1 to 4, 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 Button and LED library to control each LED on the board according to the matching received messages of Generic OnOff Server.

Requirements

  • One of the following development kits:

    • nRF5340 PDK board (PCA10095) - see Working with nRF5340; if you use this development kit, add the following options to the configuration of the network sample:

      CONFIG_BT_CTLR_TX_BUFFER_SIZE=74
      CONFIG_BT_CTLR_DATA_LENGTH_MAX=74
      

      This is required because Bluetooth Mesh has different Bluetooth LE Controller requirements than other Bluetooth samples.

    • nRF52840 DK board (PCA10056) - see Working with nRF52

    • nRF52 DK board (PCA10040) - see Working with nRF52

    • nRF51 DK board (PCA10028)

  • Smartphone with Nordic Semiconductor’s nRF Mesh mobile app installed in one of the following versions:

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.

Building and running

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

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

Testing

After programming the sample to your board, you can test it by using a smartphone with Nordic Semiconductor’s nRF Mesh 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 device to connect to it.

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

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

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

Configuring models

Complete the following steps in the nRF Mesh app to configure models:

  1. On the Network screen, tap the Mesh Light node. Basic information about the mesh node and its configuration is displayed.

  2. In the Mesh node view, expand the first element. It contains the list of models in the first element of the node.

  3. Tap Generic OnOff Server to see the model’s configuration.

  4. Bind the model to application keys to make it open for communication:

    1. Tap BIND KEY at the top of the screen.

    2. Select Application Key 1 from the list.

    You are now able to control the first LED on the device by using the Generic On Off Controls in the model view.

  5. Tap ON to light up the first LED on the development kit.

Repeat steps 3-5 for each of the elements on the node to enable controling each of the remaining three LEDs.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries: