pygatt NotificationTimeout:无

问题描述

我尝试从基于BLE的传感器中读取特征数据。因此,我使用pygatt模块

import pygatt

adapter = pygatt.GATTToolBackend()

try:
   adapter.start()
   device = adapter.connect("2B:01:56:6C:F4:E6")
   value= device.char_read("00007502-0000-1000-8000-00805f9b34fb")

finally:
   adapter.stop()

每次我尝试在Linux控制台(使用Python 2.7.16)中运行此命令时,都会出现错误

Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "/home/pi/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/device.py",line 17,in wrapper
    return func(self,*args,**kwargs)
  File "/home/pi/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/device.py",line 40,in char_read
    return self._backend.char_read(self,uuid,**kwargs)
  File "/home/pi/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/gatttool.py",line 50,line 593,in char_read
    self.sendline('char-read-uuid %s' % uuid)
  File "/usr/lib/python2.7/contextlib.py",line 24,in __exit__
    self.gen.next()
  File "/home/pi/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/gatttool.py",line 191,in event
    self.wait(event,timeout)
  File "/home/pi/.local/lib/python2.7/site-packages/pygatt/backends/gatttool/gatttool.py",line 157,in wait
    raise NotificationTimeout()
pygatt.exceptions.NotificationTimeout: None

我对这个错误完全迷失了。你知道如何解决这个问题吗? 任何帮助对此表示赞赏。预先感谢...

解决方法

因为我遇到了同样的问题,但似乎没有人遇到这个问题...

好吧,问题在于所请求的UUID特征不存在/无效。确保您输入正确或从油灰或类似的东西中复制时没有剪掉某些部分。(完全不是凭经验说话!当然!)

如果您要从互联网或类似设备上粘贴特征性UUID,则您的设备可能没有此UUID。

OR

如果您写入的不可写(只读/仅订阅)UUID,也可能会发生这种情况(未经测试,但应该有意义)。

如果您确定一切正确,并且使用专用嗅探器或只是在手机上使用BLE扫描器对UUID进行了三遍检查,则设备可能关闭连接的速度过快。

故障排除:

您可以手动与设备连接并使用以下命令发出命令:

gatttool -I

在程序内部,键入:

connect aa:bb:cc:dd:ee:ff

然后,在连接关闭之前:

char-read-uuid xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

并分析会发生什么。如果可以,那么应该也可以在python中工作。