Main Content

Bluetooth Mesh Flooding in Wireless Sensor Networks

This example shows you how the managed flooding technique enables you to realize communication in a Bluetooth mesh network by using Bluetooth® Toolbox. 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.

The example also shows you how to perform Monte Carlo simulations on the Bluetooth mesh network to identify critical relay nodes between the source and destination.

Bluetooth Mesh Stack

The Bluetooth Core Specification [ 2 ] includes a Low Energy version for wireless personal area networks, 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

Configure Simulation Parameters

Specify the number of nodes (numNodes) along with their positions and simulation time for both the scenarios. 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.

% Set random number generator as "twister"

% Specify the simulation time for both scenarios in seconds
simulationTime = 0.3;

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


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.

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

Create Bluetooth Mesh Nodes

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.

% Initialize array to store Bluetooth mesh nodes
nodesScenarioOne = cell(1,numNodes);
clear wirelessNode; % Clear context of wirelessNode

% Create Bluetooth mesh network for scenario one
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);

    % For the configured relayNodes, enable Relay feature. 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).
    meshNode = bluetoothLENode("broadcaster-observer",MeshConfig=meshCfg,...
        Position=[bleMeshNetworkNodePositions(nodeIndex,:) 0],Name="Node"+num2str(nodeIndex),...

    % Store mesh nodes
    nodesScenarioOne{nodeIndex} = meshNode;

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. Simulate mesh communication between specified source and destination pairs in the mesh network.

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

    % You can control the maximum number of hops that the source node uses to
    % relay message by setting the 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. Assign the helper object to the NetworkPlot parameter in the helperBLEMeshEventCallback helper object.

% Object to visualize mesh network
plotScenarioOne = helperBLEMeshVisualizeNetwork(NumberOfNodes=numNodes,...
    Title="Scenario 1: Bluetooth Mesh Flooding");

% Object to handle visualization callbacks
visualizeScenarioOne = helperBLEMeshEventCallback(NetworkPlot=plotScenarioOne,...

Visualize the path and message flow between the source and destination nodes by adding listeners. For more information, see eventlisteners.

for nodeIndex = 1:numNodes
    % Add listener at each node for visualizing the message flow in the network
    if highlightTransmissions
            @(src,evt) visualizeScenarioOne.visualizeTransmissions(src,evt));  
    % Add listener at each node for storing the message receptions in the network
    addlistener(nodesScenarioOne{nodeIndex},"PacketReceptionEnded", ...
        @(src,evt) visualizeScenarioOne.storeRx(src,evt));

% Add listener at destination nodes for visualizing the path between
% source and destination
for dstIdx = 1:numel(sourceDestinationPairs)/2
        @(src,evt) visualizeScenarioOne.showPath(src,evt));

Run the simulation

Initialize the wireless network.

networkSimulator = helperWirelessNetwork(nodesScenarioOne);

Run all the nodes in the network for the specified simulation time.


Update simulation progress at the end of the simulation.


Figure Scenario 1: Bluetooth Mesh Flooding contains an axes object. The axes object with title Scenario 1: Bluetooth Mesh Flooding contains 4 objects of type graphplot, line. These objects represent Scenario 1: Bluetooth Mesh Flooding, \color[rgb]{0 0.5 1} Node, \color[rgb]{1 0.4980 0.4980} Relay node, \color[rgb]{0 0.5 0} Source-Destination pair (1, 10).

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];
failedNode = 15;

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

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

Figure Scenario 2: Bluetooth Mesh Flooding contains an axes object. The axes object with title Scenario 2: Bluetooth Mesh Flooding contains 5 objects of type graphplot, line. These objects represent Scenario 2: Bluetooth Mesh Flooding, \color[rgb]{0 0.5 1} Node, \color[rgb]{1 0.4980 0.4980} Relay node, \color[rgb]{0.6, 0.6, 0.6} Failed node, \color[rgb]{0 0.5 0} Source-Destination pair (1, 10).

Simulation Results

View the table of statistics for both the scenarios by using the helperBLEMeshStatistics helper function.

statisticsScenarioOne = helperBLEMeshStatistics(nodesScenarioOne);
statisticsScenarioTwo = helperBLEMeshStatistics(nodesScenarioTwo);

Calculate PDR and path for both scenarios.

[pdrScenarioOne,pathScenarioOne] = meshResults(visualizeScenarioOne,statisticsScenarioOne)
pdrScenarioOne = 1
pathScenarioOne=1×4 table
    Source    Destination          Path          NumberOfHops
    ______    ___________    ________________    ____________

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

[pdrScenarioTwo,pathScenarioTwo] = meshResults(visualizeScenarioTwo,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 helperBLEMeshMonteCarloSimulations helper function. Each simulation run performs 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

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 November 25, 2021.

  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