Anrijs / Aranet4-Python

Aranet4, Aranet2 and Aranet Radiation Python client
MIT License
212 stars 18 forks source link

"Read not permitted" error when querying data #22

Closed 0x63lv closed 2 years ago

0x63lv commented 2 years ago

Hello An Aranet4 (firmware v0.4.10) is paired with a Linux (kernel 5.15) device. I can connect to this Aranet4 device and read the readable attributes via bluetoothctl (version 5.55) without any issues. When trying to query the same device with aranetctl, however, I get this:

$> aranetctl <aranet4:mac:address>
Traceback (most recent call last):
  File "/home/username/.local/bin/aranetctl", line 8, in <module>
    sys.exit(entry_point())
  File "/home/username/.local/lib/python3.9/site-packages/aranet4/aranetctl.py", line 236, in entry_point
    main(argv=sys.argv[1:])
  File "/home/username/.local/lib/python3.9/site-packages/aranet4/aranetctl.py", line 228, in main
    current = client.get_current_readings(args.device_mac)
  File "/home/username/.local/lib/python3.9/site-packages/aranet4/client.py", line 451, in get_current_readings
    return asyncio.run(_current_reading(mac_address))
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/username/.local/lib/python3.9/site-packages/aranet4/client.py", line 442, in _current_reading
    readings = await monitor.current_readings(details=True)
  File "/home/username/.local/lib/python3.9/site-packages/aranet4/client.py", line 245, in current_readings
    raw_bytes = await self.device.read_gatt_char(uuid)
  File "/home/username/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 598, in read_gatt_char
    assert_reply(reply)
  File "/home/username/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.NotPermitted] Read not permitted

I get that this is probably not strictly related exclusively to just this client, since I get pretty much the same error when using Go module for Aranet4 as well. Maybe something has changed after the most recent Aranet4 firmware update or I'm missing something else?

Anrijs commented 2 years ago

After upgrading my devices to 0.4.10, library seems to be working fine. ooking at your error message it seems to be permissions problem. Have you tried sudo aranetctl?

0x63lv commented 2 years ago

Thank you for verifying the firmware update. I had tried sudo and even root account as well, but the result was the same.

Did a bit more digging, and the problematic characteristic's UUID was f0cd3001-95da-4f4b-9ac8-aa55d312af0c, which, strangely, does have the read flag.

I eventually got it working by pairing Aranet4 with the mobile application and enabling "Homey integration" in the settings of the device. The characteristic can now be read, and the library works.

Perhaps this could be mentioned in Readme, or the particular error could be somehow handled.

Anyway, closing this one. Thank you.