Open DanClarke-io opened 1 month ago
Perhaps I should move from the implicit BleakScanner.discover()
in client.connect()
to an explicit BleakScanner.discover()
in run()
, passing the BLEDevice
into the Fridge
constructor?
fridge.py
has been updated to use BleakScanner.find_device_by_address()
, which should reduce the likelihood of getting a timeout connecting to the device.
Thanks for your quick replies @klightspeed, unfortunately we are still facing the same issue.. I'm trying to merge the decoding function of your repo into the python code I've worked on, i'll keep you posted!
Here is the response I get now:
✘ ⚡ root@journey-control /opt/BrassMonkeyFridgeMonitor main python3 fridge.py ED:67:39:CE:17:7A
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/bleak/backends/bluezdbus/client.py", line 214, in connect
reply = await self._bus.call(
File "/usr/local/lib/python3.9/dist-packages/dbus_fast/aio/message_bus.py", line 385, in call
await future
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/BrassMonkeyFridgeMonitor/fridge.py", line 563, in <module>
main()
File "/opt/BrassMonkeyFridgeMonitor/fridge.py", line 557, in main
asyncio.run(run(args.address, args.bind, args.loop, args.pollinterval))
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 "/opt/BrassMonkeyFridgeMonitor/fridge.py", line 501, in run
async with Fridge(fridge_dev) as fridge:
File "/opt/BrassMonkeyFridgeMonitor/fridge.py", line 346, in __aenter__
await self.connect()
File "/opt/BrassMonkeyFridgeMonitor/fridge.py", line 316, in connect
await self.client.connect()
File "/usr/local/lib/python3.9/dist-packages/bleak/__init__.py", line 615, in connect
return await self._backend.connect(**kwargs)
File "/usr/local/lib/python3.9/dist-packages/bleak/backends/bluezdbus/client.py", line 315, in connect
raise
File "/usr/local/lib/python3.9/dist-packages/async_timeout/__init__.py", line 141, in __aexit__
self._do_exit(exc_type)
File "/usr/local/lib/python3.9/dist-packages/async_timeout/__init__.py", line 228, in _do_exit
raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
Running on a RPI4
Thanks again
async with BleakClient(d) as client:
BleakClient.__aenter__
internally calls connect
, so apart from the multiple retries in fridge.py
, there should be no functional difference.
You should be able to import fridge.py
as a module, and use it at whatever depth you are wanting (whether using the raw decoding functions, or the Fridge
class).
I am getting a timeout error when putting in the MAC address of my fridge. I know it does work as I've partially built a script using this basic script:
I get an output of:
This is the output I get from your script, I just wish I could get it to not time out!