Anrijs / Aranet4-Python

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

MAC address not found #16

Closed sammcj closed 2 years ago

sammcj commented 2 years ago

Although I think this library is written for Linux, I thought I'd try it out on macOS.

It looks like it can't find the unit (the MAC is correct, just redacted below).

Is the intended flow that you connect the OS to the device before running this - or should this both find and connect to it directly?

aranetctl "XX:XX:XX:XX:XX:XX"
Traceback (most recent call last):
  File "/opt/homebrew/bin/aranetctl", line 8, in <module>
    sys.exit(entry_point())
  File "/opt/homebrew/lib/python3.9/site-packages/aranet4/aranetctl.py", line 215, in entry_point
    main(argv=sys.argv[1:])
  File "/opt/homebrew/lib/python3.9/site-packages/aranet4/aranetctl.py", line 207, in main
    current = client.get_current_readings(args.device_mac)
  File "/opt/homebrew/lib/python3.9/site-packages/aranet4/client.py", line 366, in get_current_readings
    return asyncio.run(_current_reading(mac_address))
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/python@3.9/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/opt/homebrew/lib/python3.9/site-packages/aranet4/client.py", line 356, in _current_reading
    await monitor.connect()
  File "/opt/homebrew/lib/python3.9/site-packages/aranet4/client.py", line 215, in connect
    await self.device.connect()
  File "/opt/homebrew/lib/python3.9/site-packages/bleak/backends/corebluetooth/client.py", line 86, in connect
    raise BleakError(
bleak.exc.BleakError: Device with address XX:XX:XX:XX:XX:XX was not found
ukBaz commented 2 years ago

This library builds on the bleak where UUIDs are utilized instead of Bluetooth address for macOS.

More information at: https://bleak.readthedocs.io/en/latest/backends/macos.html#specific-features-for-the-macos-backend

ukBaz commented 2 years ago

I don't have access to a macOS machine to test so any more detail you can share would be helpful.

My first thought was that you could provide the UUID instead of the mac address. However, the following might block that: https://github.com/Anrijs/Aranet4-Python/blob/a85660ed4a6408732379518ddbdf87a8aa3e2172/aranet4/client.py#L204-L207

So it might be that this check needs to be different if it detects this is running on a macOS machine.

Anrijs commented 2 years ago

@sammcj Try now with version 2.0.3. First run aranetctl --scan to find UUID. Then use this UUID instead of MAC address.

sammcj commented 2 years ago

Sorry for the slow response.

That fixed it, it works!

--------------------------------------
 Connected: Aranet4 317960060368 | v0.4.10
 Updated 28 s ago. Intervals: 300 s
 2016 total log_size
 --------------------------------------
 CO2:            577 ppm
 Temperature:    18.9 °C
 Humidity:       54 %
 Pressure:       990.3 hPa
 Battery:        95 %
 Status Display: GREEN
--------------------------------------

Thank you,