创建,配置和模拟蓝牙Mesh网络
此示例向您展示如何使用Bluetooth®工具箱模拟Bluetooth®网状网络。
使用这个例子,你可以:
创建并配置蓝牙网状网络。
启用/禁用mesh节点中继特性。
在源节点和目的节点之间添加应用程序流量。
模拟蓝牙mesh网络,检索mesh节点统计信息。
创建一个无线网络模拟器。
networkSimulator = wirelessNetworkSimulator.init();
创建一个蓝牙网格概要文件配置对象,指定源节点的元素地址。
cfgMeshSource = bluetoothMeshProfileConfig(ElementAddress=“0001”)
cfgMeshSource = bluetoothMeshProfileConfig with properties: ElementAddress: "0001" Relay: 0 Friend: 0 LowPower: 0 networktransmission: 1 NetworkTransmitInterval: 0.0100 TTL: 127
创建蓝牙LE节点,指定角色为“broadcaster-observer”
.指定源节点的位置。将网格概要文件配置分配给源节点。
sourceNode = bluetoothLENode(“broadcaster-observer”);sourceNode。位置= [0 0 0];sourceNode。MeshConfig = cfgMeshSource;
创建一个蓝牙网格概要文件配置对象,指定元素地址并启用蓝牙LE节点的中继特性。
cfgMeshRelay = bluetoothMeshProfileConfig(ElementAddress=“0002”继电器= true)
cfgMeshRelay = bluetoothMeshProfileConfig with properties: ElementAddress: "0002" Relay: 1 Friend: 0 LowPower: 0 networktransmission: 1 NetworkTransmitInterval: 0.0100 TTL: 127 relayretransmission: 1 RelayRetransmitInterval: 0.0100
创建蓝牙LE节点,指定角色为“broadcaster-observer”
.指定中继节点的位置。将网格概要文件配置分配给中继节点。
relayNode = bluetoothLENode(“broadcaster-observer”);relayNode。位置= [25 0 0];relayNode。MeshConfig = cfgMeshRelay;
创建一个蓝牙网格概要文件配置对象,指定蓝牙LE节点的元素地址。
cfgMeshDestination = bluetoothMeshProfileConfig(ElementAddress=“0003”)
cfgMeshDestination = bluetoothMeshProfileConfig with properties: ElementAddress: "0003" Relay: 0 Friend: 0 LowPower: 0 networktransmission: 1 NetworkTransmitInterval: 0.0100 TTL: 127
创建蓝牙LE节点,指定角色为“broadcaster-observer”
.指定目的节点的位置。将网格概要文件配置分配给目标节点。
destinationNode = bluetoothLENode(“broadcaster-observer”);destinationNode。位置= [50 0 0];destinationNode。MeshConfig = cfgMeshDestination;
创建一个networkTrafficOnOff
对象生成On-Off应用程序流量模式。指定准时、数据速率(kb/s)和数据包大小(字节)。通过启用包生成,生成带有有效负载的应用程序包。
traffic = networkTrafficOnOff(OnTime=inf,...DataRate = 1,...PacketSize = 15,...GeneratePacket = true);
在源节点和目的节点之间添加应用程序流量。
addTrafficSource (sourceNode、交通、...SourceAddress = cfgMeshSource。ElementAddress,...DestinationAddress = cfgMeshDestination.ElementAddress TTL = 10);
创建由源节点、中继节点和目的节点组成的蓝牙网状网络。
nodes = {sourceNode relayNode destinationNode};
将网格节点添加到无线网络模拟器中。
addnode (networkSimulator节点)
设置仿真时间并运行仿真。
simulationTime = 1;%秒运行(networkSimulator simulationTime);
未添加自定义通道模型。采用自由空间路径损耗(fspl)模型作为默认信道模型。
检索与源节点、中继节点和目的节点相关的应用程序、链路层(LL)和物理层(PHY)统计信息统计数据
对象的功能。有关统计信息的详细信息,请参见蓝牙LE节点统计信息.
sourceStats =统计信息(sourceNode)
sourceStats =带字段的结构:名称:"Node1" ID: 1 App: [1x1 struct]传输:[1x1 struct]网络:[1x1 struct] LL: [1x1 struct] PHY: [1x1 struct]
relayStats = statistics(relayNode)
relayStats =带字段的结构:名称:“Node2”ID: 2 App: [1x1 struct]传输:[1x1 struct]网络:[1x1 struct] LL: [1x1 struct] PHY: [1x1 struct]
destinationStats = statistics(destinationNode)
destinationStats =带字段的结构:名称:"Node3" ID: 3 App: [1x1 struct]传输:[1x1 struct]网络:[1x1 struct] LL: [1x1 struct] PHY: [1x1 struct]
参考文献
[1]蓝牙®技术网站。“蓝牙技术网站|蓝牙技术官网。”2021年11月22日访问。https://www.bluetooth.com/.
[2]蓝牙SIG (Bluetooth Special Interest Group)。“蓝牙核心规范。”5.3版。https://www.bluetooth.com/.