Main Content

addTrafficSource

Add data traffic source to Bluetooth LE node

Since R2022a

    Download Required: To use addTrafficSource, first download the Communications Toolbox Wireless Network Simulation Library add-on. For more information, see Get and Manage Add-Ons.

    Description

    addTrafficSource(bluetoothLENodeObj,trafficSource) adds a data traffic source, trafficSource, to the Bluetooth® low energy (LE) node object bluetoothLENodeObj. The Role property of the bluetoothLENode object must be set to "isochronous-broadcaster" or "broadcaster".

    example

    addTrafficSource(bluetoothLENodeObj,trafficSource,DestinationNode=destinationNode) adds a data traffic source to send data to the specified destination node destinationNode. The Role property of bluetoothLENode object must be set to "central" or "peripheral".

    example

    addTrafficSource(bluetoothLENodeObj,trafficSource,DestinationNode=destinationNode,CISConfig=cisConfig) adds a data traffic source to send data to the connected isochronous stream (CIS) connection, cisConfig of the specified destination node destinationNode. The Role property of bluetoothLENode object must be set to "central" or "peripheral".

    addTrafficSource(bluetoothLENodeObj,trafficSource,DestinationAddress=destinationElementAddress,SourceAddress=sourceElementAddress,varargin) adds a data traffic source to send data from the specified element of the source mesh node sourceElementAddress to the specified element of the destination mesh node destinationElementAddress. The Role property of the bluetoothLENode object must be set to "broadcaster-observer". varargin specifies one or more name-value arguments of the upper layer metadata.

    addTrafficSource(bluetoothLENodeObj,trafficSource,DestinationAddress=destinationElementAddress,SourceAddress=sourceElementAddress,TTL=ttl) additionally specifies the time to live (TTL) for the data communication between the specified source and destination mesh nodes. The Role property of the bluetoothLENode object must be set to "broadcaster-observer".

    Note

    Reusing the same traffic source object in another addTrafficSource function call results in an error.

    Examples

    collapse all

    This example shows you how to simulate a Bluetooth® low energy (LE) network with a custom channel by using Bluetooth® Toolbox and Communications Toolbox™ Wireless Network Simulation Library.

    Using this example, you can:

    1. Create and configure a Bluetooth LE piconet with Central and Peripheral nodes.

    2. Create and configure a link layer (LL) connection between Central and Peripheral nodes.

    3. Add application traffic from the Central to Peripheral nodes.

    4. Create a custom channel, and plug it into the wireless network simulator.

    5. Simulate Bluetooth LE network and retrieve the statistics of the Central and Peripheral 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 LE node, specifying the role as "central". Specify the name and position of the node.

    centralNode = bluetoothLENode("central");
    centralNode.Name = "CentralNode";
    centralNode.Position = [0 0 0];                 % In x-, y-, and z-coordinates in meters

    Create a Bluetooth LE node, specifying the role as "peripheral". Specify the name and position of the node.

    peripheralNode = bluetoothLENode("peripheral");
    peripheralNode.Name = "PeripheralNode";
    peripheralNode.Position = [10 0 0]              % In x-, y-, and z-coordinates in meters
    peripheralNode = 
      bluetoothLENode with properties:
    
             TransmitterPower: 20
              TransmitterGain: 0
                ReceiverRange: 100
                 ReceiverGain: 0
          ReceiverSensitivity: -100
                  NoiseFigure: 0
         InterferenceModeling: "overlapping-adjacent-channel"
        MaxInterferenceOffset: 100000000
         InterferenceFidelity: 0
                         Name: "PeripheralNode"
                     Position: [10 0 0]
    
       Read-only properties:
                         Role: "peripheral"
             ConnectionConfig: [1x1 bluetoothLEConnectionConfig]
                    CISConfig: [1x1 bluetoothLECISConfig]
               TransmitBuffer: [1x1 struct]
                           ID: 2
    
    

    Add a random waypoint mobility model to the Bluetooth peripheral node. Set the shape of the node's mobility area to "circle".

    addMobility(peripheralNode,BoundaryShape="circle");

    Create a default Bluetooth LE configuration object to share the LL connection between the Central and Peripheral nodes.

    cfgConnection = bluetoothLEConnectionConfig;

    Specify the connection interval and connection offset. Throughout the simulation, the object establishes LL connection events for the duration of each connection interval. The connection offset is from the beginning of the connection interval.

    cfgConnection.ConnectionInterval = 0.01; % In seconds
    cfgConnection.ConnectionOffset = 0;      % In seconds

    Specify the active communication period after the connection event is established between the Central and Peripheral nodes.

    cfgConnection.ActivePeriod = 0.01 % In seconds
    cfgConnection = 
      bluetoothLEConnectionConfig with properties:
    
        ConnectionInterval: 0.0100
             AccessAddress: "5DA44270"
              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]
                 Algorithm: 1
              HopIncrement: 5
         CRCInitialization: "012345"
        SupervisionTimeout: 1
                   PHYMode: "LE1M"
             InstantOffset: 6
          ConnectionOffset: 0
              ActivePeriod: 0.0100
    
    

    Configure the connection between Central and Peripheral nodes by using the configureConnection object function of the bluetoothLEConnectionConfig object.

    configureConnection(cfgConnection,centralNode,peripheralNode);

    Create a networkTrafficOnOff object to generate an On-Off application traffic pattern. Specify the data rate in kb/s and the packet size in bytes. Enable packet generation to generate an application packet with a payload.

    traffic = networkTrafficOnOff(DataRate=100, ...
                                  PacketSize=10, ...
                                  GeneratePacket=true);

    Add application traffic from the Central to the Peripheral node by using the addTrafficSource object function.

    addTrafficSource(centralNode,traffic,"DestinationNode",peripheralNode.Name);

    Create a Bluetooth LE network consisting of a Central and a Peripheral node.

    nodes = {centralNode peripheralNode};

    Add the Central and Peripheral nodes to the wireless network simulator.

    addNodes(networkSimulator,nodes)

    Add the custom channel to the wireless network simulator.

    addChannelModel(networkSimulator,@addImpairment);

    Set the simulation time in seconds and run the simulation.

    simulationTime = 0.5;
    run(networkSimulator,simulationTime)

    Retrieve application, link layer (LL), and physical layer (PHY) statistics corresponding to the broadcaster and receiver nodes. For more information about the statistics, see Bluetooth LE Node Statistics.

    centralStats = statistics(centralNode)
    centralStats = struct with fields:
        Name: "CentralNode"
          ID: 1
         App: [1x1 struct]
          LL: [1x1 struct]
         PHY: [1x1 struct]
    
    
    peripheralStats = statistics(peripheralNode)
    peripheralStats = struct with fields:
        Name: "PeripheralNode"
          ID: 2
         App: [1x1 struct]
          LL: [1x1 struct]
         PHY: [1x1 struct]
    
    

    Follow these steps to create a custom channel that models Bluetooth path loss for an industrial scenario.

    • Create a custom function with this syntax: rxData = customFcnName(rxInfo,txData). The rxInfo input specifies the receiver node information as a structure, and the txData input specifies the transmitted packets as a structure. The simulator automatically passes information about the receiver node and the packets transmitted by a transmitter node as inputs to the custom function. For more information about creating custom channel, see the addChannelModel object function.

    • Use the bluetoothPathLossConfig object to set path loss configuration parameters for an industrial scenario.

    • Calculate path loss between the Central and Peripheral nodes using the bluetoothPathLoss function. Specify the transmitter and receiver positions.

    • Apply path loss to the transmitted packets.

    function rxData = addImpairment(rxInfo,txData)
    
        pathlossCfg = bluetoothPathLossConfig(Environment="Industrial");
    
        % Apply path loss and update output signal
        rxData = txData;
    
        % Calculate the distance between transmitter and receiver in meters
        distance = norm(rxData.TransmitterPosition - rxInfo.Position);
        pathloss = bluetoothPathLoss(distance,pathlossCfg);
        rxData.Power = rxData.Power-pathloss;                           % In dBm
        scale = 10.^(-pathloss/20);
        [numSamples,~] = size(rxData.Data);
        rxData.Data(1:numSamples,:) = rxData.Data(1:numSamples,:)*scale;
    end

    Input Arguments

    collapse all

    Bluetooth LE node object, specified as a bluetoothLENode object.

    On-Off application traffic pattern object, specified as a networkTrafficOnOff object. If you specify this input, the generatePacket property of the networkTrafficOnOff object is not applicable because the Bluetooth LE node will always generate the packets.

    When you add the application traffic to a Bluetooth LE node by using this object function, the bluetoothLENodeObj automatically calls the generate object function associated with the networkTrafficOnOff object to generate the corresponding application traffic packet.

    Name of the destination node, specified as a character vector, a string scalar, or a bluetoothLENode object. If you set the Role property of the bluetoothLENodeObj object to "central" or "peripheral", this input is mandatory. This value specifies the Name property of the specified Bluetooth LE node object bluetoothLENodeObj for sending data to the specified destination node.

    Data Types: char | string

    CIS connection configuration of destination node, specified as an object or an array of objects of the type bluetoothLECISConfig object.

    Destination address, specified as a 4-element character vector or string scalar denoting a 2-octet hexadecimal address. If you set the Role property of the bluetoothLENodeObj object to "broadcaster-observer", this input is mandatory. This value specifies the destination address of the Bluetooth mesh node.

    Data Types: char | string

    Source address, specified as a 4-element character vector or string scalar denoting a 2-octet hexadecimal address. If you set the Role property of the bluetoothLENodeObj object to "broadcaster-observer", this input is mandatory. This value specifies the element address of the Bluetooth mesh source node. The element address specifies the ElementAddress property of the specified Bluetooth mesh profile configuration object bluetoothMeshProfileConfig.

    Data Types: char | string

    Time to live for the message, specified as an integer in the range [0, 127], excluding 1. If you set the Role property of the bluetoothLENode object to "broadcaster-observer", this value is optional. If the value is not set, the function uses the default TTL property value 127 of the bluetoothMeshProfileConfig object. This value specifies the maximum number of hops that the transmitted message can traverse between the source and destination elements. For more information about the TTL value, see Bluetooth mesh profile v1.0.1, section 4.2.7.

    Data Types: double

    References

    [1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed November 12, 2021. https://www.bluetooth.com/.

    [2] Bluetooth Core Specifications Working Group. "Bluetooth Core Specification" v5.3. https://www.bluetooth.com/.

    Version History

    Introduced in R2022a