fhempy: ble_monitor (Bluetooth Low Energy)

Begonnen von dominik, 15 Februar 2022, 23:36:47

Vorheriges Thema - Nächstes Thema

Nighthawk

Hallo Dominik,
scheinbar ist das integrierte BT Modul meines Rechners höchst instabil.
Ich habe jetzt ein USB Dongle bestellt, mit der Hoffnung dass es stabil wird.

dominik

Ja, die alten RPis sind nicht optimal. Ich hatte mir einen RPi4 zugelegt, da läuft BT relativ stabil.

Wenn du den Dongle hast, vergiss nicht hci_device umzustellen.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

Hallo Dominik,

nach einem Update meines Ubuntus auf 22.04 bekomme ich gerade ble_monitor nicht mehr zum laufen.

Mein HCI hat sich zu HCI1 geändert und beim Versuch dies in MiScale zu ändern, bekomme ich folgende Fehlermeldeung:

Failed to execute function Attr: Traceback (most recent call last):
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 262, in handle_function
    ret = await self.execute_function(hash, fhem_reply_done, nmInstance)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 333, in execute_function
    ret = await asyncio.wait_for(
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/generic.py", line 169, in Attr
    return await utils.handle_attr(self._conf_attr, self, hash, args, argsh)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/utils.py", line 69, in handle_attr
    return await fct_call(hash)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/miscale/miscale.py", line 184, in set_attr_hci_interface
    self.blemonitor.unregister_device(self)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 149, in unregister_device
    self.update_hci_interface(fhemdevice.hci())
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 131, in update_hci_interface
    self.config[CONF_BT_INTERFACE].append(BT_INTERFACES[fhem_dev.hci()])
KeyError: 0



und auch beim ble_monitor bekomme ich eine Fehlermeldung:

Failed to execute function Attr: Traceback (most recent call last):
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 262, in handle_function
    ret = await self.execute_function(hash, fhem_reply_done, nmInstance)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 333, in execute_function
    ret = await asyncio.wait_for(
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/generic.py", line 169, in Attr
    return await utils.handle_attr(self._conf_attr, self, hash, args, argsh)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/utils.py", line 69, in handle_attr
    return await fct_call(hash)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/ble_monitor.py", line 66, in set_attr_generic
    self.blemonitor.unregister_device(self)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 149, in unregister_device
    self.update_hci_interface(fhemdevice.hci())
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 131, in update_hci_interface
    self.config[CONF_BT_INTERFACE].append(BT_INTERFACES[fhem_dev.hci()])
KeyError: 0

dominik

Poste bitte den Output von
sudo hciconfig -a
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

sudo hciconfig -a
hci1: Type: Primary  Bus: USB
BD Address: E8:48:B8:C8:20:00  ACL MTU: 1021:6  SCO MTU: 255:12
UP RUNNING
RX bytes:4623 acl:0 sco:0 events:298 errors:0
TX bytes:35815 acl:0 sco:0 commands:268 errors:0
Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: PERIPHERAL ACCEPT
Name: 'PC'
Class: 0x6c0104
Service Classes: Rendering, Capturing, Audio, Telephony
Device Class: Computer, Desktop workstation
HCI Version: 5.1 (0xa)  Revision: 0x9a9
LMP Version: 5.1 (0xa)  Subversion: 0x8a6b
Manufacturer: Realtek Semiconductor Corporation (93)

dominik

Hast du den lokalen BT Adapter deaktiviert? Nur hci1 ohne hci0 zu haben ist eigenartig  ???
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

#66
Das Abschalten im Bios ist leider wirkungslos, im OS ist aber die Interne Schnittstelle nicht zu sehen:

hciconfig --all
hci1: Type: Primary  Bus: USB
BD Address: E8:48:B8:C8:20:00  ACL MTU: 1021:6  SCO MTU: 255:12
UP RUNNING
RX bytes:4900 acl:0 sco:0 events:301 errors:0
TX bytes:35824 acl:0 sco:0 commands:271 errors:0
Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: PERIPHERAL ACCEPT
Name: 'alex-L55'
Class: 0x6c0104
Service Classes: Rendering, Capturing, Audio, Telephony
Device Class: Computer, Desktop workstation
HCI Version: 5.1 (0xa)  Revision: 0x9a9
LMP Version: 5.1 (0xa)  Subversion: 0x8a6b
Manufacturer: Realtek Semiconductor Corporation (93)



EDIT:

ich habe jetzt mal alle anderen EInträge ausser dem E8:48:B8:C8:20:00 im Ordner /var/lib/bluetooth/ gelöscht und nach einem Neustart wurde mein BT Device jetzt HCI0.
Leider bekomme ich weiterhin einen Fehler im ble_monitor, siehe unten.
Kann es daran liegen dass aioblescan nur daten liefert wenn es mit Rootrechten ausgeführt wird?
Wie bekomme ich den fhem user dazu auf die HCI Schnittestelle zugreifen zu können?


2022-05-15 19:41:07,422 - ERROR    - Feuermelder_Galerie: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
Exception in thread Thread-7:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 644, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2022-05-15 19:41:11,101 - ERROR    - fhempy.lib.fhem_pythonbinding: Failed to execute function Attr: Traceback (most recent call last):
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 262, in handle_function
    ret = await self.execute_function(hash, fhem_reply_done, nmInstance)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/fhem_pythonbinding.py", line 333, in execute_function
    ret = await asyncio.wait_for(
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/generic.py", line 169, in Attr
    return await utils.handle_attr(self._conf_attr, self, hash, args, argsh)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/utils.py", line 69, in handle_attr
    return await fct_call(hash)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/ble_monitor.py", line 67, in set_attr_generic
    self.blemonitor.register_device(self)
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 121, in register_device
    self.update_hci_interface(fhemdevice.hci())
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/blemonitor.py", line 131, in update_hci_interface
    self.config[CONF_BT_INTERFACE].append(BT_INTERFACES[fhem_dev.hci()])
KeyError: '0'





Danke und Gruß
Alex

dominik

Poste bitte nochmals hciconfig -a, weil das sieht aus, als wäre es noch immer nicht da.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

hciconfig -a
hci0: Type: Primary  Bus: USB
BD Address: E8:48:B8:C8:20:00  ACL MTU: 1021:6  SCO MTU: 255:12
UP RUNNING
RX bytes:5261 acl:0 sco:0 events:279 errors:0
TX bytes:34249 acl:0 sco:0 commands:262 errors:0
Features: 0xff 0xff 0xff 0xfe 0xdb 0xfd 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: PERIPHERAL ACCEPT
Name: 'alex-L55'
Class: 0x6c0104
Service Classes: Rendering, Capturing, Audio, Telephony
Device Class: Computer, Desktop workstation
HCI Version: 5.1 (0xa)  Revision: 0x9a9
LMP Version: 5.1 (0xa)  Subversion: 0x8a6b
Manufacturer: Realtek Semiconductor Corporation (93)

dominik

Mach bitte noch folgende Tests:


sudo -u fhem bash
pip3 install btsocket==1.0.0

Danach nochmals ein Test. Wenn es nicht funktioniert, dann bitte...


python3
import fhempy.lib.ble_monitor.bt_helpers
fhempy.lib.ble_monitor.bt_helpers.hci_get_mac([0,1,2,3])
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

Bei dem ersten Befehlen bekomme ich die Fehlermeldung dass es die Version 1.0.0 nicht gibt:

ERROR: Could not find a version that satisfies the requirement btsocket==1.0.0 (from versions: 0.1.0, 0.2.0)
ERROR: No matching distribution found for btsocket==1.0.0

dominik

Sorry, Tippfehler von mir. Sollte 0.1.0 heißen statt 1.0.0.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

Leider ebenfalls ohne Erfolg:


2022-05-17 20:20:20,029 - INFO     - fhempy.lib.fhem_pythonbinding: Starting fhempy 0.1.331...
2022-05-17 20:20:20,032 - INFO     - fhempy.lib.fhem_pythonbinding: Waiting for FHEM connection
2022-05-17 20:20:20,072 - INFO     - websockets.server: server listening on 0.0.0.0:15733
2022-05-17 20:20:37,756 - INFO     - websockets.server: connection open
2022-05-17 20:20:37,756 - INFO     - fhempy.lib.fhem_pythonbinding: Incoming FHEM connection: 127.0.0.1
2022-05-17 20:20:37,793 - WARNING  - zeroconf: Error with socket 19 (('192.168.42.0', 5353))): [Errno 126] Required key not available
Traceback (most recent call last):
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 1053, in sendto
    self._sock.sendto(data, addr)
OSError: [Errno 126] Required key not available
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 644, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2022-05-17 20:20:42,121 - ERROR    - Feuermelder_SZ: Waiting for the HCIdump thread to finish took too long! (>10s)
2022-05-17 20:20:42,122 - WARNING  - asyncio: Executing <Task finished name='Task-38' coro=<ble_monitor.Define() done, defined at /opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/ble>
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 171, in run
    conn[hci], btctrl[hci] = self._event_loop.run_until_complete(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 644, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/opt/fhem/.local/lib/python3.10/site-packages/fhempy/lib/ble_monitor/hcidump.py", line 183, in run
    self._event_loop.run_until_complete(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 644, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2022-05-17 20:20:46,126 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:20:47,390 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:20:51,130 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:20:52,394 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:20:57,398 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:21:02,402 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.
2022-05-17 20:21:07,406 - ERROR    - Feuermelder_SZ: HCIdump thread: Something wrong - interface hci0 not ready, and will be skipped for current scan period.



python3
Python 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fhempy.lib.ble_monitor.bt_helpers
>>> fhempy.lib.ble_monitor.bt_helpers.hci_get_mac([0,1,2,3])
{0: 'E8:48:B8:C8:20:00'}

dominik

Hast du Python 3.10 manuell installiert? Wenn ja, probier es bitte mal mit der Standardversion die mit Ubuntu ausgeliefert wird.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

Nighthawk

Die Version wird offensichtlich mit Ubuntu 22.04 ausgeliefert:

Holen:1 http://de.archive.ubuntu.com/ubuntu jammy/main amd64 python3 amd64 3.10.4-0ubuntu2 [22,8 kB]
Es wurden 22,8 kB in 0 s geholt (303 kB/s).
Vormals nicht ausgewähltes Paket python3 wird gewählt.
(Lese Datenbank ... 233714 Dateien und Verzeichnisse sind derzeit installiert.)
Vorbereitung zum Entpacken von .../python3_3.10.4-0ubuntu2_amd64.deb ...
Entpacken von python3 (3.10.4-0ubuntu2) ...
python3 (3.10.4-0ubuntu2) wird eingerichtet ...
running python rtupdate hooks for python3.10...
running python post-rtupdate hooks for python3.10...