registerEventCallback
Description
registerEventCallback(
registers a function callback bluetoothLENodeObj,eventName,callback)callback for the specified event
eventName from the Bluetooth® low energy (LE) node bluetoothLENodeObj.
Examples
Set the seed for the random number generator to ensure repeatability of results. The seed value controls the pattern of random number generation. For high-fidelity simulation results, change the seed value and average the results over multiple simulations.
rng(1,"twister")Create a wireless network simulator object. Specify the simulation time, in seconds.
networkSimulator = wirelessNetworkSimulator.init(); simulationTime = 0.01;
Create a Bluetooth LE Central node and a Peripheral node, specifying their positions in 3-D Cartesian coordinates.
centralNode = bluetoothLENode("central",Position=[1 1 1]); peripheralNode = bluetoothLENode("peripheral",Position=[2 2 2]);
Create a Bluetooth LE configuration object to share a connection between the Central and Peripheral nodes. Specify the LL connection interval and active communication period, in seconds, and the maximum number of octets that a data PDU can carry.
cfgConnection = bluetoothLEConnectionConfig(ConnectionInterval=0.1,ActivePeriod=0.1,MaxPDU=32);
Configure the LL connection between the Bluetooth LE Central and Peripheral nodes.
configureConnection(cfgConnection,centralNode,peripheralNode)
ans =
bluetoothLEConnectionConfig with properties:
ConnectionInterval: 0.1000
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.1000
MaxPDU: 32
TIFS: 1.5000e-04
TMCES: 1.5000e-04
Create an On-Off application traffic pattern generator object, specifying the On and Off state durations in seconds, the packet length in bytes, and the packet generation rate in Kbps. Add the application traffic source from the Central node to the Peripheral node.
c2pTraffic = networkTrafficOnOff(DataRate=256,PacketSize=32,OnTime=inf,OffTime=0); addTrafficSource(centralNode,c2pTraffic,DestinationNode=peripheralNode);
Create an On-Off application traffic pattern generator object, specifying the On and Off state durations in seconds, the packet length in bytes, and the packet generation rate in Kbps. Add the application traffic source from the Peripheral node to the Central node.
p2cTraffic = networkTrafficOnOff(DataRate=256,PacketSize=32,OnTime=inf,OffTime=0)
p2cTraffic =
networkTrafficOnOff with properties:
OnTime: Inf
OffTime: 0
DataRate: 256
PacketSize: 32
ApplicationData: [1500×1 double]
addTrafficSource(peripheralNode,p2cTraffic,DestinationNode=centralNode);
Add the Central node and Peripheral node to the wireless network simulator.
nodes = [centralNode peripheralNode]; addNodes(networkSimulator,nodes)
Register callbacks for events from the Central and Peripheral nodes.
registerEventCallback(centralNode,"TransmissionStarted",@(eventStruct) disp(eventStruct)) registerEventCallback(peripheralNode,"ReceptionEnded",@(eventStruct) disp(eventStruct)) registerEventCallback(centralNode,"AppPacketGenerated",@(eventStruct) disp(eventStruct)) registerEventCallback(peripheralNode,"AppPacketReceived",@(eventStruct) disp(eventStruct))
Run the simulation for the specified time.
run(networkSimulator,simulationTime)
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0
TechnologyType: 3
EventData: [1×1 struct]
EventName: "TransmissionStarted"
NodeName: "Node1"
NodeID: 1
Timestamp: 0
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketReceived"
NodeName: "Node2"
NodeID: 2
Timestamp: 3.3700e-04
TechnologyType: 3
EventData: [1×1 struct]
EventName: "ReceptionEnded"
NodeName: "Node2"
NodeID: 2
Timestamp: 3.3700e-04
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 1.0000e-03
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0020
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0030
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0040
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0050
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0060
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0070
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0080
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0090
TechnologyType: 3
EventData: [1×1 struct]
EventName: "AppPacketGenerated"
NodeName: "Node1"
NodeID: 1
Timestamp: 0.0100
TechnologyType: 3
EventData: [1×1 struct]
Retrieve APP, LL, and PHY statistics corresponding to the Central and Peripheral nodes.
statsCentral = statistics(centralNode)
statsCentral = struct with fields:
Name: "Node1"
ID: 1
App: [1×1 struct]
LL: [1×1 struct]
PHY: [1×1 struct]
statsPeripheral = statistics(peripheralNode)
statsPeripheral = struct with fields:
Name: "Node2"
ID: 2
App: [1×1 struct]
LL: [1×1 struct]
PHY: [1×1 struct]
Input Arguments
Bluetooth LE node object, specified as a bluetoothLENode object or a vector of bluetoothLENode
objects.
Name of the event, specified as a string scalar, character vector, vector of strings, or cell array of character vectors. Each element of the argument must be one of these values:
TransmissionStartedReceptionEndedAppPacketGeneratedAppPacketReceivedChangingState
For more information about these events, see Events and Corresponding Event Notification Data Substructure.
Data Types: string | char | cell
Callback function to run when the Bluetooth LE node notifies occurrence of an event, specified as a scalar function handle. The callback function must use this syntax.
@(eventStruct) callback(eventStruct)
eventStruct with the
notification data as a mandatory argument to the callback function. The structure
contains these fields.
| Field | Value | Description |
|---|---|---|
| String scalar | Name of the event. |
| String scalar | Name of the node. |
| Double scalar | Node identifier. |
| Double scalar | Time at which the event is notified, in seconds. |
| Double scalar Valid values are:
| Type of technology. |
| Structure | Event notification data. For more information about this structure, see Events and Corresponding Event Notification Data Substructure. |
Note
Register a callback function for an event from bluetoothLENode only once. If you register the same callback function
multiple times for the same event, the callback function executes repeatedly each
time the node notifies the event.
More About
This object function defines these events.
TransmissionStartedThe link layer (LL) triggers this event, notifying the node of the start of packet transmission. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU | Row vector of decimal octets | PDU bits to be transmitted from the LL in the current transmission |
Length | Double scalar | Number of octets sent from the LL to the physical layer (PHY) |
Duration | Double scalar | Over the air transmission time, in seconds (nanoseconds precision), including PHY overhead |
TransmitPower | Double scalar | Power of the current transmission, in dBm |
TransmitCenterFrequency | Double scalar | Center frequency of the current transmission, in Hz |
TransmitBandwidth | Double scalar | Bandwidth of the current transmission, in Hz |
CenterFrequency | Double scalar | Frequency of operation of the PHY, in Hz |
Bandwidth | Double scalar | Bandwidth of operation of the PHY, in Hz |
LogicalTransport | Valid values are:
| Bluetooth logical transport of the packet transmission |
Role | Valid values are | Role of the Bluetooth LE node that is transmitting packets |
PHYMode | Valid values are | PHY transmission mode |
AccessAddress | String scalar representing a 4-octet hexadecimal number | Access address of the Bluetooth LE packet |
ReceptionEndedThe LL triggers this event, notifying the node of the end of packet reception. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PDU | Row vector of decimal octets | PDU bits received from the LL in the current transmission |
Length | Double scalar | Number of octets sent from the PHY to eh LL |
Duration | Double scalar | Duration of the current reception, in seconds (nanoseconds precision) |
ReceiveCenterFrequency | Double scalar | Center frequency of the current reception, in Hz |
ReceiveBandwidth | Double scalar | Bandwidth of the current reception, in Hz |
CenterFrequency | Double scalar | Frequency of operation of the PHY, in Hz |
Bandwidth | Double scalar | Bandwidth of operation of the PHY, in Hz |
PHYDecodeStatus | Nonnegative integer, where | Decoding status of the current reception at the PHY |
PDUDecodeStatus | Nonnegative integer, where If the PHY
does not transmit a payload to the LL, the value of this field is
| Decoding status of the signal received at the LL |
SINR | Double scalar | Signal-to-interference plus noise ratio, in dB, of the current reception |
TransmitterNodeID | Double scalar | Identifier of the node that transmitted the signal of interest (SOI) in the current reception |
LogicalTransport | Valid values are:
| Bluetooth logical transport of the packet transmission |
Role | Valid values are | Role of the Bluetooth LE node that is transmitting packets |
PHYMode | Valid values are | PHY transmission mode |
AccessAddress | String scalar representing a 4-octet hexadecimal number | Access address of the Bluetooth LE packet |
RSSI | Double scalar | Strength of the received SOI, in dBm |
AppPacketGeneratedThe application layer (APP) triggers this event, notifying the start of the packet generation. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
Packet | Vector of decimal octets | Application packet, in bytes |
PacketLength | Double scalar | Number of bytes in the application packet |
DestinationNodeID | Double scalar | Identifier of the destination node |
Note
If you generate packets using full-buffer traffic, the node does not notify the occurrence of this event.
AppPacketReceivedThe APP triggers this event, notifying start of the packet reception. In response, the node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
Packet | Vector of decimal octets | Application packet, in bytes |
PacketLength | Double scalar | Number of bytes in the application packet |
SourceNodeID | Double scalar | Identifier of the source node |
Note
The node does not notify the occurrence of this event when it receives packets generated using full-buffer traffic.
ChangingStateThe LL triggers this event to notify a change in its state. The node passes this structure as event data to the registered callback.
| Field | Value | Description |
|---|---|---|
PreviousState | Valid values are | State from which the LL transitioned |
NextState | Valid values are | State to which the LL transitioned |
PreviousStateDuration | Double scalar | Duration, in seconds, that the LL remains in its previous state before transitioning |
CenterFrequency | Double scalar | Frequency of operation of a device or link, in Hz |
Bandwidth | Double scalar | Bandwidth of operation of a device or a link, in Hz |
References
[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed January 10, 2026. 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 R2026a
See Also
Objects
bluetoothLENode|bluetoothLEConnectionConfig|wirelessNetworkSimulator(Wireless Network Toolbox)
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)