Main Content

Bluetooth Mesh Flooding in Wireless Sensor Networks

This example demonstrates network layer flooding in a Bluetooth® mesh network using Communication Toolbox Library™ for the Bluetooth® Protocol. Using this example, you can:

  • Create and configure a Bluetooth mesh network by positioning the nodes in a grid.

  • Specify your own network by configuring the node positions and the type of node position allocation.

  • Classify and configure the mesh nodes as source, destination, relay, and end nodes and observe how network layer flooding helps in communication between the source and destination even after disabling few intermediate relay nodes.

  • Visualize the flow of packets from source to destination.

The example also shows how to perform Monte Carlo simulations on the Bluetooth mesh network to obtain numerical results (like number of relay nodes required, critical relay nodes between the source and destination) averaged over multiple iterations.

Bluetooth Mesh Stack

The Bluetooth Core Specification [ 1 ] includes a Low Energy version for low-rate wireless personal area networks, referred to as Bluetooth low energy (BLE) or Bluetooth Smart. The BLE stack consists of generic attribute profile (GATT), attribute protocol (ATT), security manager protocol (SMP), logical link control and adaptation protocol (L2CAP), link layer (LL) and physical layer. BLE was added to the standard for low energy devices generating small amounts of data, such as notification alerts used in such applications as home automation, health-care, fitness, and Internet of things (IoT). For more information about BLE protocol stack, see Bluetooth Protocol Stack.

The Bluetooth mesh profile [ 2 ] defines the fundamental requirements to implement a mesh networking solution for BLE. The mesh stack is located on top of the BLE core specification and consists of model layer, foundation model layer, access layer, upper transport layer, lower transport layer, network layer and bearer layer. Bluetooth mesh networking enables large-scale device networks in the applications such as smart lighting, industrial automation, sensor networking, asset tracking, and many other IoT solutions. For more information about Bluetooth mesh stack, see Bluetooth Mesh Networking.

The Bluetooth mesh network layer performs these primary operations.

  • Transmit upper layer messages over the network using the bearer layer

  • Relay mesh messages

  • Implement managed flooding to optimize network flooding

  • Assign network addresses

  • Configure network layer security

For more information about these mesh network layer operations, see Bluetooth Mesh Networking.

This example uses the advertising bearer to demonstrate Bluetooth mesh flooding in a wireless sensor network.

The main objectives of this example are:

  1. Create and configure a Bluetooth mesh network

  2. Visualize message flooding

  3. Derive path between selected source and destination

  4. Display statistics (refer Network Layer Statistics at Each Node) at each node

Check for Support Package Installation

% Check if the 'Communications Toolbox Library for the Bluetooth Protocol'
% support package is installed or not.
commSupportPackageCheck('BLUETOOTH');

Create and Configure Bluetooth Mesh Network Scenarios

This example enables you to create and configure two Bluetooth mesh network scenarios. Each scenario is a 50-node network. The nodes in the network are classified as relays, source, destination, and end nodes. Specify the corresponding time to live (TTL) values of source and destination nodes. In the first scenario, the example identifies the paths between the source and destination nodes. You can visualize the message flow in the network with network layer statistics. In the second scenario, the example disables some relay nodes and end nodes. In this case, the simulations show that the network has the likelihood of establishing a path between the specified source and destination pair.

To create and visualize the mesh network, use helperBLEMeshNetworkNode and helperBLEMeshVisualizeNetwork functions. Specify number of nodes (totalNodes) and the type of node position (NodePositionType) in helperBLEMeshVisualizeNetwork function. The default type of node position is 'Grid'. To specify your own network, set the value of NodePositionType to 'UserInput' and node positions to Positions.

% Set random number generator seed to 'default'
sprev = rng('default');

% Specify the number of nodes in the mesh network
totalNodes = 50;

% Initialize 'bleMeshNodes' vector with objects of type
% helperBLEMeshNetworkNode
bleMeshNodes(1, totalNodes) = helperBLEMeshNetworkNode;

% Configure each mesh node with unique identifier
for idx = 1:totalNodes
    meshNode = helperBLEMeshNetworkNode;
    meshNode.Identifier = idx;
    meshNode.NetworkLayer.ElementAddresses = dec2hex(idx, 4);
    bleMeshNodes(idx) = meshNode;
end

% Load node positions from the MAT file
load('bleMeshNetworkNodePositions.mat');

% Number of scenarios simulated in this examples
numberOfScenarios = 2;

% Initialize 'meshNetworkPlots' vector with objects of type
% helperBLEMeshVisualizeNetwork
meshNetworkPlots(1, numberOfScenarios) = helperBLEMeshVisualizeNetwork;

for idx = 1:numberOfScenarios
    meshNetworkPlots(idx) = helperBLEMeshVisualizeNetwork;
    meshNetworkPlots(idx).NumberOfNodes = totalNodes;
    % Set the type of the node position allocation as 'Grid' or
    % 'UserInput'
    meshNetworkPlots(idx).NodePositionType = 'UserInput';

    % Set node positions based on number of nodes (applicable for
    % 'UserInput'), in meters
    meshNetworkPlots(idx).Positions = bleMeshNetworkNodePositions;

    % Set vicinity range based on node positions, in meters
    meshNetworkPlots(idx).VicinityRange = 25;

    % Set title to the network visualization
    meshNetworkPlots(idx).Title = ...
        ['Scenario ' num2str(idx) ': Bluetooth Mesh Flooding'];
end

Specify the number of source and destination pairs in the mesh network using srcDstPairs parameter. Specify the TTL values for the packet originated at each source node.

% Specify the simulation time in milliseconds
simulationTime = 600;

% Enable or disable visualization
enableVisualization = true;

% Specify the source and destination pairs
srcDstPairs = [1 7; 13 29];

% Specify TTL values for packet originated at each source node
ttl = [25; 25];

Simulations

To run the simulation and get the results, use helperBLEMeshFloodingSimulation and helperBLEMeshFloodingSimulationResults functions, respectively.

  • Scenario 1: In this scenario, all the fifty nodes in the network are active. Some of these nodes are selected as relays and there are no failed nodes in this scenario.

% Specify the relay nodes
relayNodeIDs = [3 4 5 8 10 11 15 19 20 21 23 25 28 30 32 34 36 37 38 39 41 ...
    42 43 44 45 46 47 48 49];

% Specify the failed nodes (nodes that are out of network)
failedNodeIDs = [];

This plot shows the corresponding paths between each source and destination pair. The scenarioOneResults workspace variable stores the results containing the obtained paths in scenario 1.

% Run the simulation with scenario 1 configuration
pathScenarioOne = helperBLEMeshFloodingSimulation(totalNodes, bleMeshNodes, meshNetworkPlots(1), ...
    simulationTime, srcDstPairs, ttl, relayNodeIDs, failedNodeIDs, ...
    enableVisualization);

% Display the results of the scenario 1
scenarioOneResults = helperBLEMeshFloodingSimulationResults(srcDstPairs, pathScenarioOne)
scenarioOneResults =

  2x4 table

    Source    Destination               Path                NumberOfHops
    ______    ___________    ___________________________    ____________

       1           7         {[1 46 19 4 39 41 48 23 7]}         8      
      13          29         {[     13 5 3 28 36 44 29]}         6      

  • Scenario 2: In this scenario, disable the relay feature of Node 41. Remove Node 3 and Node 43 from the network.

% Specify the relay nodes
relayNodeIDs = [4 5 8 10 11 15 19 20 21 23 25 28 30 32 34 36 37 38 39 42 ...
    44 45 46 47 48 49];

% Specify the failed nodes (nodes that are out of network)
failedNodeIDs = [3, 43];

This plot shows the corresponding paths between each source and destination pair. The scenarioTwoResults workspace variable stores the results containing the obtained paths in scenario 2.

% Run the simulation with scenario 2 configuration
pathScenarioTwo = helperBLEMeshFloodingSimulation(totalNodes, bleMeshNodes, meshNetworkPlots(2), ...
    simulationTime, srcDstPairs, ttl, relayNodeIDs, failedNodeIDs, ...
    enableVisualization);

% Display the results of the scenario 2
scenarioTwoResults = helperBLEMeshFloodingSimulationResults(srcDstPairs, pathScenarioTwo)
scenarioTwoResults =

  2x4 table

    Source    Destination                  Path                  NumberOfHops
    ______    ___________    ________________________________    ____________

       1           7         {[1 46 19 4 8 20 37 45 34 23 7]}         10     
      13          29         {[     13 30 45 34 28 36 44 29]}          7     

Network Layer Statistics

At each node, the example captures these network layer statistics.

  • Number of messages transmitted by the node

  • Number of messages received by the node

  • Number of application messages received

  • Number of messages relayed by the node

  • Number of messages dropped at the node

The statisticsAtEachNode workspace variable contains cumulative network statistics of all the nodes in scenario 1 and scenario 2. For a specific simulation run, you can see the network statistics for only first five nodes. These are the network statistics for first five nodes in the network.

statisticsAtEachNode = helperBLEMeshFloodingSimulationResults(bleMeshNodes);
statisticsForFirstFiveNodes = statisticsAtEachNode(1:min(5, totalNodes), :)
statisticsForFirstFiveNodes =

  5x6 table

    NodeID    TotalTxMsgs    TotalRxMsgs    TotalAppRxMsgs    TotalRelayedMsgs    TotalDroppedMsgs
    ______    ___________    ___________    ______________    ________________    ________________

      1            2              4               0                  0                   4        
      2            0              8               0                  0                   8        
      3            0              5               0                  2                   3        
      4            0             10               0                  4                   6        
      5            0              9               0                  4                   5        

Further Exploration

To obtain numerical results averaged over multiple simulations, the example implements the Monte Carlo method [ 3 ]. To analyze the probability of message delivery from the source node to the destination node after enabling or disabling the relay nodes in the mesh network, use helperBLEMeshMonteCarloSimulations script. Each simulation run follows these steps.

  1. Uses a new seed to generate a random number.

  2. Randomly disables the relay nodes until only one path exist between the source and destination nodes.

  3. Stores the path.

The Monte Carlo simulations outputs these statistics.

  • Probability of a message delivery from source to destination when relay nodes are randomly disabled in the network

  • Average hop count between the source and destination nodes

  • Critical relays required to ensure packet delivery from the source to destination

The example performs Monte Carlo simulations by using these configuration parameters.

% Source and destination nodes
srcDstPair = [16 12];

% TTL value for the message originated at the above source node
ttl = 25;

% Relay nodes
relayNodeIDs = [21 15 25 11 38 19 46 8 39 20 37 32 30 5 45 49 43 3 28 36 47 ...
    34 23 48 41 44 42 10 4];

% Failed nodes (nodes that are out of network)
failedNodeIDs = [];

The example performs 10,000 simulations by using the above configuration. To view the simulation results, see bleMeshMonteCarloResults.mat MAT file.

load('bleMeshMonteCarloResults.mat');
disp(['Probability of having a path between nodes Node ' num2str(srcDstPair(1)) ...
    ' and Node ' num2str(srcDstPair(2)) ' is ' ...
    num2str(probabilityOfSuccess) '%.']);
disp(['Average hop count between nodes Node ' num2str(srcDstPair(1)) ' and Node ' ...
    num2str(srcDstPair(2)) ' is ' ...
    num2str(averageHopCount) '.']);
disp(['Critical relay nodes required to derive a path between Node ' num2str(srcDstPair(1)) ...
    ' and Node ' num2str(srcDstPair(2)) ' are [' num2str(criticalRelaysInfo{1:5, 1}') ...
    '].']);
% Restore the previous setting of random number generation
rng(sprev);
Probability of having a path between nodes Node 16 and Node 12 is 88.6428%.
Average hop count between nodes Node 16 and Node 12 is 8.
Critical relay nodes required to derive a path between Node 16 and Node 12 are [39  37   8  38   4].

To perform Monte Carlo simulations for custom configuration parameters, modify and run the helperBLEMeshMonteCarloSimulations script.

This example enables you to create and configure a multinode Bluetooth mesh network and analyze the network layer flooding. To study the flooding behavior, the example considers two simulation scenarios. In the first scenario, the path between source and destination nodes is identified and visualized by selecting some intermediate nodes as relay nodes. In the second scenario, some nodes (Relay and End) are dropped, and the relay feature for some of the relay nodes is disabled. The obtained results show that there exists a path between the source and destination nodes even if nodes (Relay and End) fail randomly in the network.

This example enables you to create your own Bluetooth mesh network and visualize mesh flooding and network statistics. To obtain numerical results averaged over multiple iterations, you can perform Monte Carlo simulations on the Bluetooth mesh network.

Appendix

The example uses these helpers:

Selected Bibliography

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

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

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

Related Topics