Giter VIP home page Giter VIP logo

ble2mqtt's People

Contributors

archekb avatar devbis avatar e-minguez avatar freefelt avatar gloird avatar j4cbo avatar m4dm4rtig4n avatar nicolaerosia avatar quintinhill avatar stefan-golinschi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ble2mqtt's Issues

Handle negative temperatures

It seems like negative temperatures are not handled correctly, and they end up being reported as uint16 overflowed, e.g. 6548.6 C

Re: Reconnection interval and forcing connections for disconnection errors

Hi, thanks a lot for working on these - I've managed to get them up and running but I am getting disconnects and I'm not sure they are signal strength related..

The below three are the types of errors I am getting.

Oct 08 12:44:15 (redacted): 2022-10-08 12:44:15 WARNING: Error while connecting to Blind_AM43_02676afdad5b, Device with address 02:67:6A:FD:AD:5B was not found. BleakError('Device with address 02:67:6A:FD:AD:5B was not found.'), attempts=2
Oct 08 12:45:17 (redacted): 2022-10-08 12:45:17 WARNING: Error while connecting to Blind_AM43_02676afdad5b, [org.bluez.Error.Failed] Software caused connection abort BleakDBusError('org.bluez.Error.Failed', 'Software caused connection abort'), failure_count=2
Oct 08 13:03:23 (redacted): 2022-10-08 13:03:23 WARNING: Error while connecting to Blind_AM43_02676afdad5b, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=1

In all of these cases (all that I've tried) the script doesn't seem to be able to connect to the device but a manual connection on bluetoothctl (eg. blueoothctl connect MAC_ADD) seems to get through with no issue. On adding a second AM43 device, the disconnection issues have gotten more frequent.

For error (1), is it possible to force a connection attempt regardless of whether an address is found or not?
For error (2), can we reduce to reconnection interval? I'm not used to Python programming, but this seems to be under the manage_device(self) function (line 562, ble2mqtt.py)). The connect() function I've traced to base.py line 586 - is there anyway to reduce the reconnection interval.
Not sure what error (3) is about.

EDIT: Is it possible that this clashes with another BLE script eg. https://github.com/custom-components/ble_monitor? If that is the case is it possible in your script to define another Bluetooth adapter to be used if I use another one (eg. hci1 instead of hci0)? Line 131 in main.py has:

    # 'hci_device': 'hci0',

commented out. Is it possible/coded in to uncomment, and replace hci0 with eg hci1?

Also related error during service startup is:

Oct 08 11:04:03 (redacted): Restarting bluetooth (via systemctl): bluetooth.service
Oct 08 11:04:03 (redacted): Failed to restart bluetooth.service: Interactive authentication required.
Oct 08 11:04:03 (redacted): See system logs and 'systemctl status bluetooth.service' for details.
Oct 08 11:04:03 (redacted): failed!
Oct 08 11:04:06 (redacted): Can't init device hci0: Operation not permitted (1)

Would you suggest running this as a dockerised process instead?

Thanks.
Zhao

don't work bleak 0.19

File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 709, in manage_device
await aio.wait_for(
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
2022-10-22 00:32:59 ERROR: Redmond_112233aabbce not disconnected in 10 secs
Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/locks.py", line 226, in wait
await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 490, in wait_for
return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 709, in manage_device
await aio.wait_for(
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
2022-10-22 00:33:01 WARNING: Restarting bluetoothd finished
2022-10-22 00:33:01 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:02 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:03 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:04 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:05 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:06 ERROR: module 'bleak' has no attribute 'version'
Traceback (most recent call last):
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 885, in scan_devices_task
scanner = get_scanner(self.device_detection_callback)
File "/root/.local/lib/python3.9/site-packages/ble2mqtt/compat.py", line 13, in get_scanner
if bleak.version < '0.18':
AttributeError: module 'bleak' has no attribute 'version'
2022-10-22 00:33:07 ERROR: module 'bleak' has no attribute 'version'
Traceback (mo

Error occurs when declaring an additional BM2 voltage sensor

Ble2mqtt version 0.1.8 on Openwrt

It runs okay when only declaring a BM2 sensor

2023-08-22 10:20:55 INFO: Connected to 50:54:7B:22:6C:8F
2023-08-22 10:20:56 INFO: [BM2_Battery_Monitor_50547b226c8f] send state=SensorState(voltage=12.52)
2023-08-22 10:22:05 INFO: Connected to 50:54:7B:22:6C:8F
2023-08-22 10:22:06 INFO: [BM2_Battery_Monitor_50547b226c8f] send state=SensorState(voltage=12.51)
2023-08-22 10:23:14 INFO: Connected to 50:54:7B:22:6C:8F
2023-08-22 10:23:16 INFO: [BM2_Battery_Monitor_50547b226c8f] send state=SensorState(voltage=12.51)

However, when declaring additional sensor it reports errors, for example, addding Mijia ATC and Wp6003

2023-08-22 10:24:12 INFO: Starting BLE2MQTT version 0.1.8
2023-08-22 10:24:12 INFO: Connected to localhost
2023-08-22 10:24:12 WARNING: Restarting bluetoothd...
2023-08-22 10:24:15 ERROR: [org.bluez.Error.Failed] No discovery started
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 907, in scan_devices_task
  File "/usr/lib/python3.11/site-packages/bleak/__init__.py", line 186, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 203, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 390, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] No discovery started
2023-08-22 10:24:20 WARNING: Restarting bluetoothd finished
2023-08-22 10:24:23 WARNING: Error while connecting to Vson_600303942dd9, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=1
2023-08-22 10:24:24 WARNING: Error while connecting to BM2_50547b226c8f, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=1
2023-08-22 10:24:25 INFO: Connected to 60:03:03:94:2D:D9
2023-08-22 10:24:25 INFO: [Vson_6003#0600303942DD9_600303942dd9] send state=SensorState(temperature=24.5, tvoc=6.632, hcho=1.059, co2=1205)
2023-08-22 10:24:37 INFO: [Xiaomi_ATC_DAFB00_a4c138dafb00] send state=SensorState(battery=45, temperature=22.0, humidity=55, sends_custom=False)
2023-08-22 10:24:45 INFO: [Vson_6003#0600303942DD9_600303942dd9] send state=SensorState(temperature=24.5, tvoc=6.574, hcho=1.05, co2=1201)
2023-08-22 10:25:06 INFO: [Vson_6003#0600303942DD9_600303942dd9] send state=SensorState(temperature=24.5, tvoc=6.574, hcho=1.05, co2=1201)
2023-08-22 10:25:24 WARNING: Restarting bluetoothd...
2023-08-22 10:25:32 WARNING: Restarting bluetoothd finished
2023-08-22 10:25:32 WARNING: Restarting bluetoothd...
2023-08-22 10:25:35 WARNING: Error while connecting to BM2_50547b226c8f, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=2
2023-08-22 10:25:37 INFO: [Xiaomi_ATC_DAFB00_a4c138dafb00] send state=SensorState(battery=45, temperature=22.0, humidity=55, sends_custom=False)
2023-08-22 10:25:40 WARNING: Restarting bluetoothd finished
2023-08-22 10:25:43 WARNING: Error while connecting to Vson_6003#0600303942DD9_600303942dd9, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=1
2023-08-22 10:25:44 ERROR: [org.bluez.Error.InProgress] Operation already in progress
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 907, in scan_devices_task
  File "/usr/lib/python3.11/site-packages/bleak/__init__.py", line 186, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 203, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 390, in stop
  File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress
2023-08-22 10:25:45 INFO: Connected to 60:03:03:94:2D:D9
2023-08-22 10:25:45 INFO: [Vson_6003#0600303942DD9_600303942dd9] send state=SensorState(temperature=24.5, tvoc=6.574, hcho=1.05, co2=1201)

This is the configuration file

{
    "mqtt_host": "localhost",
    "mqtt_port": 1883,
    "mqtt_user": "",
    "mqtt_password": "",
    "log_level": "INFO",
    "devices": [
        
        {
            "address": "A4:C1:38:DA:FB:00",
            "type": "xiaomilywsd_atc"
        },
                {
            "address": "60:03:03:94:2D:D9",
            "type": "wp6003"
        },
        {
            "address": "50:54:7B:22:6C:8F",
            "type": "voltage_bm2"
        }
    ]
}

Hope you can take some time to review and help resolve this issue. thanks

Add support for AM43 Blinds

https://github.com/TheBazeman/A-OK-AM43-Blinds-Drive
https://github.com/binsentsu/am43-ctrl

[Blind]# list-attributes 
Primary Service (Handle 0x5270)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service0001
  00001801-0000-1000-8000-00805f9b34fb
  Generic Attribute Profile
Characteristic (Handle 0x8b34)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service0001/char0002
  00002a05-0000-1000-8000-00805f9b34fb
  Service Changed
Descriptor (Handle 0x0015)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service0001/char0002/desc0004
  00002902-0000-1000-8000-00805f9b34fb
  Client Characteristic Configuration
Primary Service (Handle 0x6920)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service000c
  0000fe50-0000-1000-8000-00805f9b34fb
  Google Inc.
Characteristic (Handle 0xaac4)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service000c/char000d
  0000fe51-0000-1000-8000-00805f9b34fb
  SRAM 
Descriptor (Handle 0x0015)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service000c/char000d/desc000f
  00002902-0000-1000-8000-00805f9b34fb
  Client Characteristic Configuration
Characteristic (Handle 0xad28)
  /org/bluez/hci0/dev_02_F6_21_7E_10_96/service000c/char0010
  0000fe52-0000-1000-8000-00805f9b34fb
  SetPoint Medical

Application crashed when connection to Mosquitto lost

In docker on rasbpi I'm getting application crash when it lost connectivity to mosquitto. Only restart helps.

ERROR: Connection lost. Will retry in 10 seconds. Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 204, in connect self._reader, self._writer = await aio.open_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/streams.py", line 48, in open_connection transport, _ = await loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection raise exceptions[0] File "/usr/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock await self.sock_connect(sock, address) File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect return await fut ^^^^^^^^^ File "/usr/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 1883) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 970, in _connect_forever mqtt_connection = await aio.wait_for(self._mqtt_client.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/tasks.py", line 479, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 207, in connect raise ConnectFailedError() from e aio_mqtt.exceptions.ConnectFailedError ERROR: Disconnect from MQTT broker error ERROR: Connection lost. Will retry in 10 seconds. Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 204, in connect self._reader, self._writer = await aio.open_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/streams.py", line 48, in open_connection transport, _ = await loop.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection raise exceptions[0] File "/usr/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock await self.sock_connect(sock, address) File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect return await fut ^^^^^^^^^ File "/usr/lib/python3.11/asyncio/selector_events.py", line 674, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 1883) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 970, in _connect_forever mqtt_connection = await aio.wait_for(self._mqtt_client.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/tasks.py", line 479, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 207, in connect raise ConnectFailedError() from e aio_mqtt.exceptions.ConnectFailedError ERROR: Disconnect from MQTT broker error INFO: Connected to localhost WARNING: Restarting bluetoothd... ERROR: <Task finished name='Task-1458' coro=<Ble2Mqtt.scan_devices_task() done, defined at /usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py:881> exception=FileNotFoundError(2, 'No such file or directory')> stopped unexpectedly Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 178, in handle_ble_exceptions yield File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 896, in scan_devices_task await aio.wait_for(scanner.start(), 10) File "/usr/lib/python3.11/asyncio/tasks.py", line 479, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/bleak/__init__.py", line 182, in start await self._backend.start() File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 191, in start self._stop = await manager.active_scan( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 368, in active_scan assert_reply(reply) File "/usr/lib/python3.11/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.InProgress] Operation already in progress During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 890, in scan_devices_task async with handle_ble_exceptions(self._hci_adapter): File "/usr/lib/python3.11/contextlib.py", line 222, in __aexit__ await self.gen.athrow(typ, value, traceback) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 181, in handle_ble_exceptions await restart_bluetooth(adapter) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 146, in restart_bluetooth proc = await aio.create_subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/subprocess.py", line 218, in create_subprocess_exec transport, protocol = await loop.subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 1694, in subprocess_exec transport = await self._make_subprocess_transport( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/unix_events.py", line 207, in _make_subprocess_transport transp = _UnixSubprocessTransport(self, protocol, args, shell, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_subprocess.py", line 36, in __init__ self._start(args=args, shell=shell, stdin=stdin, stdout=stdout, File "/usr/lib/python3.11/asyncio/unix_events.py", line 810, in _start self._proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.11/subprocess.py", line 1917, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'hciconfig' ERROR: Connection lost. Will retry in 10 seconds. Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 178, in handle_ble_exceptions yield File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 896, in scan_devices_task await aio.wait_for(scanner.start(), 10) File "/usr/lib/python3.11/asyncio/tasks.py", line 479, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/bleak/__init__.py", line 182, in start await self._backend.start() File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 191, in start self._stop = await manager.active_scan( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 368, in active_scan assert_reply(reply) File "/usr/lib/python3.11/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.InProgress] Operation already in progress During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 992, in _connect_forever await self._run_device_tasks(mqtt_connection.disconnect_reason) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 964, in _run_device_tasks await handle_returned_tasks(*finished) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 114, in handle_returned_tasks await task_for_raise File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 890, in scan_devices_task async with handle_ble_exceptions(self._hci_adapter): File "/usr/lib/python3.11/contextlib.py", line 222, in __aexit__ await self.gen.athrow(typ, value, traceback) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 181, in handle_ble_exceptions await restart_bluetooth(adapter) File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 146, in restart_bluetooth proc = await aio.create_subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/subprocess.py", line 218, in create_subprocess_exec transport, protocol = await loop.subprocess_exec( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_events.py", line 1694, in subprocess_exec transport = await self._make_subprocess_transport( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/unix_events.py", line 207, in _make_subprocess_transport transp = _UnixSubprocessTransport(self, protocol, args, shell, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/asyncio/base_subprocess.py", line 36, in __init__ self._start(args=args, shell=shell, stdin=stdin, stdout=stdout, File "/usr/lib/python3.11/asyncio/unix_events.py", line 810, in _start self._proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.11/subprocess.py", line 1917, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'hciconfig' /usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py:867: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead if device.rssi: /usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py:869: FutureWarning: BLEDevice.rssi is deprecated and will be removed in a future version of Bleak, use AdvertisementData.rssi instead reg_device.rssi = device.rssi INFO: Connected to localhost WARNING: Restarting bluetoothd... ERROR: <Task finished name='Task-1472' coro=<Ble2Mqtt.scan_devices_task() done, defined at /usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py:881> exception=FileNotFoundError(2, 'No such file or directory')> stopped unexpectedly

Redmond Kettle G2XX auth problem

Hi,
I try to connect , but it crashes with an error

INFO:ble2mqtt.ble2mqtt:Connected to localhost
INFO:ble2mqtt.devices.base:Connected to DE:39:B7:1D:85:42
INFO:ble2mqtt.protocols.redmond:Enable BLE notifications from [DE:39:B7:1D:85:42]
ERROR:ble2mqtt.ble2mqtt:Root task has raised an exception
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 556, in _run_device_tasks
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 402, in manage_device
  File "/usr/lib/python3.7/site-packages/ble2mqtt/devices/kettle_redmond.py", line 80, in get_device_data
  File "/usr/lib/python3.7/site-packages/ble2mqtt/protocols/redmond.py", line 225, in login
  File "/usr/lib/python3.7/site-packages/ble2mqtt/protocols/redmond.py", line 166, in _check_success
ble2mqtt.protocols.redmond.RedmondError: Not logged in
INFO:ble2mqtt.ble2mqtt:Disconnected
Traceback (most recent call last):
  File "/usr/bin/ble2mqtt", line 11, in <module>
    load_entry_point('ble2mqtt==0.1.0a11', 'console_scripts', 'ble2mqtt')()
  File "/usr/lib/python3.7/site-packages/ble2mqtt/__main__.py", line 61, in main
  File "/usr/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 115, in close
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 107, in stop_task
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 556, in _run_device_tasks
  File "/usr/lib/python3.7/site-packages/ble2mqtt/ble2mqtt.py", line 402, in manage_device
  File "/usr/lib/python3.7/site-packages/ble2mqtt/devices/kettle_redmond.py", line 80, in get_device_data
  File "/usr/lib/python3.7/site-packages/ble2mqtt/protocols/redmond.py", line 225, in login
  File "/usr/lib/python3.7/site-packages/ble2mqtt/protocols/redmond.py", line 166, in _check_success
ble2mqtt.protocols.redmond.RedmondError: Not logged in

Restart Bluetooth interface every 30 seconds can break Bluetooth controller driver

When all Bluetooth devices (from config) are offline, daemon will restart Bluetooth interface every 30 seconds. It can break Bluetooth controller driver (in my case Atheros AR3012 Bluetooth 4.0 Adapter).

root@ble2mqtt:/# rfkill list
0: hci0: Bluetooth
	Soft blocked: no
	Hard blocked: no
1: phy0: Wireless LAN
	Soft blocked: no
	Hard blocked: no

root@ble2mqtt:/# hciconfig hci0 up
Can't init device hci0: Connection timed out (110)

root@ble2mqtt:/# hciconfig 
hci0:	Type: Primary  Bus: USB
	BD Address: 24:0A:64:C8:36:64  ACL MTU: 1022:8  SCO MTU: 183:5
	DOWN INIT RUNNING 
	RX bytes:19840 acl:0 sco:0 events:668 errors:0
	TX bytes:2289 acl:0 sco:0 commands:726 errors:7

root@ble2mqtt:/# hciconfig hci0 up
Can't init device hci0: Connection timed out (110)

After that for UP Bluetooth interface I should remount driver, all another ways (host reboot too) have no effect.

rmmod ath3k
rmmod btusb
modprobe btusb

I think, we need some another way for check Bluetooth adapter status (online or offline) and restart interface only when it did not works.

syslog (GMT)
May 22 13:39:03 hsrv systemd[1]: Stopped target Bluetooth.
May 22 13:39:03 hsrv kernel: [ 8620.369121] usb 1-9: new full-speed USB device number 71 using xhci_hcd
May 22 13:39:04 hsrv kernel: [ 8620.519573] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.01
May 22 13:39:04 hsrv kernel: [ 8620.519580] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:39:04 hsrv kernel: [ 8620.519585] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:39:04 hsrv kernel: [ 8620.519588] usb 1-9: Manufacturer: Atheros Communications
May 22 13:39:04 hsrv kernel: [ 8620.519591] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:39:04 hsrv kernel: [ 8620.569272] usb 1-9: USB disconnect, device number 71
May 22 13:39:04 hsrv kernel: [ 8620.877300] usb 1-9: new full-speed USB device number 72 using xhci_hcd
May 22 13:39:08 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:39:09 hsrv kernel: [ 8626.191998] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.02
May 22 13:39:09 hsrv kernel: [ 8626.192004] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:39:09 hsrv kernel: [ 8626.192009] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:39:09 hsrv kernel: [ 8626.192013] usb 1-9: Manufacturer: Atheros Communications
May 22 13:39:09 hsrv kernel: [ 8626.192016] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:39:09 hsrv systemd[1]: Starting Load/Save RF Kill Switch Status...
May 22 13:39:09 hsrv systemd[1]: Reached target Bluetooth.
May 22 13:39:09 hsrv systemd[3763]: Reached target Bluetooth.
May 22 13:39:09 hsrv systemd[1]: Started Load/Save RF Kill Switch Status.
May 22 13:39:14 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:39:20 hsrv kernel: [ 8637.427978] usb 1-9: USB disconnect, device number 72
May 22 13:39:20 hsrv systemd[1]: Starting Load/Save RF Kill Switch Status...
May 22 13:39:20 hsrv systemd[3763]: Stopped target Bluetooth.
May 22 13:39:20 hsrv systemd[1]: Stopped target Bluetooth.
May 22 13:39:20 hsrv systemd[1]: Started Load/Save RF Kill Switch Status.
May 22 13:39:21 hsrv kernel: [ 8637.773559] usb 1-9: new full-speed USB device number 73 using xhci_hcd
May 22 13:39:21 hsrv kernel: [ 8637.924056] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.01
May 22 13:39:21 hsrv kernel: [ 8637.924063] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:39:21 hsrv kernel: [ 8637.924068] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:39:21 hsrv kernel: [ 8637.924071] usb 1-9: Manufacturer: Atheros Communications
May 22 13:39:21 hsrv kernel: [ 8637.924074] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:39:21 hsrv kernel: [ 8637.970042] usb 1-9: USB disconnect, device number 73
May 22 13:39:21 hsrv kernel: [ 8638.277737] usb 1-9: new full-speed USB device number 74 using xhci_hcd
May 22 13:39:26 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:39:27 hsrv kernel: [ 8643.600443] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.02
May 22 13:39:27 hsrv kernel: [ 8643.600451] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:39:27 hsrv kernel: [ 8643.600456] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:39:27 hsrv kernel: [ 8643.600460] usb 1-9: Manufacturer: Atheros Communications
May 22 13:39:27 hsrv kernel: [ 8643.600463] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:39:27 hsrv systemd[1]: Starting Load/Save RF Kill Switch Status...
May 22 13:39:27 hsrv systemd[3763]: Reached target Bluetooth.
May 22 13:39:27 hsrv systemd[1]: Reached target Bluetooth.
May 22 13:39:27 hsrv systemd[1]: Started Load/Save RF Kill Switch Status.
May 22 13:39:32 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:40:30 hsrv kernel: [ 8707.357930] usb 1-9: USB disconnect, device number 74
May 22 13:40:30 hsrv systemd[1]: Starting Load/Save RF Kill Switch Status...
May 22 13:40:30 hsrv systemd[1]: Started Load/Save RF Kill Switch Status.
May 22 13:40:30 hsrv systemd[3763]: Stopped target Bluetooth.
May 22 13:40:30 hsrv systemd[1]: Stopped target Bluetooth.
May 22 13:40:31 hsrv kernel: [ 8707.703253] usb 1-9: new full-speed USB device number 75 using xhci_hcd
May 22 13:40:31 hsrv kernel: [ 8707.853399] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.01
May 22 13:40:31 hsrv kernel: [ 8707.853406] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:40:31 hsrv kernel: [ 8707.853410] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:40:31 hsrv kernel: [ 8707.853414] usb 1-9: Manufacturer: Atheros Communications
May 22 13:40:31 hsrv kernel: [ 8707.853417] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:40:31 hsrv kernel: [ 8707.903413] usb 1-9: USB disconnect, device number 75
May 22 13:40:31 hsrv kernel: [ 8708.211373] usb 1-9: new full-speed USB device number 76 using xhci_hcd
May 22 13:40:35 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:40:37 hsrv kernel: [ 8713.490073] usb 1-9: New USB device found, idVendor=13d3, idProduct=3362, bcdDevice= 0.02
May 22 13:40:37 hsrv kernel: [ 8713.490082] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
May 22 13:40:37 hsrv kernel: [ 8713.490086] usb 1-9: Product: Bluetooth USB Host Controller
May 22 13:40:37 hsrv kernel: [ 8713.490091] usb 1-9: Manufacturer: Atheros Communications
May 22 13:40:37 hsrv kernel: [ 8713.490094] usb 1-9: SerialNumber: Alaska Day 2006
May 22 13:40:37 hsrv systemd[1]: Starting Load/Save RF Kill Switch Status...
May 22 13:40:37 hsrv systemd[1]: Reached target Bluetooth.
May 22 13:40:37 hsrv systemd[3763]: Reached target Bluetooth.
May 22 13:40:37 hsrv systemd[1]: Started Load/Save RF Kill Switch Status.
May 22 13:40:42 hsrv systemd[1]: systemd-rfkill.service: Succeeded.
May 22 13:41:36 hsrv kernel: [ 8772.637013] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:36 hsrv kernel: [ 8772.637019] Bluetooth: hci0: failed to restart LE scan: status 31
May 22 13:41:38 hsrv kernel: [ 8774.653019] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:38 hsrv kernel: [ 8774.653053] Bluetooth: hci0: failed to restart LE scan: status 31
May 22 13:41:40 hsrv kernel: [ 8776.669118] Bluetooth: hci0: failed to restart LE scan: status 31
May 22 13:41:40 hsrv kernel: [ 8776.669125] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:42 hsrv kernel: [ 8778.685118] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:44 hsrv kernel: [ 8780.701257] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:46 hsrv kernel: [ 8782.717292] Bluetooth: hci0: command 0x200c tx timeout
May 22 13:41:54 hsrv kernel: [ 8790.653569] usb 1-9: Failed to access otp area (-110)
May 22 13:41:59 hsrv kernel: [ 8795.773763] usb 1-9: Failed to access otp area (-110)
May 22 13:42:43 hsrv kernel: [ 8840.447153] usb 1-9: reset full-speed USB device number 76 using xhci_hcd
May 22 13:42:46 hsrv kernel: [ 8843.134868] Bluetooth: hci0: urb 000000003633bcb9 failed to resubmit (113)
May 22 13:42:57 hsrv kernel: [ 8853.471305] Bluetooth: hci0: urb 00000000cfb066d2 failed to resubmit (113)
May 22 13:43:17 hsrv kernel: [ 8873.791481] Bluetooth: hci0: urb 0000000077edb743 failed to resubmit (113)
May 22 13:43:24 hsrv kernel: [ 8880.863918] Bluetooth: hci0: urb 0000000031c5bcc1 failed to resubmit (113)
May 22 13:44:17 hsrv kernel: [ 8933.576995] Bluetooth: hci0: urb 000000000f4b34e0 failed to resubmit (113)
May 22 13:44:28 hsrv kernel: [ 8944.497450] Bluetooth: hci0: urb 00000000ea3428b7 failed to resubmit (113)
May 22 13:44:44 hsrv kernel: [ 8961.029644] Bluetooth: hci0: urb 0000000077edb743 failed to resubmit (113)
May 22 13:44:54 hsrv kernel: [ 8971.218091] Bluetooth: hci0: urb 000000000626774a failed to resubmit (113)
May 22 13:45:16 hsrv kernel: [ 8992.502451] Bluetooth: hci0: urb 0000000045317dab failed to resubmit (113)
May 22 13:45:26 hsrv kernel: [ 9003.354588] Bluetooth: hci0: urb 000000005b23099b failed to resubmit (113)
May 22 13:45:47 hsrv kernel: [ 9023.895061] Bluetooth: hci0: urb 000000006e571a11 failed to resubmit (113)
May 22 13:45:57 hsrv kernel: [ 9034.203398] Bluetooth: hci0: urb 000000000f4b34e0 failed to resubmit (113)
May 22 13:46:42 hsrv kernel: [ 9078.720428] Bluetooth: hci0: urb 000000008087d9a2 failed to resubmit (113)
ble2mqtt (GMT+5)
ble2mqtt_1     | Starting system message bus: dbus.
ble2mqtt_1     | 2022-05-22 17:10:50 INFO: Starting BLE2MQTT version 0.1.1
ble2mqtt_1     | 2022-05-22 17:10:50 INFO: Connected to 192.168.55.10
ble2mqtt_1     | 2022-05-22 17:10:52 INFO: Connected to 02:F6:21:7E:10:96
ble2mqtt_1     | 2022-05-22 17:10:53 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'closed', 'position': 100}}
ble2mqtt_1     | 2022-05-22 17:11:02 ERROR: [Blind_AM43_0209db993941] connection problem, attempts=1
ble2mqtt_1     | 2022-05-22 17:12:05 INFO: Connected to 02:09:DB:99:39:41
ble2mqtt_1     | 2022-05-22 17:12:05 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'closed', 'position': 100}}
ble2mqtt_1     | 2022-05-22 17:14:06 INFO: [Blind_AM43_0209db993941] set mode cover to "CLOSE"
ble2mqtt_1     | 2022-05-22 17:14:06 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'closing', 'position': 100}}
ble2mqtt_1     | 2022-05-22 17:14:06 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'closing', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:07 INFO: [Blind_AM43_02f6217e1096] set mode cover to "CLOSE"
ble2mqtt_1     | 2022-05-22 17:14:07 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'closing', 'position': 100}}
ble2mqtt_1     | 2022-05-22 17:14:07 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'closing', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:10 INFO: [Blind_AM43_0209db993941] set mode cover to "STOP"
ble2mqtt_1     | 2022-05-22 17:14:11 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'stopped', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:11 INFO: [Blind_AM43_02f6217e1096] set mode cover to "STOP"
ble2mqtt_1     | 2022-05-22 17:14:11 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'stopped', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:12 INFO: [Blind_AM43_0209db993941] set mode cover to "OPEN"
ble2mqtt_1     | 2022-05-22 17:14:12 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'opening', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:12 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'opening', 'position': 81}}
ble2mqtt_1     | 2022-05-22 17:14:13 INFO: [Blind_AM43_02f6217e1096] set mode cover to "OPEN"
ble2mqtt_1     | 2022-05-22 17:14:13 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'opening', 'position': 99}}
ble2mqtt_1     | 2022-05-22 17:14:14 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'opening', 'position': 82}}
ble2mqtt_1     | 2022-05-22 17:14:18 INFO: [Blind_AM43_0209db993941] Maximum position reached. Set to OPEN
ble2mqtt_1     | 2022-05-22 17:14:18 INFO: [Blind_AM43_0209db993941] send state={'linkquality': 79, 'battery': 96, 'illuminance': 0.0, 'cover': {'state': 'open', 'position': 100}}
ble2mqtt_1     | 2022-05-22 17:14:19 INFO: [Blind_AM43_02f6217e1096] Maximum position reached. Set to OPEN
ble2mqtt_1     | 2022-05-22 17:14:19 INFO: [Blind_AM43_02f6217e1096] send state={'linkquality': 87, 'battery': 94, 'illuminance': 0.0, 'cover': {'state': 'open', 'position': 100}}

// devices are turned off

ble2mqtt_1     | 2022-05-22 17:15:43 WARNING: Error while connecting to Blind_AM43_02f6217e1096, Device with address 02:F6:21:7E:10:96 was not found. BleakError('Device with address 02:F6:21:7E:10:96 was not found.'), attempts=1
ble2mqtt_1     | 2022-05-22 17:15:45 ERROR: [Blind_AM43_0209db993941] connection problem, attempts=1
ble2mqtt_1     | 2022-05-22 17:16:45 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=1
ble2mqtt_1     | 2022-05-22 17:16:50 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=1
ble2mqtt_1     | 2022-05-22 17:17:50 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=2
ble2mqtt_1     | 2022-05-22 17:17:52 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=2
ble2mqtt_1     | 2022-05-22 17:18:59 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=3
ble2mqtt_1     | 2022-05-22 17:18:59 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=3
ble2mqtt_1     | 2022-05-22 17:20:10 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=4
ble2mqtt_1     | 2022-05-22 17:20:11 ERROR: [Blind_AM43_0209db993941] connection problem, attempts=2
ble2mqtt_1     | 2022-05-22 17:21:20 WARNING: Error while connecting to Blind_AM43_02f6217e1096, Device with address 02:F6:21:7E:10:96 was not found. BleakError('Device with address 02:F6:21:7E:10:96 was not found.'), attempts=2
ble2mqtt_1     | 2022-05-22 17:21:21 WARNING: Error while connecting to Blind_AM43_0209db993941, Device with address 02:09:DB:99:39:41 was not found. BleakError('Device with address 02:09:DB:99:39:41 was not found.'), attempts=3
ble2mqtt_1     | 2022-05-22 17:22:21 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=4
ble2mqtt_1     | 2022-05-22 17:22:28 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=5
ble2mqtt_1     | 2022-05-22 17:22:28 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 17:22:37 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 17:23:32 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=5
ble2mqtt_1     | 2022-05-22 17:23:32 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Can't get device info: No such device
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 17:23:41 WARNING: Restarting bluetoothd finished

// and now adapter will break

ble2mqtt_1     | 2022-05-22 18:39:05 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Can't get device info: No such device
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 18:39:15 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 18:39:25 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=1
ble2mqtt_1     | 2022-05-22 18:40:26 WARNING: Error while connecting to Blind_AM43_02f6217e1096, Device with address 02:F6:21:7E:10:96 was not found. BleakError('Device with address 02:F6:21:7E:10:96 was not found.'), attempts=14
ble2mqtt_1     | 2022-05-22 18:40:36 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.UnknownObject] Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn't exist
ble2mqtt_1     |  BleakDBusError('org.freedesktop.DBus.Error.UnknownObject', 'Method "StopDiscovery" with signature "" on interface "org.bluez.Adapter1" doesn\'t exist\n'), failure_count=2
ble2mqtt_1     | 2022-05-22 18:41:36 WARNING: Error while connecting to Blind_AM43_02f6217e1096, Device with address 02:F6:21:7E:10:96 was not found. BleakError('Device with address 02:F6:21:7E:10:96 was not found.'), attempts=15
ble2mqtt_1     | 2022-05-22 18:41:46 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | Can't init device hci0: Input/output error (5)
ble2mqtt_1     | 2022-05-22 18:42:04 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 18:42:07 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=3
ble2mqtt_1     | 2022-05-22 18:42:36 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)
ble2mqtt_1     | 2022-05-22 18:43:09 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 18:43:09 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 18:43:12 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=1
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)
ble2mqtt_1     | 2022-05-22 18:43:37 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 18:43:40 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=4
ble2mqtt_1     | 2022-05-22 18:44:12 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)
ble2mqtt_1     | 2022-05-22 18:44:39 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 18:44:40 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 18:44:42 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=2
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)

...

ble2mqtt_1     | 2022-05-22 20:27:30 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 20:27:33 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=4
ble2mqtt_1     | 2022-05-22 20:28:02 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)
ble2mqtt_1     | 2022-05-22 20:28:29 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 20:28:32 WARNING: Error while connecting to Blind_AM43_02f6217e1096, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=2
ble2mqtt_1     | 2022-05-22 20:28:33 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | Can't init device hci0: Connection timed out (110)
ble2mqtt_1     | 2022-05-22 20:29:00 WARNING: Restarting bluetoothd finished
ble2mqtt_1     | 2022-05-22 20:29:03 WARNING: Error while connecting to Blind_AM43_0209db993941, [org.freedesktop.DBus.Error.AccessDenied] Client tried to send a message other than Hello without being registered BleakDBusError('org.freedesktop.DBus.Error.AccessDenied', 'Client tried to send a message other than Hello without being registered'), failure_count=5
ble2mqtt_1     | 2022-05-22 20:29:03 WARNING: Restarting bluetoothd...
ble2mqtt_1     | Stopping bluetooth: /usr/sbin/bluetoothd.
ble2mqtt_1     | Starting bluetooth: bluetoothd.
ble2mqtt_1     | 2022-05-22 20:29:16 ERROR: Caught exception: {'message': 'Future exception was never retrieved', 'exception': EOFError(), 'future': <Future finished exception=EOFError()>}
ble2mqtt_1     | 2022-05-22 20:29:16 ERROR: Future exception was never retrieved
ble2mqtt_1     | future: <Future finished exception=EOFError()>
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 365, in _message_reader
ble2mqtt_1     |     if self._unmarshaller.unmarshall():
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/dbus_next/_private/unmarshaller.py", line 304, in unmarshall
ble2mqtt_1     |     self._unmarshall()
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/dbus_next/_private/unmarshaller.py", line 243, in _unmarshall
ble2mqtt_1     |     self.read(16, prefetch=True)
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/dbus_next/_private/unmarshaller.py", line 91, in read
ble2mqtt_1     |     raise EOFError()
ble2mqtt_1     | EOFError
ble2mqtt_1     | 2022-05-22 20:29:16 INFO: Shutting down...
ble2mqtt_1     | 2022-05-22 20:29:16 INFO: Closing ble2mqtt service
ble2mqtt_1     | 2022-05-22 20:29:16 INFO: Cancelling 6 outstanding tasks
ble2mqtt_1     | 2022-05-22 20:29:16 ERROR: Unexpected exception while cancelling tasks! <Task finished name='Task-2' coro=<Ble2Mqtt._connect_forever() done, defined at /root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py:956> exception=ConnectionClosedError()>
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 960, in _connect_forever
ble2mqtt_1     |     mqtt_connection = await self._mqtt_client.connect(
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 204, in connect
ble2mqtt_1     |     self._reader, self._writer = await aio.open_connection(
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/streams.py", line 52, in open_connection
ble2mqtt_1     |     transport, _ = await loop.create_connection(
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1050, in create_connection
ble2mqtt_1     |     sock = await self._connect_sock(
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 961, in _connect_sock
ble2mqtt_1     |     await self.sock_connect(sock, address)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 499, in sock_connect
ble2mqtt_1     |     return await fut
ble2mqtt_1     | asyncio.exceptions.CancelledError
ble2mqtt_1     | 
ble2mqtt_1     | During handling of the above exception, another exception occurred:
ble2mqtt_1     | 
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 59, in cancel_tasks
ble2mqtt_1     |     await t
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 984, in _connect_forever
ble2mqtt_1     |     await self._mqtt_client.publish(
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 289, in publish
ble2mqtt_1     |     self._raise_if_not_connected()
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 354, in _raise_if_not_connected
ble2mqtt_1     |     raise ConnectionClosedError()
ble2mqtt_1     | aio_mqtt.exceptions.ConnectionClosedError
ble2mqtt_1     | 2022-05-22 20:29:16 ERROR: Task raises exception while cancelling parent coroutine that waits for it <Task finished name='Task-2' coro=<Ble2Mqtt._connect_forever() done, defined at /root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py:956> exception=ConnectionClosedError()>
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 73, in run_tasks_and_cancel_on_first_return
ble2mqtt_1     |     done, pending = await aio.wait(tasks, return_when=return_when)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 413, in wait
ble2mqtt_1     |     return await _wait(fs, timeout, return_when, loop)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 525, in _wait
ble2mqtt_1     |     await waiter
ble2mqtt_1     | asyncio.exceptions.CancelledError
ble2mqtt_1     | 
ble2mqtt_1     | During handling of the above exception, another exception occurred:
ble2mqtt_1     | 
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 82, in run_tasks_and_cancel_on_first_return
ble2mqtt_1     |     t.result()
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 59, in cancel_tasks
ble2mqtt_1     |     await t
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 984, in _connect_forever
ble2mqtt_1     |     await self._mqtt_client.publish(
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 289, in publish
ble2mqtt_1     |     self._raise_if_not_connected()
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 354, in _raise_if_not_connected
ble2mqtt_1     |     raise ConnectionClosedError()
ble2mqtt_1     | aio_mqtt.exceptions.ConnectionClosedError
ble2mqtt_1     | 2022-05-22 20:29:16 WARNING: Error on MQTT  disconnecting: ConnectionClosedError()
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/__main__.py", line 108, in amain
ble2mqtt_1     |     await service.start()
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 762, in start
ble2mqtt_1     |     result = await run_tasks_and_cancel_on_first_return(
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 73, in run_tasks_and_cancel_on_first_return
ble2mqtt_1     |     done, pending = await aio.wait(tasks, return_when=return_when)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 413, in wait
ble2mqtt_1     |     return await _wait(fs, timeout, return_when, loop)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/tasks.py", line 525, in _wait
ble2mqtt_1     |     await waiter
ble2mqtt_1     | asyncio.exceptions.CancelledError
ble2mqtt_1     | 
ble2mqtt_1     | During handling of the above exception, another exception occurred:
ble2mqtt_1     | 
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/runners.py", line 44, in run
ble2mqtt_1     |     return loop.run_until_complete(main)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
ble2mqtt_1     |     return future.result()
ble2mqtt_1     | asyncio.exceptions.CancelledError
ble2mqtt_1     | 
ble2mqtt_1     | During handling of the above exception, another exception occurred:
ble2mqtt_1     | 
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/bin/ble2mqtt", line 8, in <module>
ble2mqtt_1     |     sys.exit(main())
ble2mqtt_1     |   File "/root/.local/lib/python3.9/site-packages/ble2mqtt/__main__.py", line 140, in main
ble2mqtt_1     |     aio.run(amain(config), debug=(config['log_level'].upper() == 'DEBUG'))
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/runners.py", line 47, in run
ble2mqtt_1     |     _cancel_all_tasks(loop)
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/runners.py", line 63, in _cancel_all_tasks
ble2mqtt_1     |     loop.run_until_complete(
ble2mqtt_1     |   File "/usr/local/lib/python3.9/asyncio/base_events.py", line 645, in run_until_complete
ble2mqtt_1     |     raise RuntimeError('Event loop stopped before Future completed.')
ble2mqtt_1     | RuntimeError: Event loop stopped before Future completed.

DBus memory leak

Hello @devbis,

thank you for your efforts to maintain this great module to handle BLE sensor data.

I have a problem with DBus: it is filling my memory massively (until the system dies) when using ble2mqtt!

I found this thread that describes the problem pretty well, but unfortunately I can't transfer the solution to your code:
https://stackoverflow.com/questions/66465459/active-ble-scanning-bluez-issue-with-dbus

The cause of the problem seems to be that the Bluetooth stack is constantly searching for devices.

Do you have a suggestion on how to tweak the code like described on stackoverflow?

Thanks and best regards,
Juergen

Cannot install on Xiaomi DGNWG05LM with OpenWRT

After this command:
pip3 install "bleak>=0.11.0"
I see the following output:

root@DGNWG05LM:~# pip3 install "bleak>=0.11.0"
Collecting bleak>=0.11.0
  Downloading bleak-0.21.1-py3-none-any.whl.metadata (5.3 kB)
Collecting async-timeout<5,>=3.0.0 (from bleak>=0.11.0)
  Downloading async_timeout-4.0.3-py3-none-any.whl.metadata (4.2 kB)
Collecting dbus-fast<3,>=1.83.0 (from bleak>=0.11.0)
  Downloading dbus_fast-2.12.0.tar.gz (68 kB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 68.8/68.8 kB 376.7 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting typing-extensions>=4.7.0 (from bleak>=0.11.0)
  Downloading typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB)
Downloading bleak-0.21.1-py3-none-any.whl (137 kB)
   โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 137.8/137.8 kB 1.1 MB/s eta 0:00:00
Downloading async_timeout-4.0.3-py3-none-any.whl (5.7 kB)
Downloading typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Building wheels for collected packages: dbus-fast
  error: subprocess-exited-with-error

  ร— Building wheel for dbus-fast (pyproject.toml) did not run successfully.
  โ”‚ exit code: 1
  โ•ฐโ”€> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for dbus-fast (pyproject.toml) ... error
  ERROR: Failed building wheel for dbus-fast
Failed to build dbus-fast
ERROR: Could not build wheels for dbus-fast, which is required to install pyproject.toml-based projects

BM2 Bluetooth battery logger

For several years I use several bluetooth Car battery loggers. It would be very nice if these can also be implemented in this ble2mqtt because then I can add the battery devices to my Domoticz system and monitor them more active. The hard part is that I'm no programmer so I do not have the knowledge to implement this. Hoping somebody is willing to help me with this.
There is already some related decoding info done, this can be found here.

Data received and immediately lost in Home Assistant

I am trying to feed temperature and humidity data from a Xiaomi LYWSD03MMC BLE device into Home Assistant via MQTT.
In principle, the ble2mqtt script seems to work as expected. It connects to the MQTT broker (Mosquitto) in the local network. It further connects to the Xiaomi BLE device periodically and reads out temperature and humidity data. See excerpt from the log below:

INFO:ble2mqtt.__main__:Starting BLE2MQTT version 0.1.0a47
INFO:ble2mqtt.ble2mqtt:Connected to mosquitto.valais
...
INFO:ble2mqtt.devices.base:Connected to A4:C1:38:7B:70:5D
INFO:ble2mqtt.devices.base:[Xiaomi_LYWSD03MMC_a4c1387b705d] send state=SensorState(battery=100, temperature=21.62, humidity=53)

This is the corresponding configuration file /etc/ble2mqtt.json:

{
    "mqtt_host": "<host>",
    "mqtt_port": 1883,
    "mqtt_user": "<user>",
    "mqtt_password": "<password>",
    "base_topic": "ble2mqtt1",
    "log_level": "INFO",
    "devices": [
        {
            "address": "A4:C1:38:7B:70:5D",
            "type": "xiaomilywsd",
            "key": "<key>"
        }
    ]
}

When I check in Home Assistant, the device appears in the MQTT integration, however, temperature and humidity sensor readings are indicated as not available. Sometimes, sensor readings flash up in Lovelace or the MQTT integration. However, data disappears immediately again and is not shown in sensor trend graphs.

I am using Home Assistant version 2021.12.10 with the default MQTT integration. For Mosquitto, I am using the docker image eclipse-mosquitto:latest. The setup works flawlessly in combination with zigbee2mqtt.

What could be the cause for the observed behaviour?

Support for Generic iTag buttons

I'm trying to add support for these cheap BLE button tags but I'm struggling with what needs to be defined in a "protocol" vs a "device".
They're a basic presence device but with a couple of extra features once connected:

  1. Battery percentage is a readable characteristic (some of them allow it to be notified, too)
  2. There's an "alert" characteristic that makes the device beep depending on what's written to it.
  3. There's a button that can be subscribed to to get notifications when it is clicked.

(1) seems like a straightforward sensor, (2) I'm not quite sure, but I'd imagine this could be a "select" or "switch" domain device. (3) seems the weirdest because the state is always off when read directly, and it sends an event whenever it's pressed.
Any guidance or documentation I'm missing for these?

Systemd unit file for start of ble2mqtt at boot time

Not a bug, but possibly an addition for the README. I run ble2mqtt on a Raspberry Pi Zero W with RaspbianOS (Debian). To start ble2mqtt automatically at boot time I have created the following systemd unit file:

/etc/systemd/system/ble2mqtt.service

[Unit]
Description=ble2mqtt bridge

[Service]
Type=Simple
ExecStart=/usr/local/bin/ble2mqtt
User=ble2mqtt
Group=ble2mqtt
Wants=bluetooth.target

[Install]
WantedBy=multi-user.target

I am not 100% certain whether the "Wants=" statement is truly required, but at least it does not harm.
The user and group should match the owner and group of the configuration file /etc/ble2mqtt.json.

Aftewards you simply have to enable and start the service:

$ sudo systemctl enable ble2mqtt
$ sudo systemctl start ble2mqtt

Autorun

How to add the component to autorun? In /etc/init.d, for example

How to fetch Ensto thermostat key

Hi, I'm trying to add Ensto thermostat to ble2mqtt, but having challenges due to limited knowledge..

In the instructions it's advised to first pair the thermostat, which I've done. After that's done, instructions adviseto check the log files for the thermostat key.

My issue is that I'm not sure from where these logs are / how can I check the key info from a log file? I've tried various things, searched hours, but nothing..

I am running home assistant 2022.8.5 in RPI4 (Home Assistant Operating System 8.5).

Exceptions being thrown about dbus_fast authentication failure

Environment

RasPi 4 running DietPi v8.20.1 and running in Docker accessing hci0
Attempting to access Xiaomi LYWSD03MMC with custom ATC firmware (xiaomilywsd_atc), by adding their individual MAC addresses in the config. MAC addresses gained from HA instance running ble_monitor custom integration, which is still working fine.

Description

Built the container as guided in the readme and that completed without issues. Running the container with default docker compose listed threw an error about /var/run/dbus permission denied, and stating that /run/dbus/system_bus_socket: no such file or directory. Adding the line for volume mount /var/run/dbus:/var/run/dbus, mounting the dbus folder into the container allows access to the dbus but new exception is thrown: dbus_fast.errors.AuthError: authentication failed: REJECTED: ['EXTERNAL']

The service is pushing messages to the MQTT broker, listing the four devices I put into config however stating their availability is offline.

Stacktrace

ble2mqtt    | 2023-09-24 05:24:38 INFO: Starting BLE2MQTT version 0.2.0, bleak 0.21.1, adapter hci0
ble2mqtt    | 2023-09-24 05:24:38 INFO: Connected to 10.0.1.2
ble2mqtt    | 2023-09-24 05:24:38 ERROR: <Task finished name='Task-12' coro=<Ble2Mqtt.scan_devices_task() done, defined at /home/rootless/.local/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py:194> exception=AuthError("authentication failed: REJECTED: ['EXTERNAL']")> stopped unexpectedly
ble2mqtt    | Traceback (most recent call last):
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 209, in scan_devices_task
ble2mqtt    |     await aio.wait_for(scanner.start(), 10)
ble2mqtt    |   File "/usr/local/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
ble2mqtt    |     return fut.result()
ble2mqtt    |            ^^^^^^^^^^^^
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/bleak/__init__.py", line 198, in start
ble2mqtt    |     await self._backend.start()
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/bleak/backends/bluezdbus/scanner.py", line 168, in start
ble2mqtt    |     manager = await get_global_bluez_manager()
ble2mqtt    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 1046, in get_global_bluez_manager
ble2mqtt    |     await instance.async_init()
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/bleak/backends/bluezdbus/manager.py", line 236, in async_init
ble2mqtt    |     await bus.connect()
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/dbus_fast/aio/message_bus.py", line 224, in connect
ble2mqtt    |     await self._authenticate()
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/dbus_fast/aio/message_bus.py", line 507, in _authenticate
ble2mqtt    |     response = self._auth._receive_line(await self._auth_readline())
ble2mqtt    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ble2mqtt    |   File "/home/rootless/.local/lib/python3.11/site-packages/dbus_fast/auth.py", line 99, in _receive_line
ble2mqtt    |     raise AuthError(f"authentication failed: {response.value}: {args}")
ble2mqtt    | dbus_fast.errors.AuthError: authentication failed: REJECTED: ['EXTERNAL']
ble2mqtt    | 2023-09-24 05:24:38 ERROR: Connection lost. Will retry in 10 seconds.

Configurations

ble2mqtt.json

{
    "mqtt_host": "10.0.1.2",
    "mqtt_port": 1883,
    "mqtt_user": "mosquitto",
    "mqtt_password": "<password>",
    "log_level": "INFO",
    "devices": [
        {
            "address": "A4:C1:38:23:89:22",
            "type": "xiaomilywsd_atc",
            "friendly_name": "bedroom thermometer"
        },
        {
            "address": "A4:C1:38:1A:E1:F5",
            "type": "xiaomilywsd_atc",
            "friendly_name": "guestroom thermometer"
        },
        {
            "address": "A4:C1:38:D2:B5:1A",
            "type": "xiaomilywsd_atc",
            "friendly_name": "study thermometer"
        },
        {
            "address": "A4:C1:38:8B:5F:80",
            "type": "xiaomilywsd_atc",
            "friendly_name": "kitchen thermometer"
        }
    ]
}

Docker compose error

I'm trying to install ble2mqtt on docker but I get the error messages below. Googled already, most answers point in the direction of disk space but that seems (not 100% sure because it also can be the virtual volume in docker but can't find how to check that) not the problem.

pi@P1-Logger:/home/ble2mqtt $ docker build -t ble2mqtt:dev .
[+] Building 7.9s (7/14)
 => [internal] load .dockerignore                                                                                                                                                                    0.1s
 => => transferring context: 2B                                                                                                                                                                      0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.1s
 => => transferring dockerfile: 875B                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/python:3.9-slim                                                                                                                                   1.8s
 => [internal] load build context                                                                                                                                                                    0.2s
 => => transferring context: 2.10kB                                                                                                                                                                  0.0s
 => CACHED [app 1/5] FROM docker.io/library/python:3.9-slim@sha256:5192f07402cbe8b0267eef13085b321d50ab8aaac79d2f0657f96810c3f4555c                                                                  0.0s
 => ERROR [builder 2/6] RUN apt-get update &&     apt-get install gcc git -y &&     apt-get clean                                                                                                    5.8s
 => ERROR [app 2/5] RUN apt-get update &&     apt-get install bluez -y &&     apt-get clean                                                                                                          5.8s
------
 > [builder 2/6] RUN apt-get update &&     apt-get install gcc git -y &&     apt-get clean:
#6 3.436 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#6 3.626 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#6 3.629 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#6 4.277 Err:1 http://deb.debian.org/debian bullseye InRelease
#6 4.277   At least one invalid signature was encountered.
#6 4.818 Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
#6 4.818   At least one invalid signature was encountered.
#6 5.373 Err:3 http://deb.debian.org/debian bullseye-updates InRelease
#6 5.373   At least one invalid signature was encountered.
#6 5.404 Reading package lists...
#6 5.550 W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
#6 5.550 W: GPG error: http://deb.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian-security bullseye-security InRelease' is not signed.
#6 5.550 W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
#6 5.550 E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
------
------
 > [app 2/5] RUN apt-get update &&     apt-get install bluez -y &&     apt-get clean:
#5 3.473 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#5 3.599 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#5 3.599 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#5 4.218 Err:1 http://deb.debian.org/debian bullseye InRelease
#5 4.218   At least one invalid signature was encountered.
#5 4.779 Err:2 http://deb.debian.org/debian-security bullseye-security InRelease
#5 4.779   At least one invalid signature was encountered.
#5 5.327 Err:3 http://deb.debian.org/debian bullseye-updates InRelease
#5 5.327   At least one invalid signature was encountered.
#5 5.356 Reading package lists...
#5 5.469 W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
#5 5.469 W: GPG error: http://deb.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian-security bullseye-security InRelease' is not signed.
#5 5.469 W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
#5 5.469 E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
------
process "/bin/sh -c apt-get update &&     apt-get install bluez -y &&     apt-get clean" did not complete successfully: exit code: 100
```

Support for Roidmi NEX2 Pro

Hi!

The Roidmi cordless vacuum cleaners use BLE to communicate with the Xiaomi Home app, they need a connection to work. I have tried to get data via the method what works for the Mi Kettle (device ID), but I think that this device uses different method for authorization / encryption. I have extracted some data from the Xiaomi Cloud, the device ID is apparently 2145, but I am not sure about that, it did not work. There is also a token (24 chars. long) and a BLE key (32 chars. long).

The communication is described in the Xiaomi Home app plugin's source code, which is available here:
https://home.miot-spec.com/download-plugin/roidmi.cleaner.v382

The Bluetooth function can be used to view usage data, battery life, battery standby time and expected usage time, read error messages, set default motor speed and reset filter life.

UPD: extracted javascript https://gist.githubusercontent.com/devbis/8d43f97d1bf47831e38ed31d35f0529a/raw/roidmi.cleaner.v382.js

Presence as device_tracker

Hi! It would be cool if presence was device_tracker instead of binary_sensor to be able to add it to persons.
Therefore, it could be possible to add several device_trackers, such as phone, watch, etc, to one person to determine his presence.
I have tried to do it myself by simply replacing binary_sensor with device_tracker, but apparently Python is not my strong suit.

There is a description of PRESENCE DETECTION in MQTT Discovery:
https://www.home-assistant.io/docs/mqtt/discovery/#presence-detection-device-tracker

Thanks in advance!

Request - MQTT message will be published with the presence status 'OFF'

I use a cheap BLE tag running in passive mode to determine presence.

  {
         "address": "FF:FF:C4:0C:EA:88",
         "type": "presence"
     }

When I turn the tag on to 'on' mode, the presence status updates almost instantly.

2023-08-30 11:36:52 INFO: [Generic_iTAG_____________ffffc40cea88] send state=SensorState(presence=True, last_check=datetime.datetime(2023, 8, 30, 11, 36, 50, 780660)) 


 => **ble2mqtt/ffffc40cea88 {"presence": "ON", "device_tracker": "home", "linkquality": 48}**

Desired behavior: When the tag is turned off, if it's not detected after 3 consecutive tag scans, a MQTT message will be published with the presence status 'OFF'. This approach will promptly update the absence status of the tag.

2023-08-30 11:39:36 ERROR: [Generic_ffffc40cea88] connection problem, attempts=3
 
 => **ble2mqtt/ffffc40cea88 {"presence": "OFF", "device_tracker": "home", "linkquality": 0}**

Please take your time to further elaborate on this requirement. Much appreciated!

Python 3.10

INFO:ble2mqtt.__main__:Starting BLE2MQTT version 0.1.1
ble2mqtt_1     | Traceback (most recent call last):
ble2mqtt_1     |   File "/root/.local/bin/ble2mqtt", line 8, in <module>
ble2mqtt_1     |     sys.exit(main())
ble2mqtt_1     |   File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 140, in main
ble2mqtt_1     |     aio.run(amain(config), debug=(config['log_level'].upper() == 'DEBUG'))
ble2mqtt_1     |   File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
ble2mqtt_1     |     return loop.run_until_complete(main)
ble2mqtt_1     |   File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
ble2mqtt_1     |     return future.result()
ble2mqtt_1     |   File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 100, in amain
ble2mqtt_1     |     service.register(
ble2mqtt_1     |   File "/root/.local/lib/python3.10/site-packages/ble2mqtt/ble2mqtt.py", line 769, in register
ble2mqtt_1     |     device = device_class(*args, **kwargs)
ble2mqtt_1     |   File "/root/.local/lib/python3.10/site-packages/ble2mqtt/devices/cover_am43.py", line 66, in __init__
ble2mqtt_1     |     super().__init__(*args, **kwargs)
ble2mqtt_1     |   File "/root/.local/lib/python3.10/site-packages/ble2mqtt/protocols/base.py", line 15, in __init__
ble2mqtt_1     |     self._ble_queue = aio.Queue(loop=self._loop)
ble2mqtt_1     |   File "/usr/local/lib/python3.10/asyncio/queues.py", line 34, in __init__
ble2mqtt_1     |     super().__init__(loop=loop)
ble2mqtt_1     |   File "/usr/local/lib/python3.10/asyncio/mixins.py", line 17, in __init__
ble2mqtt_1     |     raise TypeError(
ble2mqtt_1     | TypeError: As of 3.10, the *loop* parameter was removed from Queue() since it is no longer necessary

Not working on OpenWRT 22.03.2 in Xiaomi Gateway DGNWG05LM

I see BT devices by Discovery:

root@Xiaomi_Gateway:~# bluetoothctl
Agent registered
[CHG] Controller 58:B3:FC:38:72:FB Pairable: yes
[DEL] Device A4:06:E9:D5:B4:E0 A4-06-E9-D5-B4-E0
[DEL] Device 7C:C2:94:17:68:DE 7C-C2-94-17-68-DE
[bluetooth]# scan on
Discovery started
[CHG] Controller 58:B3:FC:38:72:FB Discovering: yes
[NEW] Device 7C:C2:94:17:68:DE 7C-C2-94-17-68-DE
[DEL] Device A4:C1:38:39:CE:A4 LYWSD03MMC
[NEW] Device A4:C1:38:39:CE:A4 LYWSD03MMC
[NEW] Device A4:C1:38:73:9E:D5 LYWSD03MMC
[CHG] Device 7C:C2:94:17:68:DE RSSI: -82
[CHG] Device A4:C1:38:73:9E:D5 RSSI: -50
[NEW] Device 54:EF:44:31:3B:3E 54-EF-44-31-3B-3E
[CHG] Device A4:C1:38:AC:C7:90 RSSI: -90
[CHG] Device 54:EF:44:31:3B:3E RSSI is nil
[DEL] Device 54:EF:44:31:3B:3E 54-EF-44-31-3B-3E
[CHG] Device A4:C1:38:AC:C7:90 RSSI is nil
[CHG] Device A4:C1:38:73:9E:D5 RSSI is nil
[CHG] Device A4:C1:38:39:CE:A4 RSSI is nil
[CHG] Device 7C:C2:94:17:68:DE RSSI is nil
[CHG] Controller 58:B3:FC:38:72:FB Powered: no
[CHG] Controller 58:B3:FC:38:72:FB Discovering: no
Agent unregistered
[DEL] Device A4:C1:38:C5:33:7E A4-C1-38-C5-33-7E
[DEL] Device A4:C1:38:AC:C7:90 LYWSD03MMC
[DEL] Device 7C:C2:94:17:68:DE 7C-C2-94-17-68-DE
[DEL] Device A4:C1:38:39:CE:A4 LYWSD03MMC
[DEL] Device A4:C1:38:73:9E:D5 LYWSD03MMC
[DEL] Controller 58:B3:FC:38:72:FB BlueZ 5.64 [default]
Agent registered
[bluetooth]# exit

But not working:

root@Xiaomi_Gateway:~# /etc/init.d/ble2mqtt stop
root@Xiaomi_Gateway:~# BLE2MQTT_CONFIG=/etc/ble2mqtt.json ble2mqtt
2023-01-14 15:23:08 INFO: Starting BLE2MQTT version 0.1.5
2023-01-14 15:23:08 INFO: Connected to 192.168.1.50
2023-01-14 15:23:08 WARNING: Restarting bluetoothd...
2023-01-14 15:23:17 WARNING: Restarting bluetoothd finished
2023-01-14 15:23:18 WARNING: Error while connecting to Xiaomi_Temp_sklad, [org.bluez.Error.Failed] No discovery started BleakDBusError('org.bluez.Error.Failed', 'No discovery started'), failure_count=1
2023-01-14 15:23:20 WARNING: Error while connecting to Xiaomi_Temp_kuhnya, [org.bluez.Error.InProgress] Operation already in progress BleakDBusError('org.bluez.Error.InProgress', 'Operation already in progress'), failure_count=1
2023-01-14 15:23:20 WARNING: Error while connecting to Xiaomi_Temp_dom, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=1
2023-01-14 15:23:20 WARNING: Error while connecting to Xiaomi_Temp_ulica, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=1
2023-01-14 15:23:21 WARNING: Error while connecting to Xiaomi_Temp_zal, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=1
2023-01-14 15:23:21 WARNING: Error while connecting to Xiaomi_7cc2941768dc, [org.bluez.Error.NotReady] Resource Not Ready BleakDBusError('org.bluez.Error.NotReady', 'Resource Not Ready'), failure_count=1

Config:

root@Xiaomi_Gateway:~# cat /etc/ble2mqtt.json
{
    "mqtt_host": "192.168.1.50",
    "mqtt_port": 1883,
    "mqtt_user": "mqtt",
    "mqtt_password": "mqtt",
    "devices": [
        {
            "address": "A4:C1:38:CA:99:FE",
            "type": "xiaomilywsd",
            "friendly_name": "Temp sklad"
        },
        {
            "address": "A4:C1:38:39:CE:A4",
            "type": "xiaomilywsd",
            "friendly_name": "Temp kuhnya"
        },
        {
            "address": "A4:C1:38:C5:33:7E",
            "type": "xiaomilywsd",
            "friendly_name": "Temp dom"
        },
        {
            "address": "A4:C1:38:AC:C7:90",
            "type": "xiaomilywsd",
            "friendly_name": "Temp ulica"
        },
        {
            "address": "A4:C1:38:73:9E:D5",
            "type": "xiaomilywsd",
            "friendly_name": "Temp zal"
        },
        {
            "address": "7c:c2:94:17:68:dc",
            "type": "xiaomilywsd"
        }
    ]
}

image

Not working at OpenLumi 21.02.2 after version 0.1.0a42-1

Good Day.
After version 0.1.0a42-1 ble2mqtt not starting at xiaomi gateway with OpenLumi 21.02.2 with error:

root@OpenWrt:/usr/bin# BLE2MQTT_CONFIG=/etc/ble2mqtt.json ble2mqtt
Traceback (most recent call last):
File "/usr/bin/ble2mqtt", line 33, in
sys.exit(load_entry_point('ble2mqtt==0.1.0a47', 'console_scripts', 'ble2mqtt')())
File "/usr/bin/ble2mqtt", line 25, in importlib_load_entry_point
return next(matches).load()
StopIteration

Downgrade to 0.1.0a42-1 fixes problem

Version 0.1.0a47 incompatible with Python 3.10

As of today the python:slim docker image includes Python 3.10.

The following error appears at container start:

INFO:ble2mqtt.__main__:Starting BLE2MQTT version 0.1.0a47
Traceback (most recent call last):
  File "/root/.local/bin/ble2mqtt", line 8, in <module>
    sys.exit(main())
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 140, in main
    aio.run(amain(config), debug=(config['log_level'].upper() == 'DEBUG'))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 77, in amain
    service = Ble2Mqtt(
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/ble2mqtt.py", line 667, in __init__
    self._mqtt_client = aio_mqtt.Client(
  File "/root/.local/lib/python3.10/site-packages/aio_mqtt/client.py", line 165, in __init__
    self._drain_lock = aio.Lock(loop=self._loop)
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 77, in __init__
    super().__init__(loop=loop)
  File "/usr/local/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary

Downgrading to the python:3.9.9-slim image in the Dockerfile solves the issue

Application crashed with ServerDiedError

Hi,

In docker on raspi I'm getting ServerDiedError:

`May 28 10:17:16 raspberrypi docker[6694]: 2023-05-28 08:17:16 ERROR: Task raises exception while cancelling parent coroutine that waits for it <Task finished name='Task-12' coro=<Sensor.handle() done, defined at /usr/lib/python3.11/site-packages/ble2mqtt/devices/base.py:549

exception=ServerDiedError()>
May 28 10:17:16 raspberrypi docker[6694]: Traceback (most recent call last):
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 74, in run_tasks_and_canc
el_on_first_return
May 28 10:17:16 raspberrypi docker[6694]: done, pending = await aio.wait(tasks, return_when=return_when)
May 28 10:17:16 raspberrypi docker[6694]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/asyncio/tasks.py", line 418, in wait
May 28 10:17:16 raspberrypi docker[6694]: return await _wait(fs, timeout, return_when, loop)
May 28 10:17:16 raspberrypi docker[6694]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/asyncio/tasks.py", line 525, in _wait
May 28 10:17:16 raspberrypi docker[6694]: await waiter
May 28 10:17:16 raspberrypi docker[6694]: asyncio.exceptions.CancelledError
May 28 10:17:16 raspberrypi docker[6694]: During handling of the above exception, another exception occurred:
May 28 10:17:16 raspberrypi docker[6694]: Traceback (most recent call last):
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 83, in run_tasks_and_cancel_on_first_return
May 28 10:17:16 raspberrypi docker[6694]: t.result()
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/devices/base.py", line 551, in handle
May 28 10:17:16 raspberrypi docker[6694]: return await self.handle_passive(*args, **kwargs)
May 28 10:17:16 raspberrypi docker[6694]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/devices/presence.py", line 77, in handle_passive
May 28 10:17:16 raspberrypi docker[6694]: await super().handle_passive(*args, **kwargs)
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/devices/base.py", line 546, in handle_passive
May 28 10:17:16 raspberrypi docker[6694]: await self.do_passive_loop(publish_topic)
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/devices/presence.py", line 93, in do_passive_loop
May 28 10:17:16 raspberrypi docker[6694]: await self._notify_state(publish_topic)
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/devices/base.py", line 518, in _notify_state
May 28 10:17:16 raspberrypi docker[6694]: await publish_topic(
May 28 10:17:16 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 560, in publish_topic_with_availability
May 28 10:17:16 raspberrypi docker[6694]: await self.publish_topic_callback(topic, value)
May 28 10:17:17 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/ble2mqtt/ble2mqtt.py", line 223, in publish_topic_callback
May 28 10:17:17 raspberrypi docker[6694]: await self._mqtt_client.publish(
May 28 10:17:17 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 301, in publish
May 28 10:17:17 raspberrypi docker[6694]: await self._wait((PacketType.PUBACK, packet_id))
May 28 10:17:17 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 367, in _wait
May 28 10:17:17 raspberrypi docker[6694]: return await future
May 28 10:17:17 raspberrypi docker[6694]: ^^^^^^^^^^^^
May 28 10:17:17 raspberrypi docker[6694]: File "/usr/lib/python3.11/site-packages/aio_mqtt/client.py", line 815, in _keepalive_mechanism_task
May 28 10:17:17 raspberrypi docker[6694]: raise ServerDiedError()
May 28 10:17:17 raspberrypi docker[6694]: aio_mqtt.exceptions.ServerDiedError
`

Bleak updated :(

Run new container has result:
ble2mqtt_1 | 2022-08-25 19:35:42 INFO: Connected to 02:F6:21:7E:10:96
ble2mqtt_1 | 2022-08-25 19:35:43 WARNING: Error while connecting to Blind_AM43_02f6217e1096, 'BleakClientBlueZDBus' object has no attribute '_properties' AttributeError("'BleakClientBlueZDBus' object has no attribute '_properties'"), failure_count=1

Old version works fine.

Unable to start docker container

INFO:ble2mqtt.__main__:Starting BLE2MQTT version 0.1.0a44
Traceback (most recent call last):
  File "/root/.local/bin/ble2mqtt", line 8, in <module>
    sys.exit(main())
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 140, in main
    aio.run(amain(config), debug=(config['log_level'].upper() == 'DEBUG'))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/__main__.py", line 77, in amain
    service = Ble2Mqtt(
  File "/root/.local/lib/python3.10/site-packages/ble2mqtt/ble2mqtt.py", line 681, in __init__
    BLUETOOTH_RESTARTING = aio.Lock(loop=self._loop)
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 77, in __init__
    super().__init__(loop=loop)
  File "/usr/local/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Lock() since it is no longer necessary

Look like its related to some recent update in python3.10

Support: Help understanding frequency of updates

Trying this out for the first time, and I had a few questions.

  1. The primary one being how frequently does ble2mqtt check for the presence of the device and its RSSI? I know you can set the threshold of when a device is considered away. However it seems like it is only checking about once per minute.

The next issue pertains to that - as you can see it checked for the Govee from 19:55-19:58 before finally checking at 19:59 for the OnePlus. And there are multiple times that it doesn't check for the OnePlus. This phone is actually paired to bluetoothctl

  1. Can I increase the frequency of these checks?
  2. Can I rename the device in mqtt so that it is not 0xac5f.. I know you can set a friendly name for home assistant, but would like to see in MQTT
2022-12-11 19:55:21 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 18, 3735))
2022-12-11 19:56:22 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 19:57:23 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 19:58:24 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 19:59:11 INFO: [Generic_OnePlus_8T_rays_phone] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 59, 8, 912660))
2022-12-11 19:59:25 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 20:00:12 INFO: [Generic_OnePlus_8T_rays_phone] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 20, 0, 1, 891776))
2022-12-11 20:00:26 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 20:00:40 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=False, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 20:01:13 INFO: [Generic_OnePlus_8T_rays_phone] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 20, 0, 47, 455634))
2022-12-11 20:01:42 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=False, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))
2022-12-11 20:02:14 INFO: [Generic_OnePlus_8T_rays_phone] send state=SensorState(presence=True, last_check=datetime.datetime(2022, 12, 11, 20, 1, 54, 670655))
2022-12-11 20:02:43 INFO: [Generic_Govee_H5051_F895_govee] send state=SensorState(presence=False, last_check=datetime.datetime(2022, 12, 11, 19, 55, 40, 3525))

Bluetooth interface requires periodic reset

I noticed that bluetooth connections have a tendency to fail on one of my Raspberry Pi Zero W running ble2mqtt under RaspbianOS (Debian). Initially, ble2mqtt is able to connect to Xiaomi LYWSD03MMC temperature and humidity sensor devices. After a while, connections always fail and I start to see the following error messages in the log:

...
Jan 21 20:50:52 bridge2 ble2mqtt[327]: WARNING:ble2mqtt.ble2mqtt:Error while connecting to Xiaomi_LYWSD03MMC_a4c138736b80, Device with address A4:C1:38:73:6B:80 was >
Jan 21 20:51:53 bridge2 ble2mqtt[327]: ERROR:ble2mqtt.__main__:Caught exception: {'message': 'Task was destroyed but it is pending!', 'task': <Task pending name='Tas>
Jan 21 20:51:53 bridge2 ble2mqtt[327]: ERROR:asyncio:Task was destroyed but it is pending!
Jan 21 20:51:53 bridge2 ble2mqtt[327]: task: <Task pending name='Task-256' coro=<BleakClientBlueZDBus._disconnect_monitor() running at /usr/local/lib/python3.9/dist->
Jan 21 20:51:53 bridge2 ble2mqtt[327]: INFO:ble2mqtt.__main__:Ignore this exception.

After reset of the bluetooth interface, everything seems to work again until the next failure:

$ sudo hciconfig hci0 reset

Any idea, what might be causing this problem? Obviously, I am interested in a stable setup that does not require any manual interventions.

If sensor is out of range the MQTT msg still sends the last value

I have been using Xiaomi LYWSD_ATC sensor for a while and noticed a problem. When the sensor is out of range or runs out of battery, the MQTT message still sends the last value - an unchanged value to the MQTT server.
If the sensor is within range, everything works fine.

Please take some time to fix this. Thank you.

Here is apart of log

2023-10-13 08:19:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:20:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:21:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:22:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:23:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:24:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:25:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:26:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:27:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:28:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:29:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:30:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:31:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:32:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:33:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:34:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:35:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:36:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:37:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:38:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:39:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:40:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:41:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:42:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:43:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:44:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:45:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:46:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:47:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:48:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:49:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)
2023-10-13 08:50:43 INFO: [Xiaomi_ATC_C21074_a4c138c21074] send state=SensorState(battery=68, temperature=30.2, humidity=77, sends_custom=False)

Illustrated when using ble2mqtt with Domoticz
image

Cannot connect to MQTT broker with SSL

While trying to connect to a MQTT broker (Mosquitto) with encryption and certificate verification the following error occurs:

INFO:ble2mqtt.__main__:Starting BLE2MQTT version 0.1.0a47
ERROR:ble2mqtt.ble2mqtt:Connection lost. Will retry in 10 seconds.
Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/aio_mqtt/client.py", line 202, in connect
    self._reader, self._writer = await aio.open_connection(
  File "/usr/local/lib/python3.9/asyncio/streams.py", line 52, in open_connection
    transport, _ = await loop.create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('<MQTT_BROKER_IP>', 8883)

My ble2mqtt.json config is as follows:

{
    "mqtt_host": "<MQTT_BROKER_ADDRESS>",
    "mqtt_port": 8883,
    "mqtt_user": "<USER>",
    "mqtt_password": "<PASS>",
    "base_topic": "ble2mqtt",
    "mqtt_prefix": "b2m_",
    "log_level": "INFO",
    "devices": [
        {
            "address": "<MAC>",
            "friendly_name": "Avea",
            "type": "avea_rgbw"
        }
    ]
}

Where should I configure the certificate to be used?

Running in Docker

I need some help to run ble2mqtt in Docker, here's what I tried:

docker run \
--rm \
--privileged \
--net=host \
--cap-add SYS_PTRACE,SYS_ADMIN,NET_ADMIN,NET_RAW \
-e TZ=Europe/Bucharest \
-v /etc/timezone:/etc/timezone:ro \
-v /etc/localtime:/etc/localtime:ro \
-v `pwd`/config.json:/etc/ble2mqtt.json:z \
ble2mqtt:dev

My conf has xiaomihtv1 devices with passive set to either false or true.

Results in

INFO:ble2mqtt.ble2mqtt:Connected to 127.0.0.1
ERROR:ble2mqtt.ble2mqtt:Unhandled exception during connecting
Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 619, in _connect_forever
    await self._run_device_tasks(connect_result.disconnect_reason)
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 593, in _run_device_tasks
    t.result()
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 380, in manage_device
    disconnect_fut = await device.connect()
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/devices/base.py", line 182, in connect
    await self.client.connect()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 121, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 166, in find_device_by_address
    async with cls(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 63, in __aenter__
    await self.start()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 78, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 86, in __init__
    self._setup_socket()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 569, in _setup_socket
    raise err
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 542, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory
Traceback (most recent call last):
  File "/root/.local/bin/ble2mqtt", line 8, in <module>
    sys.exit(main())
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/__main__.py", line 62, in main
    loop.run_until_complete(server.close())
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 113, in close
    await self.stop_task(task)
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 105, in stop_task
    await task
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 380, in manage_device
    disconnect_fut = await device.connect()
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/devices/base.py", line 182, in connect
    await self.client.connect()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 121, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 166, in find_device_by_address
    async with cls(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 63, in __aenter__
    await self.start()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 78, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 86, in __init__
    self._setup_socket()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 569, in _setup_socket
    raise err
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 542, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Ble2Mqtt.manage_device() done, defined at /root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py:373> exception=FileNotFoundError(2, 'No such file or directory')>
Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 380, in manage_device
    disconnect_fut = await device.connect()
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/devices/base.py", line 182, in connect
    await self.client.connect()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 121, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 166, in find_device_by_address
    async with cls(
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 63, in __aenter__
    await self.start()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 78, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 86, in __init__
    self._setup_socket()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 569, in _setup_socket
    raise err
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 542, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-10' coro=<Ble2Mqtt.scan_devices_task() done, defined at /root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py:557> exception=FileNotFoundError(2, 'No such file or directory')>
Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/ble2mqtt/ble2mqtt.py", line 560, in scan_devices_task
    async with BleakScanner() as scanner:
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/scanner.py", line 63, in __aenter__
    await self.start()
  File "/root/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/scanner.py", line 78, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 86, in __init__
    self._setup_socket()
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 569, in _setup_socket
    raise err
  File "/root/.local/lib/python3.9/site-packages/dbus_next/message_bus.py", line 542, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

I'm running this on Raspberry Pi 4, Raspbian, running ble2mqtt in an venv works. Any idea what else I need to share with the container?

Thanks,
Nicolae

Logger severity level

Could you please add a config option in json to adjust the severity level? My sensors are causing too many INFO lines of logs.

Passive support

Hello,

I was thinking of developing something similar to your project but with passive support since most devices advertise their state from time to time. There's already a project that implements passive BLE support in Home Assistant [0] but it's too tied to HA and I would like to use it independently (on a separate device).
Do you have any plan to support passive readings?

Currently I'm using ESPHome for this [1], but I would like to reduce the number of devices :)

Regards,
Nicolae
[0] custom-components/ble_monitor#220
[1] https://esphome.io/components/sensor/xiaomi_ble.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.