簡體   English   中英

RPi3無法通過Bluepy Python找到ffe0服務

[英]RPi3 can't find ffe0 service via Bluepy python

我有一個帶有GPIO-hm10 ble模塊的RPi2,該模塊連接ble繼電器板(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並看到包括我需要的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的某處保存某些內容嗎?

經過數小時的檢查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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM