peplin/pygatt

Unable to read the characteristic but with no problem to subscribe

YuanjenHung opened this issue · 0 comments

Hi, everyone! I tried to connect my raspberry pi to Arduino BLE sense using pygatt, unfortunately something weird happened. With the code block 1, I can subscribe to one of the characteristic without any problem. Then I tried another approach code block 2 by reading the characteristic using char_read method, in this case, a NotificationTimeout exception was thrown (more information is attached below). Maybe I made dumb mistake, but I already checked the code for different time, so anyone has any idea how does this happened? and how can I fix it?

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

code block 1

bedroom_adapter = pygatt.GATTToolBackend()
  try: 
    bedroom_adapter.start()
    bedroom_sensor = bedroom_adapter.connect(BEDROOM_MAIN_ADDRESS)
    print("Connected to Bedroom Main!")
    bedroom_sensor.subscribe(
      bedroom_ambientLight_Uuid,
      callback = on_ambientLight_bedroom_update
    )
    while True:
      pass
  finally:
    bedroom_adapter.stop()
    print("Disconnect to Bedroom Main!")

code block 2

bedroom_adapter = pygatt.GATTToolBackend()
  try: 
    bedroom_adapter.start()
    bedroom_sensor = bedroom_adapter.connect(BEDROOM_MAIN_ADDRESS)
    print("Connected to Bedroom Main!")
    raw_value = bedroom_sensor.char_read(bedroom_ambientLight_Uuid)
  finally:
    bedroom_adapter.stop()
    print("Disconnect to Bedroom Main!")