Main Content

Create, Configure, and Visualize Bluetooth Mesh Network

Using this example, you can:

  1. Create a Bluetooth® mesh network by configuring the nodes as source, destination, and relay.

  2. Create and configure Bluetooth mesh profile.

  3. Add On-Off application traffic between the mesh nodes.

  4. Visualize Bluetooth mesh network.

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.

wirelessnetworkSupportPackageCheck;

Specify the total number of Bluetooth LE mesh nodes and their respective positions in the network. This example creates a 6-node Bluetooth mesh network consisting of a relay node, an end node, and two source-destination pairs. For more information about the functionalities of these nodes, see Bluetooth Mesh Networking.

totalNodes = 6;
meshNodesPositions = [15 25; 15 5; 30 15; 45 5; 45 25; 30 30];  % In meters

Specify the relay node and source-destination node pairs. In this example, Node1 and Node2 are source nodes and the corresponding destination nodes are Node4 and Node5.

relayNode = 3;
sourceDestinationNodePairs = [1 4; 2 5];

Set the Bluetooth mesh profile configuration parameters. Create Bluetooth mesh nodes with "broadcaster-observer" role.

meshNodes = cell(1,totalNodes);
for nodeIdx = 1:totalNodes
    meshCfg = bluetoothMeshProfileConfig(ElementAddress=dec2hex(nodeIdx,4));
    if any(nodeIdx,relayNode)
        meshCfg.Relay = true;
    end
    meshNode = bluetoothLENode("broadcaster-observer", MeshConfig=meshCfg, ...
        Position=[meshNodesPositions(nodeIdx,:) 0],ReceiverRange=25, ...
        AdvertisingInterval=20e-3, ScanInterval=30e-3);
    meshNodes{nodeIdx} = meshNode;
end

Add traffic between Node1 - Node4 and Node2 - Node5 source-destination node pairs by using the networkTrafficOnOff object. The networkTrafficOnOff object enables you to create an On-Off application traffic pattern.

% Add traffic between Node1 and Node4
traffic = networkTrafficOnOff(DataRate=1,PacketSize=15,GeneratePacket=true);
addTrafficSource(meshNodes{1},traffic, ...
    SourceAddress=meshNodes{1}.MeshConfig.ElementAddress, ...
    DestinationAddress=meshNodes{4}.MeshConfig.ElementAddress, ...
    TTL=3);

% Add traffic between Node2 and Node5
traffic = networkTrafficOnOff(DataRate=1,PacketSize=10,GeneratePacket=true);
addTrafficSource(meshNodes{2},traffic, ...
    SourceAddress=meshNodes{2}.MeshConfig.ElementAddress, ...
    DestinationAddress=meshNodes{5}.MeshConfig.ElementAddress, ...
    TTL=3);

Visualize the Bluetooth mesh network by using the helperBLEMeshVisualizeNetwork helper function. This helper function displays the created Bluetooth mesh network.

meshNetworkGraph = helperBLEMeshVisualizeNetwork();                     % Object for Bluetooth mesh network visualization                
meshNetworkGraph.NumberOfNodes = totalNodes;                            % Total number of mesh nodes
meshNetworkGraph.NodePositionType = 'UserInput';                        % Option to assign node position             
meshNetworkGraph.Positions = meshNodesPositions;                        % List of all node positions
meshNetworkGraph.ReceiverRange = 25;                                    % Reception range of mesh node
meshNetworkGraph.Title = 'Bluetooth Mesh Network';                      % Title of plot
meshNetworkGraph.SourceDestinationPairs = sourceDestinationNodePairs;   % Source-destination node pair
meshNetworkGraph.NodeType = [1 1 2 1 1 1];                              % State of mesh node
meshNetworkGraph.DisplayProgressBar = false;                            % Display progress bar
meshNetworkGraph.createNetwork();                                       % Display mesh network

Figure Bluetooth Mesh Network contains an axes object. The axes object with title Bluetooth Mesh Network, xlabel X-position (meters), ylabel Y-position (meters) contains 29 objects of type line, scatter, text. One or more of the lines displays its values using only markers These objects represent Node, Relay node, Source-Destination pair (1, 4), Source-Destination pair (2, 5).

References

[1] Bluetooth® Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed December 25, 2021. 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] Bluetooth Special Interest Group (SIG). "Bluetooth Mesh Model Specification." Version 1.0.1. https://www.bluetooth.com/.

Related Topics