Create, Configure and Simulate Bluetooth Mesh Network
This example shows you how to simulate 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.
Enable or disable relay feature of the mesh node.
Add application traffic between the source and destination nodes.
Simulate Bluetooth mesh network and retrieve the statistics and key performance indicators (KPIs) of mesh nodes.
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;
Create a wireless network simulator.
networkSimulator = wirelessNetworkSimulator.init;
Create a Bluetooth mesh profile configuration object, specifying the element address of the source node.
cfgMeshSource = bluetoothMeshProfileConfig(ElementAddress="0001")
cfgMeshSource = bluetoothMeshProfileConfig with properties: ElementAddress: "0001" Relay: 0 Friend: 0 LowPower: 0 NetworkTransmissions: 1 NetworkTransmitInterval: 0.0100 TTL: 127
Create a Bluetooth LE node, specifying the role as "broadcaster-observer"
. Specify the position of the source node. Assign the mesh profile configuration to the source node.
sourceNode = bluetoothLENode("broadcaster-observer");
sourceNode.Position = [0 0 0];
sourceNode.MeshConfig = cfgMeshSource;
Create a Bluetooth mesh profile configuration object, specifying the element address and enabling the relay feature of the Bluetooth LE node.
cfgMeshRelay = bluetoothMeshProfileConfig(ElementAddress="0002",Relay=true)
cfgMeshRelay = bluetoothMeshProfileConfig with properties: ElementAddress: "0002" Relay: 1 Friend: 0 LowPower: 0 NetworkTransmissions: 1 NetworkTransmitInterval: 0.0100 TTL: 127 RelayRetransmissions: 1 RelayRetransmitInterval: 0.0100
Create a Bluetooth LE node, specifying the role as "broadcaster-observer"
. Specify the position of the relay node. Assign the mesh profile configuration to the relay node.
relayNode = bluetoothLENode("broadcaster-observer");
relayNode.Position = [25 0 0];
relayNode.MeshConfig = cfgMeshRelay;
Create a Bluetooth mesh profile configuration object, specifying the element address of the Bluetooth LE node.
cfgMeshDestination = bluetoothMeshProfileConfig(ElementAddress="0003")
cfgMeshDestination = bluetoothMeshProfileConfig with properties: ElementAddress: "0003" Relay: 0 Friend: 0 LowPower: 0 NetworkTransmissions: 1 NetworkTransmitInterval: 0.0100 TTL: 127
Create a Bluetooth LE node, specifying the role as "broadcaster-observer"
. Specify the position of the destination node. Assign the mesh profile configuration to the destination node.
destinationNode = bluetoothLENode("broadcaster-observer");
destinationNode.Position = [50 0 0];
destinationNode.MeshConfig = cfgMeshDestination;
Create a networkTrafficOnOff
object to generate an On-Off application traffic pattern. Specify the on time, data rate in kb/s, and packet size in bytes. Generate an application packet with a payload by enabling packet generation.
traffic = networkTrafficOnOff(OnTime=inf, ... DataRate=1, ... PacketSize=15, ... GeneratePacket=true);
Add application traffic between the source and destination nodes.
addTrafficSource(sourceNode,traffic, ... SourceAddress=cfgMeshSource.ElementAddress, ... DestinationAddress=cfgMeshDestination.ElementAddress,TTL=10);
Create a Bluetooth mesh network consisting of the source node, relay node, and destination node.
nodes = {sourceNode relayNode destinationNode};
Add the mesh nodes to the wireless network simulator.
addNodes(networkSimulator,nodes)
Set the simulation time and run the simulation.
simulationTime = 1; % In seconds
run(networkSimulator,simulationTime);
Retrieve application, link layer (LL) , and physical layer (PHY) statistics related to the source, relay, and destination nodes by using the statistics
object function. For more information about the statistics, see Bluetooth LE Node Statistics.
sourceStats = statistics(sourceNode)
sourceStats = struct with fields:
Name: "Node1"
ID: 1
App: [1x1 struct]
Transport: [1x1 struct]
Network: [1x1 struct]
LL: [1x1 struct]
PHY: [1x1 struct]
relayStats = statistics(relayNode)
relayStats = struct with fields:
Name: "Node2"
ID: 2
App: [1x1 struct]
Transport: [1x1 struct]
Network: [1x1 struct]
LL: [1x1 struct]
PHY: [1x1 struct]
destinationStats = statistics(destinationNode)
destinationStats = struct with fields:
Name: "Node3"
ID: 3
App: [1x1 struct]
Transport: [1x1 struct]
Network: [1x1 struct]
LL: [1x1 struct]
PHY: [1x1 struct]
Retrieve application layer (APP) KPIs such as latency, packet loss ratio (PLR), and packet delivery ratio (PDR) for the connection between the source and destination node.
kpi(sourceNode,destinationNode,"latency",Layer="App")
ans = 0.0177
kpi(sourceNode,destinationNode,"PLR",Layer="App")
ans = 0.6667
kpi(sourceNode,destinationNode,"PDR",Layer="App")
ans = 0.3333
References
[1] Bluetooth® Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed November 22, 2021. https://www.bluetooth.com/.
[2] Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.3. https://www.bluetooth.com/.
See Also
Functions
Objects
Related Topics
- Create, Configure, and Simulate Bluetooth LE Network With Custom Channel
- Create, Configure, and Simulate Bluetooth LE Broadcast Audio Network
- Create and Visualize Bluetooth LE Broadcast Audio Residential Scenario
- Establish Friendship Between Friend Node and LPN in Bluetooth Mesh Network
- Bluetooth LE Node Statistics
- Energy Profiling of Bluetooth Mesh Nodes in Wireless Sensor Networks
- Bluetooth Mesh Flooding in Wireless Sensor Networks