RPi3无法通过Bluepy python找到ffe0服务

时间:2018-05-25 21:54:23

标签: python-2.7 bluetooth-lowenergy raspberry-pi3

我有一个带有GPIO-hm10 ble模块的RPi2,它连接并与一个继电器板(RB1)通信。我想用RPi3替换RPi2。所以我用相同的测试单元继电器板RB2测试了RPi3,并使用这个python脚本,RPi3可以连接并与RB2通信。所以我准备交换它们。

以下是它的视觉效果:

RPi2 RPi3 RB1 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的某处保存一些可能导致这种情况的东西吗?

1 个答案:

答案 0 :(得分:0)

在检查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()