我有一个带有GPIO-hm10ble模块的RPi2,它可以连接到ble中继板(RB1)并与之通信。我想用RPi3替换RPi2。因此,我使用一个相同的测试单元中继板RB2测试了RPi3,并且使用这个python脚本,RPi3可以连接到RB2并与之通信。所以我准备把它们换掉。
这是它的视觉效果:
我还尝试从iphone上的BLE scanner应用程序连接到两个中继板(RB1和RB2),我可以通过写入它们的字符来连接和发送命令。
我可以从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并看到包括我需要的ffe0的UUID服务:
[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中的某个地方保存了可能导致此问题的某些内容?
发布于 2018-05-30 07:28:01
在检查btle.py文件几个小时后,我注意到getServices()函数没有被调用。我向它添加了一个调用,现在它可以找到该服务:
#!/usr/bin/env python
import bluepy.btle as btle
p = btle.Peripheral("00:0E:0B:00:75:12", "random")
services=p.getServices()
for service in services:
print service
s = p.getServiceByUUID("0000ffe0-0000-1000-8000-00805f9b34fb")
c = s.getCharacteristics()[0]
c.write("e", "utf-8")
p.disconnect()
https://stackoverflow.com/questions/50537310
复制相似问题