addTrafficSource
Description
This feature also requires the Wireless Network Toolbox™ product.
addTrafficSource(
adds a data traffic source object, bluetoothBRNodeObj,trafficSource,DestinationNode=destinationNode)trafficSource, to the specified
Bluetooth® basic rate/enhanced data rate (BR/EDR) node for sending data to the specified
connected destination node destinationNode.
Note
Each time you call this object function, you add a traffic generator (traffic source) to a Bluetooth BR/EDR node. You can add multiple traffic sources to a node, directing them to the same or different destination nodes.
Examples
Initialize the wireless network simulator.
networkSimulator = wirelessNetworkSimulator.init;
Create two Bluetooth BR nodes, one with the "central" role and the other with the "peripheral" role. Specify the position of the Peripheral node, in meters.
centralNode = bluetoothNode("central"); peripheralNode = bluetoothNode("peripheral",Position=[1 0 1]);
Add a random waypoint mobility model to the peripheral node. Set the shape of the node's mobility area to "circle".
addMobility(peripheralNode,BoundaryShape="circle",RefreshInterval=0.1)Create a default Bluetooth BR/EDR connection configuration object to configure and share a connection between the Bluetooth BR Central and Peripheral nodes.
cfgConnection = bluetoothConnectionConfig;
Configure the connection between the Central and the Peripheral nodes.
connection = configureConnection(cfgConnection,centralNode,peripheralNode)
connection =
bluetoothConnectionConfig with properties:
CentralToPeripheralACLPacketType: "DH1"
PeripheralToCentralACLPacketType: "DH1"
SCOPacketType: "None"
HoppingSequenceType: "Connection adaptive"
UsedChannels: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 … ] (1×79 double)
PollInterval: 40
InstantOffset: 240
TransmitterPower: 20
SupervisionTimeout: 32000
CentralAddress: "D091BBE70001"
PrimaryLTAddress: 1
Create and configure a networkTrafficOnOff (Wireless Network Toolbox) object to generate an On-Off application traffic pattern.
traffic = networkTrafficOnOff(DataRate=200,PacketSize=27,OnTime=inf);
Add application traffic from the Central to the Peripheral node.
addTrafficSource(centralNode,traffic,DestinationNode=peripheralNode);
Add the Central and Peripheral nodes to the wireless network simulator.
addNodes(networkSimulator,[centralNode peripheralNode]);
Specify the simulation time, in seconds.
simulationTime = 0.3;
Run the simulation for the specified simulation time.
run(networkSimulator,simulationTime);
Retrieve the application, baseband, and physical layer (PHY) statistics corresponding to the Central and Peripheral nodes.
centralStats = statistics(centralNode)
centralStats = struct with fields:
Name: "Node1"
ID: 1
App: [1×1 struct]
Baseband: [1×1 struct]
PHY: [1×1 struct]
peripheralStats = statistics(peripheralNode)
peripheralStats = struct with fields:
Name: "Node2"
ID: 2
App: [1×1 struct]
Baseband: [1×1 struct]
PHY: [1×1 struct]
Create a wireless network simulator.
networkSimulator = wirelessNetworkSimulator.init;
Create three Bluetooth BR/EDR nodes, one with the "central" role and the other two with the "peripheral" role. Specify the positions of the nodes in meters.
central = bluetoothNode("central",Position=[0 0 1]); peripheral = bluetoothNode("peripheral",Position=[1 0 0; 1 1 0]);
Create a default Bluetooth BR/EDR connection configuration object to configure and share a connection between the Central and Peripheral nodes.
cfgConnection = bluetoothConnectionConfig;
Configure the connection between the Central and the Peripheral nodes.
configureConnection(bluetoothConnectionConfig,central,peripheral);
Create an On-Off application traffic pattern generator object, specifying the length (in bytes) of the packet to be generated.
trafficSource = networkTrafficOnOff(PacketSize=10);
Add application traffic from the source node central to the destination nodes peripheral.
addTrafficSource(central,trafficSource,DestinationNode=peripheral)
Create a Bluetooth LE piconet consisting of one Central and two Peripheral nodes.
nodes = {central peripheral(1) peripheral(2)};Add all the nodes to the wireless network simulator.
addNodes(networkSimulator,nodes)
Specify the simulation time in seconds, and run the simulation.
simulationTime = 1; run(networkSimulator,simulationTime)
Retrieve application, LL, and PHY statistics for each of the Central and Peripheral nodes.
centralStats = statistics(central)
centralStats = struct with fields:
Name: "Node1"
ID: 1
App: [1×1 struct]
Baseband: [1×1 struct]
PHY: [1×1 struct]
peripheralStats1 = statistics(peripheral(1))
peripheralStats1 = struct with fields:
Name: "Node2"
ID: 2
App: [1×1 struct]
Baseband: [1×1 struct]
PHY: [1×1 struct]
peripheralStats2 = statistics(peripheral(2))
peripheralStats2 = struct with fields:
Name: "Node3"
ID: 3
App: [1×1 struct]
Baseband: [1×1 struct]
PHY: [1×1 struct]
Input Arguments
Bluetooth BR/EDR node object, specified as a bluetoothNode object or a vector of bluetoothNode
objects.
On-Off application traffic pattern class, specified as a networkTrafficOnOff (Wireless Network Toolbox) object or an object of a subclass of the wnet.Traffic (Wireless Network Toolbox)
class. To add an On-Off application traffic pattern, configure the
networkTrafficOnOff object of the wnet.traffic class.
The object function uses this input to transport data traffic over the asynchronous
connection-oriented logical (ACL) link of the connection. If you specify this input, the
generatePacket property of the
networkTrafficOnOff object is not applicable because the Bluetooth
BR/EDR node will always generate the packets.
When you add the application traffic to a Bluetooth BR/EDR node by using this object
function, the bluetoothBRNodeObj input automatically calls the generate (Wireless Network Toolbox)
object function associated with the trafficSource object during the
simulation runtime to generate the corresponding application traffic packet.
Destination node of traffic, specified as a bluetoothNode object or a vector of bluetoothNode objects.
Specify this input based on the bluetoothBRNodeObj value under these conditions.
If the
bluetoothBRNodeObjinput is abluetoothNodeobject, specify this value as abluetoothNodeobject or a vector ofbluetoothNodeobjects. In this case, the source node specified by thebluetoothBRNodeObjobject attaches a copy of the object specified to thetrafficSourceargument to the destination nodes specified by this value.If the
bluetoothBRNodeObjinput is a vector ofbluetoothNodeobjects, specify this value as abluetoothNodeobject. In this case, each source node specified by thebluetoothBRNodeObjobject attaches a copy of the object specified by thetrafficSourceargument to the destination node specified by this value.
Data Types: char | string
References
[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed December 22, 2025. https://www.bluetooth.com/.
[2] Bluetooth Core Specifications Working Group. "Bluetooth Core Specification" v6.1. https://www.bluetooth.com/specifications/specs/core-specification-6-1/.
Version History
Introduced in R2022bStarting in R2026a, this feature is available in Bluetooth Toolbox and also requires a Wireless Network Toolbox license. In prior releases, the feature is available through the Communications Toolbox™ Wireless Network Simulation Library add-on.
The addTrafficSource object function now enables you to add a
traffic source from a single source node to multiple destination nodes and from multiple
source nodes to a single destination node in a single function call.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)