我正在嵌入式 Linux 板上研究 BLE(低功耗蓝牙)。我们使用 BlueZ 和 Python。我需要创建 EddyStone Beacon。我发现有一种方法可以创建 iBeacon:https ://scribles.net/creating-ibeacon-using-bluez-example-code-on-raspberry-pi/ 。我尝试过这个。有效。但是我们需要创建 EddyStone Beacon。所以我使用这里的 Beacon 数据格式(https://ukbaz.github.io/howto/beacon_scan_cmd_line.html)来创建制造商数据。但是我的代码不起作用。我的代码有什么问题?这是我的代码:
def __init__(self, bus, index):
eddystone_id = 0xAAFE
beacon_type = [0x14, 0x16] # Length = 0x14, EddyStone type = 0x16
uuid = [0xAA, 0xFE] # EddyStone UUID = 0xAAFE
frame_type = [0x10] # Frame Type = 0x10
power = [0x00] # Power = 0x00
prefix = [0x02] # URL scheme = 0x02 (http://)
url = [0x73, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x77, 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x07]
Advertisement.__init__(self, bus, index, 'peripheral')
self.add_manufacturer_data(eddystone_id, beacon_type + uuid + frame_type + power + prefix + url)
但是,如果我使用此命令,则会创建 EddyStone 信标。我可以看到它在 nRF 移动应用程序中显示了 EddyStone Beacon:
sudo hcitool -i hci0 cmd 0x08 0x0008 1c 02 01 06 03 03 aa fe 14 16 aa fe 10 00 02 73 61 6d 70 6c 65 77 65 62 73 69 74 65 07 00 00 00
如您所见,我在 add_manufacturer_data() 函数中放入的数据与命令中的数据相同。但是为什么 Python 代码不起作用?