可以通过使用bluez提供的GattTool工具,向BLE设备动态更新广告数据。下面是使用python脚本发送广告数据的例子(仅作参考):
import os
# 这里要将bluetoothd进程杀掉,因为它占用了hci0,从而使gatttool不能使用此接口。
os.system("sudo hciconfig hci0 down")
os.system("sudo hciconfig hci0 up")
# 建立连接
os.system("gatttool -I")
os.system("connect {BLE设备MAC地址}")
# 设置广告数据
os.system("char-write-req 0x0008 {广告数据}")
# 释放连接
os.system("disconnect")
os.system("quit")