hpeyerl / airthingswave-mqtt

Publish readings from Airthings Wave radon detectors to an MQTT broker
MIT License
18 stars 9 forks source link

Unable to run – Bluetooth command failed (code: 10) #8

Closed aicarmic closed 3 years ago

aicarmic commented 3 years ago

Firstly, thanks for this project. Hoping to publish the readings from my Wave 2 to my Home Assistant over MQTT. Unfortunately I've been unable to get this working with my Wave (gen 2).

find_wave2.py works and I am able to pick up my Wave's mac/serial, so I know the bluetooth stack is up and running on my RPi3. Any ideas what might be causing this? All dependencies are installed and up-to-date. Output below:

$ python -m airthingswave-mqtt /home/pi/airthingsconfig.yaml
Config file: /home/pi/airthingsconfig.yaml
/home/pi/.local/lib/python2.7/site-packages/airthingswave-mqtt/airthingswave.py:49: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  self.config=yaml.load(f)
basement <redacted>
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/pi/.local/lib/python2.7/site-packages/airthingswave-mqtt/__main__.py", line 32, in <module>
    main()
  File "/home/pi/.local/lib/python2.7/site-packages/airthingswave-mqtt/__main__.py", line 25, in main
    r = atw.get_readings(handle)
  File "/home/pi/.local/lib/python2.7/site-packages/airthingswave-mqtt/airthingswave.py", line 96, in get_readings
    ch  = p.getCharacteristics(uuid=s.uuid)[0]
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 508, in getCharacteristics
    rsp = self._getResp('find')
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 368, in _waitResp
    raise BTLEGattError("Bluetooth command failed", resp)
bluepy.btle.BTLEGattError: Bluetooth command failed (code: 10, error: No attribute found within the given range)`
hpeyerl commented 3 years ago

The short answer is "I have no idea". The slightly longer answer is just speculation. You mention that it's a "Gen 2" so that makes me wonder if they've changed what GATT profile it's responding to or have changed the sensor indexes or something.

Looks like they do have different code for an "Airthings Wave Plus": https://github.com/Airthings/waveplus-reader/blob/master/read_waveplus.py

When I get some more time, I can compare and see how they're different and perhaps mod this code. But since I don't have a device to test it with, I'll be shooting in the dark.

...unless you're feeling adventurous...

aicarmic commented 3 years ago

Thanks @hpeyerl for the reply and pointers – I was suspecting something similar but wasn't sure if this project had been tested against a Wave gen 2 yet.

I will do some more debugging tonight and see if I can pin down what's changed with the gen2. Airthings themselves have a separate read script for the gen2 devices, so that's another hint. Will reply back or suggest a PR if I figure it out!

aicarmic commented 3 years ago

@hpeyerl you were correct, they significantly changed the bluetooth stack on wave2 models. I was able to put together a project that does functionally the same thing, but for wave2s. Thanks for the inspiration!

https://github.com/aicarmic/airthings-wave2-mqtt