Bluetooth: Mesh light switch

The Bluetooth mesh light switch sample demonstrates how to set up a basic mesh client model application, and control LEDs with the Bluetooth mesh using the Generic OnOff models.

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.

Models

The following table shows the mesh light switch composition data for this sample:

Element 1

Element 2

Element 3

Element 4

Config Server

Gen. OnOff Client

Gen. OnOff Client

Gen. OnOff Client

Health Server

Gen. OnOff Client

The models are used for the following purposes:

  • Generic OnOff Client instances in elements 1 to 4 are controlled by the buttons on the development kit.

  • 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 LEDs library to detect button presses on the development kit.

If the model is configured to publish to a unicast address, the model handler calls bt_mesh_onoff_cli_set() to turn the LEDs of a mesh light device on or off. The response from the target device updates the corresponding LED on the mesh light switch device. If the model is configured to publish to a group address, it calls bt_mesh_onoff_cli_set_unack() instead, to avoid getting responses from multiple devices at once.

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_cpuappns

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF52 DK

PCA10040

nrf52dk_nrf52832

nrf52dk_nrf52832

nRF52833 DK

PCA10010

nrf52833dk_nrf52833

nrf52833dk_nrf52833

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

An additional requirement is the Bluetooth: Mesh light sample application programmed on a separate device, and configured according to the mesh light sample’s testing guide.

User interface

Buttons:

Buttons are used to control the respective Generic OnOff Clients. When pressed, the button toggles the LED state on a mesh light device.

LEDs:

Show the last known OnOff state of the targeted Bluetooth: Mesh light kit.

Building and running

This sample can be found under samples/bluetooth/mesh/light_switch 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

Note

The light switch sample cannot demonstrate any functionality on its own, and needs a device with the Bluetooth: Mesh light sample running in the same mesh network. Before testing mesh light switch, go through the mesh light’s testing guide with a different kit.

After programming the sample to your development kit, 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 Switch 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 Client model on each element on the Mesh Light Switch node:

  • Bind the model to Application Key 1.

  • Set the publication parameters:

    • Destination/publish address: Set the Publish Address to the first unicast address of the Mesh Light node.

    • Retransmit count: Set the count to zero (Disabled), to prevent the model from sending each button press multiple times.

You can now control the first LED on the mesh light device by pressing Button 1 on the mesh light switch development kit.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries: