Main Content

Create, Configure and Simulate Bluetooth Mesh Network

This example shows you how to simulate a Bluetooth mesh network by using Bluetooth® Toolbox.

Using this example, you can:

  1. Create and configure a Bluetooth mesh network.

  2. Enable or disable relay feature of the mesh node.

  3. Add application traffic between the source and destination nodes.

  4. Simulate Bluetooth mesh network and retrieve the statistics of mesh nodes.

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

Simulate the Bluetooth LE mesh network by using the helperWirelessNetwork helper object. This helper object uses these object functions.

  • runNode: Run the Bluetooth LE nodes.

  • pushChannelData and channelInvokeDecision: Apply the channel impairments to the transmitted packet and distributes the impaired packet to the receiving buffers of the nodes that intends receive the packet.

networkSimulator = helperWirelessNetwork(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: 'Node3'
          App: [1x1 struct]
    Transport: [1x1 struct]
      Network: [1x1 struct]
           LL: [1x1 struct]
          PHY: [1x1 struct]

relayStats = statistics(relayNode)
relayStats = struct with fields:
         Name: 'Node4'
          App: [1x1 struct]
    Transport: [1x1 struct]
      Network: [1x1 struct]
           LL: [1x1 struct]
          PHY: [1x1 struct]

destinationStats = statistics(destinationNode)
destinationStats = struct with fields:
         Name: 'Node5'
          App: [1x1 struct]
    Transport: [1x1 struct]
      Network: [1x1 struct]
           LL: [1x1 struct]
          PHY: [1x1 struct]

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