The Ultimate Bluetooth Mesh Tutorial (Part 7)

Last Updated on

In today’s tutorial:

  • We’ll first take a step back and talk a little bit about interoperability and compatibility in Bluetooth mesh.
  • Then, we’ll go through a demo of setting up a mesh network that includes a mix of off-the-shelf devices.
  • Finally, we’ll go through the source code step-by-step and the changes needed to implement the functionality for this demo.

Compatibility and Interoperability

The power of having a standard like Bluetooth mesh that a certified device must comply to is:

  • The ability to add devices from different manufacturers to any mesh network.
  • The ability within the network for devices to interact with others that implement a common functionality in an almost seamless manner.

This gives both manufacturers and consumers great flexibility in three main aspects:

  • Choosing the types of devices to be used within a mesh network, including the software applications that may be implemented on devices like tablets and mobile phones that interact with the network (e.g. Provisioner devices).
  • Freedom for the manufacturers to provide a wide variety of devices that provide different functionalities.
  • Flexibility for the end-user in configuring the network to their preference.

The concept of models, which we discussed in Part 2 of this tutorial series (found here), in addition to group addresses help in providing this flexibility.

Consumer Bluetooth Mesh Devices

I’ve been searching the market for devices, specifically light bulbs, that are Bluetooth mesh certified. I came across the following public list of mesh-certified devices, but 99% of the products listed are modules or chipsets.

It was a struggle finding a real consumer product that anyone can buy and use right away. This is understandable (I guess) since the standard is so new.

I saw the listing for LEDVANCE, which turns out is the company behind the Sylvania brand. I reached out to them Twitter, and they were able to point me in the right direction. Finally, I landed on the Sylvania SMART+ light bulbs. I bought a few of them to start building a Bluetooth mesh network in my home, but to also see how easy/hard it would be to create a network from multiple devices from different companies.

A Bluetooth Mesh Lighting Network in the Home

Compatibility and interoperability between certified devices is key to the success of any connectivity standard. My experience so far with this aspect of Bluetooth mesh has been great.

Following is a diagram of a simple Bluetooth mesh network I started building. I have since expanded the number of devices within the network and will be testing it more extensively, especially for reliability and range.

Figure 1: Bluetooth mesh lighting network

The network consists of the following:

  • An iOS or Android provisioner device running a generic Bluetooth mesh provisioner application (such as the Nordic’s nRF Mesh app or Silicon Labs’ Bluetooth Mesh app).
  • Two off-the-shelf Bluetooth mesh-certified light bulbs from Sylvania:
  • A Nordic nRF52840 Development Kit (DK) as a light switch. The light switch implementation will be an adapted version of the example provided by Nordic in the nRF5 SDK for Mesh (which we tested in Part 5), but with some added functionality:
    • Button #1: Turn on F1. Also turns on LED #1 on the development kit.
    • Button #2: Turn on C1. Also turns on LED #2 on the development kit.
    • Button #3: Turn on both F1 and C1 (as a group). Also turn on LEDs #1 and #2 on the development kit.
    • Button #4: Turn off both F1 and C1 (as a group). Also turn off LEDs #1 and #2 on the development kit.
Node Addresses

Figure 2: Node address assignments

nRF52-based Mesh Light Switch (Remote Control)

Make sure you follow the installation and setup steps in Part 5 first.

The original LightSwitch application provided in the nRF Bluetooth mesh examples only supports two Generic OnOff clients. In our example, we need to implement three clients:

  • One Generic OnOff client for controlling F1.
  • One Generic OnOff client for controlling C1.
  • One Generic OnOff client for controlling the group (F1 + C1).

Let’s go through the source code changes to accomplish this.

Step 1: Change the number of clients (from 2 to 3)

The number of clients is defined in the header file nrf5_SDK_for_Mesh_v2.2.0_src/examples/light_switch/include/light_switch_example_common.h .

Change it to 3 (instead of 2):

Step 2: Change the behavior of the development kit onboard buttons and LEDs

All the changes we need to make are in the function static void button_event_handler(uint32_t button_number).

  • Change the state set by the button presses to be on for buttons 1,2, and 3. Off for button 4.
  • Modify to have button 2 send a message as client #2 (indexed at 1). Also, make the change to turn on LED 2 (indexed at 1).
  • Modify to have buttons 3 and 4 to send a message as client #3 (indexed at 2). Also, make the change to set the state of both LEDs 1 & 2 (indexed at 0 & 1 respectively).

Provisioning and Network Setup Walkthrough

Let’s go through the different steps for provisioning the nodes and setting up the network from scratch.

Step 1: Make sure all devices are reset and unprovisioned

  • For the nRF52 development board, you can do this by navigating to the Target menu in SES, then choosing Connect J-Link, then Erase All. Once you’ve erased the development board (which may take a minute or two), you can now flash it with the updated Light Switch Proxy Client example that we modified in the previous section.
  • For the Sylvania light bulbs, you can do this by turning off power and then back on 5 times in a row. The last (5th) time you turn the light on, you should see a brief delay (up to 3 secs) after which the light will flash a few times indicating it is now reset.

Step 2: Use the nRF Mesh iOS or Android app to search for devices to provision them

  • Launch the nRF Mesh app and go to the Scanner tab

    Figure 3: Searching for devices (all devices unprovisioned)

Step 3: Provision the different devices

  • Click on each device and Identify it:

    Figure 4: Identify the device

    Figure 5: Identifying the device

  • Provision the device:

    Figure 6: Provision the device

    Figure 7: Provisioning process in progress

  •  You should now see the following screen after provisioning the nRF52 board:

    Figure 8: nRF52 dev kit provisioned

     

  • Repeat the process for each of the light bulbs. In the end, you should see the following:

    Figure 9: All devices provisioned

Step 4: Configure the Clients and Servers

Now that we have all the devices provisioned, we need to configure the different clients and servers.

  • First, configure the light switch (nRF52x Mesh Switch). Click on the device in the Network view:

    Figure 10: nRF5x Mesh Switch main view

  • We will configure the Generic OnOff Clients as follows:
    • Element 1:

      Figure 11: Generic OnOff Client #1

    • Element 2:

      Figure 12: Generic OnOff Client #2

    • Element 3:

      Figure 13: Generic OnOff Client #3

    • Once you’ve finished, you should see the following in the main view of the nRF5x Mesh Switch Node:

      Figure 14: nRF5x Mesh Switch Configured

  • We’ll configure the Generic OnOff Servers as follows:
    • Configure the SYLVANIA A19 F-M as follows:

      Figure 15: Sylvania Filament light bulb Generic OnOff Server configuration

    • Configure the SYLVANIA A19 C-M as follows:

      Figure 16: Sylvania Full-Color light bulb Generic OnOff Server configuration

Step 5: Test the Bluetooth Mesh Network

Now we’re ready to start the actual test of the networking. Here’s a video showing the testing:

Full Video Tutorial for Provisioning, Configuring, and Testing

If you’d like to follow the steps for provisioning, configuration, and testing through a video, you can do so here:

Summary

In the following posts, we’ll do some extensive testing with the Bluetooth mesh network:

  • Adding more lights and other mesh devices.
  • Testing with network range and how adding devices and removing them affects the range.

Don’t forget to enter your email below to stay up-to-date on the latest BLE news as well as be notified when new blog posts and tutorials get published.


2 Comments

  1. Cliff Brake on November 5, 2018 at 3:38 pm

    Great information — nice to learn there is actually a BT mesh bulb on the market now!

    Will be interesting to see how the range testing goes.

  2. Roe on November 14, 2018 at 3:31 am

    Hi. I am trying to build a mesh network using the nRF52840. Your tutorials have made all the complex stuff seem a little easier. I am struggling with setting up my mesh and just sending packets/pings between the routers. I need the mesh to enable multihopping especially in buildings with obstructions. I would also like to collect and analyze latency during the ‘pinging’. How can i do that?

Leave a Comment