Bluetooth: Mesh light switch

The Bluetooth mesh light switch sample can be used to change the state of light sources on other devices within the same mesh network. It also demonstrates how to use Bluetooth mesh models by using the Generic OnOff Client model in an application.

Use the light switch sample with the Bluetooth: Mesh light sample to demonstrate its function in a Bluetooth mesh network.


The sample supports the following development kits:

Hardware platforms


Board name

Build target

nRF5340 DK





nRF52840 DK




nRF52 DK




nRF52833 DK




You need at least two development kits:

  • One development kit where you program this sample application (the client)

  • One (or more) development kit(s) where you program the Bluetooth: Mesh light sample application (the server(s)), and configure according to the mesh light sample’s testing guide

For provisioning and configuring of the mesh model instances, the sample requires a smartphone with Nordic Semiconductor’s nRF Mesh mobile app installed in one of the following versions:


The Bluetooth mesh light switch sample demonstrates how to set up a mesh client model application, and control LEDs with the Bluetooth mesh using the Generic OnOff models. To display any functionality, the sample must be paired with a device with the Bluetooth: Mesh light sample running in the same mesh network.

In both samples, 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 to enable them to communicate with the servers.

The Generic OnOff Client model is used for manipulating the Generic OnOff state associated with the Generic OnOff Server model. The light switch sample implements the Generic OnOff Client model.

The sample has four buttons to control the state of LED 1 on servers (implemented by the Bluetooth: Mesh light sample). Four instances of the Generic OnOff Client model are instantiated in the light switch sample, one for each button on the development kit that is used. When a user presses any of the buttons, an OnOff Set message is sent out to the configured destination address.

After provisioning and configuring the mesh models supported by the sample using the nRF Mesh mobile app, you can control the LEDs on the other (server) development kit(s) from the app.


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.


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.

User interface


During the provisioning process, the buttons (1 to 4) can be used for OOB input. Once the provisioning and configuration are completed, the buttons are used to initiate certain actions and control the respective Generic OnOff Client instances. When pressed, the button publishes an OnOff message using the configured publication parameters of its model instance, and toggles the LED state on a mesh light device.


During the provisioning process, the LEDs (1 to 4) are used to output the OOB actions. Once the provisioning and configuration are completed, the LEDs are used to reflect the status of actions, and they show the last known OnOff state of the corresponding button.


See Configuring your application for information about how to permanently or temporarily change the configuration.

Source file setup

The light switch sample is split into the following source files:

  • A main.c file to handle initialization.

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

Building and running

Make sure to enable the Bluetooth mesh in nRF Connect SDK before building and testing this sample. See Bluetooth mesh user guide for more information.

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.



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 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.

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.

Once the provisioning and the configuration of the client node and at least one of the server nodes are complete, you can use buttons on the client development kit. The buttons will control the LED lights on the associated servers, as described in User interface.


This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries: