Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read the characteristic but with no problem to subscribe #338

Open
YuanjenHung opened this issue Nov 9, 2021 · 0 comments
Open

Comments

@YuanjenHung
Copy link

YuanjenHung commented Nov 9, 2021

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!")
@YuanjenHung YuanjenHung changed the title Unable to read the characteristic but no problem to subscribe Unable to read the characteristic but with no problem to subscribe Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant