BLE连接不稳定

时间:2018-03-05 14:26:45

标签: python bluetooth raspberry-pi bluetooth-lowenergy esp32

我使用esp32在bluepy库的帮助下使用BLE将传感器数据发送到raspberry pi。在此,我收到与设备断开连接的错误。任何人都可以帮我解决为什么我会收到错误。

这是我的覆盆子pi的python代码:

import binascii
import struct
import time
from bluepy.btle import UUID, Peripheral

temperature_uuid = UUID(6E400003-B5A3-F393-E0A9-E50E24DCCA9E)

p = Peripheral("24:0A:C4:02:D1:DA", "public")

try:
    ch = p.getCharacteristics(uuid=temp_uuid)[0]
    while 1:
        val = binascii.b2a_hex(ch.read())
        print str(val)
        time.sleep(1)

finally:
    p.disconnect()

错误看起来像:

Traceback (most recent call last):
File "ble_test.py", line 9, in <module>
   p = Peripheral("24:0A:C4:83:14:B6", "public")
   File "/home/pi/.local/lib/python2.7/site-packages/bluepy/btle.py", 
   line 353, in __init__
   self._connect(deviceAddr, addrType, iface)
   File "/home/pi/.local/lib/python2.7/site-packages/bluepy/btle.py", 
   line 402, in _connect
   "Failed to connect to peripheral %s, addr type: %s" % (addr, 
   addrType))
   bluepy.btle.BTLEException: Failed to connect to peripheral 
   24:0A:C4:83:14:B6, addr type: public

0 个答案:

没有答案