【发布时间】:2018-11-05 07:58:09
【问题描述】:
我有一个带有 GPIO-hm10 ble 模块的 RPi2,它与 ble 继电器板 (RB1) 连接并通信。我想用 RPi3 替换 RPi2。所以我用一个相同的测试单元继电器板RB2测试了RPi3,并使用这个python脚本,RPi3可以连接RB2并与之通信。所以我准备交换它们。
这是它的视觉效果:
我还尝试从 iPhone 上的 BLE 扫描仪应用程序连接到两个继电器板(RB1 和 RB2),我可以通过写入它们的字符来很好地连接和发送命令。
我可以通过 bluetoothctl 从 RPi3 连接、配对和信任这两个板,并查看它们的 UUID 服务。但是当我运行我的 python 代码来切换 RB2 上的继电器时:
import bluepy.btle as btle
p = btle.Peripheral("00:0E:0B:00:75:12", "random")
s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb")
c = s.getCharacteristics()[0]
c.write("o", "utf-8")
p.disconnect()
我仅在 RB1 上收到此错误::
File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 449, in getServiceByUUID
raise BTLEException(BTLEException.GATT_ERROR, "Service %s not found" % (uuid.getCommonName()))
bluepy.btle.BTLEException: Service ffe0 not found
但是服务的uuid是正确的,这里是终端会话输出。如您所见,我可以连接到 RB1 并查看 UUID 服务,包括我需要的 ffe0:
[bluetooth]# connect 00:0E:0B:00:75:12
Attempting to connect to 00:0E:0B:00:75:12
[CHG] Device 00:0E:0B:00:75:12 Connected: yes
Connection successful
[CHG] Device 00:0E:0B:00:75:12 UUIDs:
00001800-0000-1000-8000-00805f9b34fb
00001801-0000-1000-8000-00805f9b34fb
0000ffe0-0000-1000-8000-00805f9b34fb
[bluetooth]# info 00:0E:0B:00:75:12
Device 00:0E:0B:00:75:12
Name: BT Bee-BLE
Alias: BT Bee-BLE
Paired: no
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile
(00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile
(00001801-0000-1000-8000-00805f9b34fb)
UUID: Unknown
(0000ffe0-0000-1000-8000-00805f9b34fb)
为什么会这样?是否可以在 tsrb430 RB1 的某处保存可能导致此问题的某些内容?
【问题讨论】:
标签: python-2.7 bluetooth-lowenergy raspberry-pi3