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

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.

rng(1,"twister");

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.

load("bleMeshNetworkNodePositions.mat");
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.");
end

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];

Initialize the wireless network simulator by using the wirelessNetworkSimulator object function of the wirelessNetworkSimulator 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;
    end

    % 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),...
        ReceiverRange=25,AdvertisingInterval=20e-3,ScanInterval=30e-3);
end

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,...
        OnTime=simulationTime*0.3,OffTime=simulationTime*0.7);

    % 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
        TTL=ttl);
end

Visualize Mesh Network

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

plotScenarioOne = helperBLEMeshVisualizeNetwork(NumberOfNodes=numNodes,...
    NodePositionType="UserInput",Positions=bleMeshNetworkNodePositions,...
    ReceiverRange=25,SimulationTime=simulationTime,...
    SourceDestinationPairs=sourceDestinationPairs,...
    Title="Scenario one: Bluetooth Mesh Flooding");

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

eventsScenarioOne = helperBLEMeshEventCallback(nodesScenarioOne,plotScenarioOne,...
    HighlightTransmissions=highlightTransmissions);

Run the simulation

Add nodes to the wireless network simulator.

addNodes(networkSimulator,nodesScenarioOne);

Run the network simulation for the specified simulation time.

run(networkSimulator,simulationTime);
Custom channel model is not added. Using free space path loss (fspl) model as the default channel model.

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,...
    simulationTime,highlightTransmissions,sourceDestinationPairs,ttl,relayNodes,failedNodes);
Custom channel model is not added. Using free space path loss (fspl) model as the default channel model.

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>
end
% List of statistics (structure array) of the simulated mesh nodes in scenario two
for nodeIndex = 1:numel(nodesScenarioTwo)
    statisticsScenarioTwo(nodeIndex) = statistics(nodesScenarioTwo(nodeIndex));
end

Calculate PDR and path for both scenarios.

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

Figure Scenario one: Bluetooth Mesh Flooding contains an axes object. The axes object with title Scenario one: Bluetooth Mesh Flooding contains 4 objects of type graphplot, line. These objects represent Scenario one: 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).

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

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

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

Figure Scenario two: Bluetooth Mesh Flooding contains an axes object. The axes object with title Scenario two: Bluetooth Mesh Flooding contains 5 objects of type graphplot, line. These objects represent Scenario two: 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).

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.

load("bleMeshMonteCarloResults.mat");
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.

Appendix

The example uses these helpers:

Selected Bibliography

  1. Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed May 24, 2022. https://www.bluetooth.com.

  2. Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.3. https://www.bluetooth.com/.

  3. Bluetooth Special Interest Group (SIG). "Bluetooth Mesh Profile." Version 1.0.1 https://www.bluetooth.com/.

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

See Also

Functions

Objects

Related Topics