Main Content

Bluetooth Mesh Flooding in Wireless Sensor Networks

This example shows how the managed flooding technique enables you to realize communication in a Bluetooth® mesh network by using Bluetooth® Toolbox and Communications Toolbox™ Wireless Network Simulation Library. Using this example, you can:

  • Create and configure a Bluetooth mesh network.

  • Visualize and analyze how managed flooding technique enables communication between the source and destination nodes, even after disabling some intermediate relay nodes.

  • Visualize the message flow from the source to destination nodes.

  • Analyze performance metrics such as network packet delivery ratio (PDR), end-to-end latency, throughput, and other node-related metrics.

You can also identify critical relay nodes between the source and destination in the Bluetooth mesh network through Monte Carlo simulations.

Bluetooth Mesh Stack

The Bluetooth Core Specification [ 2 ] includes a Low Energy version for wireless personal area networks (WPAN), referred to as Bluetooth Low Energy (LE) or Bluetooth Smart. Bluetooth LE was added to the standard for low energy devices generating small amounts of data, such as notification alerts used in applications such as home automation, health-care, fitness, and Internet of things (IoT). For more information about Bluetooth LE protocol stack, see Bluetooth Protocol Stack.

The Bluetooth Mesh Profile [ 3 ] defines the fundamental requirements to implement a mesh networking solution for Bluetooth LE. Bluetooth mesh networking enables large-scale device networks in the applications such as smart lighting, industrial automation, sensor networking, and asset tracking.

This figure shows the Bluetooth mesh stack over the advertising bearer.

For more information about Bluetooth Mesh Profile, see Bluetooth Mesh Networking.

Bluetooth Mesh Network Flooding Scenarios

This example uses the advertising bearer to demonstrate managed flooding. This example enables you to create and configure two Bluetooth mesh network scenarios. Each scenario is a multinode mesh network. Each scenario classifies the mesh nodes as node, relay node, source node, and destination node.

  • Node: Any device in the mesh network

  • Relay node: A node that has the relay feature supported and enabled

  • Source node: A node that originates and transmits packets

  • Destination node: A node at which the packets from the source node are destined

The first mesh network scenario consists of 21 mesh nodes, including relay nodes, a source node, and a destination node. In the second scenario, the example:

  • Disables the relay feature of some nodes

  • Removes a node from the mesh network

For both the scenarios, you can visualize the message flow in the network and retrieve these statistics.

  • Network PDR: Ratio of number of packets received at all the destination nodes to the number of packets transmitted by all the source nodes in the mesh network

  • Application end-to-end packet latency in seconds

  • Link layer (LL) throughput in Kbps

  • Time spent in listen state, transmit state, idle state and sleep state in seconds

  • Packet statistics at the application layer, network layer, transport layer, link layer and physical layer

Check for Support Package Installation

Check if the Communications Toolbox™ Wireless Network Simulation Library support package is installed. If the support package is not installed, MATLAB® returns an error with a link to download and install the support package.


Configure Simulation Parameters

Set the seed for the random number generator to 1. The seed value controls the pattern of random number generation. For high fidelity simulation results, change the seed value for each run and average the results over multiple simulations.


Specify the simulation time for both scenarios.

simulationTime = 0.3; % In seconds

To highlight message transmission in the mesh network visualization, set this flag to True.

highlightTransmissions = true;

Number of nodes in the mesh network.

numNodes = 21;

Get the node positions from the MAT file. Specify the positions of Bluetooth mesh nodes as a numNodes-by-2 array, where numNodes is the number of nodes in the network. Each row specifies the Cartesian coordinates of a node, starting from the first node.

if numNodes ~= size(bleMeshNetworkNodePositions,1)
    error("Invalid Bluetooth mesh node position value. Specify 'bleMeshNetworkNodePositions' value in the MAT file as a "...
        +num2str(numNodes)+"-by-2 array.");

Simulate Mesh Network Scenario One

The first mesh network scenario consists of 21 mesh nodes. Set some of the nodes as relay nodes and source-destination node pairs. To specify multiple source-destination pairs, update sourceDestinationPairs by adding a new row specifying the source and destination nodes.

relayNodes = [3 6 7 8 9 12 13 14 15 17];
sourceDestinationPairs = [1 10];

Create a wireless network simulator object.

networkSimulator = wirelessNetworkSimulator.init;

Create and Configure Bluetooth Mesh Nodes

Initialize array to store Bluetooth mesh nodes.

nodesScenarioOne = bluetoothLENode.empty(0,numNodes);

Create Bluetooth mesh network for scenario one. Use bluetoothMeshProfileConfig to create mesh profile configuration object. To create a Bluetooth mesh node, use the bluetoothLENode object. Specify the role as "broadcaster-observer" and assign the mesh profile to MeshConfig.

for nodeIndex = 1:numNodes
    % Create and configure Bluetooth mesh profile by specifying the element
    % address (unique to each node in the network). Set network message
    % repetitions to 2, and network transmit interval as a random value in
    % the range [10, 30] milliseconds.
    meshCfg = bluetoothMeshProfileConfig(ElementAddress=dec2hex(nodeIndex,4),...
        NetworkTransmissions=2,NetworkTransmitInterval=randi([1 3])*10e-3);

    % Enable relay feature of the configured relay nodes. Set relay message
    % repetitions to 3, and relay retransmit interval as a random value in
    % the range [10, 30] milliseconds.
    if any(nodeIndex==relayNodes)
        meshCfg.Relay = true;
        meshCfg.RelayRetransmissions = 3;
        meshCfg.RelayRetransmitInterval = randi([1 3])*10e-3;

    % Create and configure Bluetooth mesh node by assigning the mesh profile.
    % Set receiver range, advertising interval (seconds) and scan interval (seconds).
    nodesScenarioOne(nodeIndex) = bluetoothLENode("broadcaster-observer",MeshConfig=meshCfg,...
        Position=[bleMeshNetworkNodePositions(nodeIndex,:) 0],Name="Node"+num2str(nodeIndex),...

Add Application Traffic to Source Nodes

Create a networkTrafficOnOff object to generate an On-Off application traffic pattern. Configure the On-Off application traffic pattern by specifying the application data rate, packet size, on, and off state duration. Use addTrafficSource object function to attach the application traffic source between the specified source-destination node pairs.

for srcIdx = 1:numel(sourceDestinationPairs)/2
    % Set data rate, packet size, on time, and off time based on the
    % simulation time.
    traffic = networkTrafficOnOff(DataRate=1,PacketSize=15,GeneratePacket=true,...

    % Maximum number of hops for a packet is controlled by setting
    % time-to-live (TTL) value
    ttl = 10;

    % Attach application traffic to source
    addTrafficSource(nodesScenarioOne(sourceDestinationPairs(srcIdx,1)),traffic, ...                        % Traffic object
        SourceAddress=nodesScenarioOne(sourceDestinationPairs(srcIdx,1)).MeshConfig.ElementAddress,...      % Source element address
        DestinationAddress=nodesScenarioOne(sourceDestinationPairs(srcIdx,2)).MeshConfig.ElementAddress,... % Destination element address

Visualize Mesh Network

Visualize the mesh network scenario by using the helperBLEMeshVisualizeNetwork helper object.

plotScenarioOne = helperBLEMeshVisualizeNetwork(NumberOfNodes=numNodes,...
    Title="Scenario one: Bluetooth Mesh Flooding");

Assign the helper object to the NetworkPlot parameter in the helperBLEMeshEventCallback helper object.

eventsScenarioOne = helperBLEMeshEventCallback(nodesScenarioOne,plotScenarioOne,...

Run the simulation

Add nodes to the wireless network simulator.


Run the network simulation for the specified simulation time.


Simulate Mesh Network Scenario Two

The second mesh network scenario consists of 21 mesh nodes. In this scenario, the relay feature at Node7, Node12 is disabled and Node15 is removed from the network.

relayNodes = [3 6 8 9 13 14 17];
failedNodes = 15;

Create, configure, and simulate the mesh network for scenario two by using the helperBLEMeshSimulateScenarioTwo helper object.

[nodesScenarioTwo,eventsScenarioTwo] = helperBLEMeshSimulateScenarioTwo(bleMeshNetworkNodePositions,...

Simulation Results

Use statistics object function to get the statistics of mesh nodes for both scenarios.

% List of statistics (structure array) of the simulated mesh nodes in scenario one
for nodeIndex = 1:numel(nodesScenarioOne)
    statisticsScenarioOne(nodeIndex) = statistics(nodesScenarioOne(nodeIndex)); %#ok<*SAGROW>
% List of statistics (structure array) of the simulated mesh nodes in scenario two
for nodeIndex = 1:numel(nodesScenarioTwo)
    statisticsScenarioTwo(nodeIndex) = statistics(nodesScenarioTwo(nodeIndex));

Calculate PDR and path for both scenarios.

[pdrScenarioOne,pathScenarioOne] = meshResults(eventsScenarioOne,statisticsScenarioOne)

pdrScenarioOne = 1
pathScenarioOne=1×4 table
    Source    Destination          Path          NumberOfHops
    ______    ___________    ________________    ____________

      1           10         {[1 6 7 8 9 10]}         5      

[pdrScenarioTwo,pathScenarioTwo] = meshResults(eventsScenarioTwo,statisticsScenarioTwo)

pdrScenarioTwo = 1
pathScenarioTwo=1×4 table
    Source    Destination            Path            NumberOfHops
    ______    ___________    ____________________    ____________

      1           10         {[1 6 13 14 8 9 10]}         6      

The obtained results show that there exists a path between the source and destination nodes even if nodes fail randomly in the network.

Further Exploration

To obtain numerical results averaged over multiple simulations, the example implements the Monte Carlo method [ 4 ]. To implement Monte Carlo simulations, use the helperBLEMeshMonteCarloSimulations helper function. During each simulation run, perform these steps.

  1. Use a new seed to generate a random number

  2. Randomly disable the relay nodes until a path exist between the source and destination nodes

  3. Store the PDR value

The Monte Carlo simulations outputs critical relay nodes required to ensure message delivery from the source to destination. The example performs Monte Carlo simulations by using these configuration parameters.

% Relay nodes
relayNodes = [3 6 7 8 9 12 13 14 15 17];

% Source and destination pair
sourceDestinationPairs = [1 10];

% TTL value for messages originated from the source
ttl = 10;

To view the simulation results, see bleMeshMonteCarloResults MAT file.

disp("Further exploration: Nodes [" + num2str(criticalRelaysInfo{1:5,1}') + ...
    "] are the top 5 critical relays for having communication between Node1 and Node10.");
Further exploration: Nodes [9   6   7   8  14] are the top 5 critical relays for having communication between Node1 and Node10.


The example uses these helpers:

Selected Bibliography

  1. Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed May 24, 2022.

  2. Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.3.

  3. Bluetooth Special Interest Group (SIG). "Bluetooth Mesh Profile." Version 1.0.1

  4. Metropolis, Nicholas, and S. Ulam. "The Monte Carlo Method." Journal of the American Statistical Association 44, no. 247 (September 1949): 335–41.

See Also



Related Topics