Main Content

Simulate Periodic Advertisements in Bluetooth LE Network

Since R2024a

This example shows how to create, configure, and simulate periodic advertisements in a Bluetooth® low energy (LE) network.

Using this example, you can:

  • Create and configure a Bluetooth LE network consisting of multiple Broadcasters and an Observer.

  • Establish periodic advertising trains (PATs) between the Broadcaster nodes and Observer node.

  • Add On-Off application traffic between the Broadcaster nodes and Observer node.

  • Simulate the scenario and visualize the packet communication and state transitions of the Broadcaster nodes and Observer node over time.

Additionally, this example script enables you to observe the variation in packet delivery ratio (PDR) between legacy advertising and periodic advertising as the number of Broadcasters in the network increases. For more information, see Further Exploration.

Periodic Advertisements Simulation Scenario

Periodic advertising facilitates synchronization between the Observer and the Broadcaster, enabling them to wake up simultaneously. After waking up, the Broadcaster transmits the advertisement packet, and the Observer switches on the receiver to capture the packet. To support the periodic advertisement functionality, the Bluetooth Core Specification 5.3 [2] introduces the LE periodic advertising feature. For more information about periodic advertising, see Section 4.4.2.12, Vol 6, Part B of the Bluetooth Core Specification. The example simulates a scenario in which multiple Broadcaster nodes transmits information to a central Observer node using PATs, as shown in this figure.

Broadcaster nodes communicating with Observer node using periodic advertising trains

Consider a Bluetooth sensor collection data system in an industrial plant. In this system, numerous sensors have been strategically placed throughout the plant, functioning as the Broadcasters. These sensors sense and relay data about the system to a central monitoring node, acting as the Observer. The Observer collects and processes the data. In this example, the Observer synchronizes with the PAT of 12 Broadcasters. Each Broadcaster transmits an advertisement packet to the Observer, then enters a sleep mode until the end of the periodic advertising interval. After this interval, the Broadcaster resumes transmission with the next advertisement packet, continuing this cycle. The Observer uses periodic advertising events to listen to all the advertisement packets from the Broadcasters, thereby ensuring both reliability and energy efficiency within the monitoring system.

Check for Support Package Installation

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 and Configure Bluetooth LE Piconet

To ensure repeatability of results, set the seed for the random number generator to 1. To improve the accuracy of your simulation results after running the simulation, you can change the seed value, run the simulation again, and average the results over multiple simulations.

rng(1,"twister")

Create a wireless network simulator object.

networkSimulator = wirelessNetworkSimulator.init;

Specify the simulation time in seconds.

simulationTime = 20;

Create a Bluetooth LE node, specifying the role as "observer".

observer = bluetoothLENode("observer",Name="Observer");

Specify the total number of Broadcaster nodes.

numBroadcasters = 12;

Specify the positions for the Broadcaster and Observer nodes in a star topology. In this topology, set the position of the Observer at the coordinates (0, 0), and place the Broadcasters evenly around the center of the Observer.

radius = 5;                                % Radius of the star, in meters
angles = linspace(0,2*pi,numBroadcasters); % Create evenly spaced angles (in radians) for the Broadcaster nodes
xPos = radius*cos(angles);                 % Calculate x positions based on the angles and radius
yPos = radius*sin(angles);                 % Calculate y positions based on the angles and radius
nodePos = [xPos(:) yPos(:)];

Create Bluetooth LE Broadcaster nodes with the role specified as "broadcaster", and assign them to the node positions.

broadcasters = bluetoothLENode.empty(0,numBroadcasters);
for broadcasterCount = 1:numBroadcasters
    broadcasters(broadcasterCount) = bluetoothLENode("broadcaster",Name="Broadcaster"+num2str(broadcasterCount),Position=[nodePos(broadcasterCount,:) 0]);
end

Create a Bluetooth LE periodic advertisements configuration object, specifying the periodic advertising interval.

periodicAdvInterval = 1;                                                       % In seconds
cfgPA = bluetoothLEPeriodicAdvConfig(PeriodicAdvInterval=periodicAdvInterval);

Configure PATs between the Observer node and Broadcaster nodes.

configurePeriodicAdv(cfgPA,broadcasters,observer);

Create a Bluetooth LE network consisting of the Observer node and Broadcaster nodes.

nodes = [broadcasters observer];

Add Application Traffic

Create a networkTrafficOnOff object to generate an On-Off application traffic pattern. Configure the On-Off application traffic pattern at the Broadcaster by specifying the application data rate, packet size, and On state duration. Add application traffic to all the Broadcasters by using the addTrafficSource object function.

Configure traffic for each Broadcaster node to send a packet to the Observer node every second throughout the simulation. In the traffic object, the time between packet generation is calculated as 0.2 seconds for a packet of size 25 bytes with a 1 Kbps rate (packet size in bits divided by the data rate in bits per second). With a simulation duration of 20 seconds, setting the OnTime as 0 to 4 seconds will generate 20 packets throughout the entire simulation.

for broadcasterCount = 1:numBroadcasters
    traffic = networkTrafficOnOff(DataRate=1,PacketSize=25,GeneratePacket=true,OnTime=4,OffTime=16.2);
    addTrafficSource(broadcasters(broadcasterCount),traffic)
end

Visualize State Transitions and Packet Communication

To visualize packet communication in the Bluetooth LE network, set enablePacketVisualization to true. The visualization shows the packet communication and state transitions of Bluetooth LE nodes over time. At the end of the simulation, you can visualize packets at any time instance.

enablePacketVisualization = true;

Initialize visualization by using the helperPlotPacketTransitions helper object.

if enablePacketVisualization
    helperPlotPacketTransitions(nodes,simulationTime,FrequencyPlotFlag=false);
end

Add your nodes to the wireless network simulator.

addNodes(networkSimulator,nodes)

Simulation and Results

Run the simulation for the specified time and generate these results.

  • A runtime plot for all the nodes showing the state transitions and packet transmissions over time.

  • The PDR of the network.

  • Application layer (APP), link layer (LL), and physical layer (PHY) statistics for all the simulated nodes.

run(networkSimulator,simulationTime)

Figure Packet Communication Over Time contains an axes object and another object of type uigridlayout. The axes object with title State Transitions of Nodes, xlabel Time (seconds), ylabel Node Names contains 3 objects of type patch, constantline.

Retrieve the statistics of all the nodes. For more information about Bluetooth LE node statistics, see Bluetooth LE Node Statistics.

nodeStats = arrayfun(@(x) x.statistics,nodes);

Calculate the PDR of the network at the Observer by using the kpi object function. The PDR is the ratio of application packets received by the Observer to the total number of application packets transmitted by all the Broadcasters in the network.

pdr = mean(kpi(broadcasters,observer,"PDR",Layer="App"))
pdr = 
1

Further Exploration

You can use this example script to observe how the PDR of legacy and periodic advertisements varies as a function of the total number of Broadcasters in the network.

PDR of Legacy and Periodic Advertisements

To simulate the impact of the number of Broadcasters in the network on the PDR performance of legacy and periodic advertisements, perform these steps:

  1. For legacy advertisements, set the AdvertisingInterval and ScanInterval properties of the bluetoothLENode object to 1 second.

  2. For periodic advertisements, set the PeriodicAdvInterval property of the bluetoothLEPeriodicAdvConfig object to 1 second.

  3. For legacy and periodic advertisements at all the Broadcasters, configure the DataRate, PacketSize, OnTime, and OffTime properties of the networkTrafficOnOff object to 1 Kbps, 25 bytes, 0.2 seconds, and 0.8 seconds, respectively.

  4. Use default values for all other configuration parameters.

With this configuration, the simulation runs for legacy and periodic advertisements for 10 seconds. The number of Broadcasters in the network is set to 2, 4, 8, 16, 32, 64, and 128. The resulting plot illustrates the impact of varying the number of Broadcasters on the PDR of the network for legacy and periodic advertisements.

ExampleImage.JPG

The reliable and energy-efficient transmission mechanism of the periodic advertisements results in a PDR performance that surpasses that of legacy advertisements. In the case of legacy advertisements, the PDR decreases as the number of Broadcasters increases due to its unreliable randomized transmission and reception mechanism. Conversely, for periodic advertisements, the number of Broadcasters has no impact on the PDR.

Appendix

The example uses this helper function.

References

  1. Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed October 20, 2023. https://www.bluetooth.com/

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