warhammerkid / bluetti_mqtt

MQTT interface for Bluetti power stations
MIT License
139 stars 53 forks source link

Feature Request: Logging #55

Closed mbay0r closed 1 year ago

mbay0r commented 1 year ago

Could a loggin option be added?

I always turn off the AC200M at night, after a few failed BT connections the application shuts down.

2023-01-01 18:38:19 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
2023-01-01 18:38:20 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:20 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation already in progress
2023-01-01 18:38:21 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:21 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
2023-01-01 18:38:22 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:22 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation already in progress
2023-01-01 18:38:23 INFO     Retrying connection to 04:7F:0E:AD:X:X
2023-01-01 18:38:23 ERROR    Error connecting to device 04:7F:0E:AD:X:X:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/bluetti_mqtt/bluetooth/client.py", line 40, in run
    await self.client.connect()
  File "/usr/local/lib/python3.10/dist-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/client.py", line 190, in connect
    assert_reply(reply)
  File "/usr/local/lib/python3.10/dist-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] br-connection-canceled
^C2023-01-01 18:38:23 INFO     Shutting down...

When systemd then restarts, sometimes no Bluetooth connection is established.

How is it possible to prevent the shutdown?

warhammerkid commented 1 year ago

It looks like it's shutting down because it's told to. The ^C at the beginning of the last line is a sign that either you hit Control+C on the keyboard or something else told it to shut down. I just tested this with my personal Bluetti AC300, and I was able to turn off Bluetooth on my power station for several minutes without it saying it was "Shutting down...". It didn't reconnect correctly, however, after I turned Bluetooth back on, so there's room for improvement there.