custom-components / ble_monitor

BLE monitor for passive BLE sensors
https://community.home-assistant.io/t/passive-ble-monitor-integration/
MIT License
1.91k stars 247 forks source link

Error on first use #388

Closed freekeys closed 3 years ago

freekeys commented 3 years ago

Hi, I keep getting this error and cannot see any devices coming in. Any ideas? Thanks!

This error originated from a custom integration.

Logger: root Source: custom_components/ble_monitor/init.py:524 Integration: Passive BLE monitor (documentation, issues) First occurred: 23:31:08 (10 occurrences) Last logged: 23:49:10

Uncaught thread exception Traceback (most recent call last): File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/config/custom_components/ble_monitor/init.py", line 524, in run self._event_loop.run_until_complete(btctrl[hci].send_scan_request(self._active)) File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete return future.result() File "/usr/local/lib/python3.8/site-packages/aioblescan/aioblescan.py", line 1803, in send_scan_request if self._use_ext_scan(): File "/usr/local/lib/python3.8/site-packages/aioblescan/aioblescan.py", line 1788, in _use_ext_scan return (self._supported_commands[37] & 0x60) == 0x60 TypeError: 'NoneType' object is not subscriptable

Ernst79 commented 3 years ago

hmm, this is the first time I've seen this error. It is an error from the aioblescan pypi package, but it is in a part of the code we have added ourselves.

What kind of bluetooth dongle/radio and system do you have. Do you have an Intel NUC? Raspberry pi Is your bluetooth working?

debugging So, note for myself.

Normally, this last line that is causing the error is reading byte 37 (starting with 0) from self._supported_commands

return (self._supported_commands[37] & 0x60) == 0x60

self._supported_commands is returning this in my case

b'\xff\xff\xff\x03\xcc\xff\xef\xff\xff\xff\xec\x1f\xf2\x0f\xe8\xfe?\xf7\x8f\xff\x1c\x00\x04\x00a\xf7\xff\xff\x7f\xf8\xff\xff\xff?\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

So, byte 37 is x00, so it will return False (as I don't have a dongle that supports the extended format.

In the case of @freekeys, self._supported_commands apparently is None, which is the initial value during init.

freekeys commented 3 years ago

I'm running HassOS on a Raspberry Pi 4. I haven't specifically turned Bluetooth on as I'm not using it for any other components - do I need to?

freekeys commented 3 years ago

I've realised I need an encryption key and haven't defined one - could this be the problem? EDIT: got this now and issue persists

Ernst79 commented 3 years ago

No, that is not related. It fails in setting up the communication with the bluetooth radio of your Pi. I will setup HassOs this weekend to check if I can reproduce this.

Can you try to see if this built in component works?

https://www.home-assistant.io/integrations/bluetooth_le_tracker/

Ernst79 commented 3 years ago

Tried it on a clean install (RPi 3b+), but I can't reproduce it.

image

I think the first thing to check is to see if Bluetooth works with other standard HA Bluetooth components, like the one I mention above.

freekeys commented 3 years ago

Tried installing bluetooth_le_tracker and interestingly I'm getting the error below - no more context though..

Logger: homeassistant.components.device_tracker Source: components/device_tracker/legacy.py:260 Integration: Device Tracker (documentation, issues) First occurred: 20:39:10 (1 occurrences) Last logged: 20:39:10

Error setting up platform legacy bluetooth_le_tracker

Ernst79 commented 3 years ago

Look s like something is wrong with the Bluetooth on your system, but I’m not sure what. Normally it works out of the box on HassOs. I have to think what could be wrong.

freekeys commented 3 years ago

Thanks so much!

Ernst79 commented 3 years ago

I can not really think of the cause of this issue. I suspect some serious issue with your bluetooth radio, but on Home Assistant OS it is quite difficult to investigate, as you don't have root access via SSH. What worries my is that even the build in components with Bluetooth don't work.

Can you try one more time by setting up the mitemp_bt component. https://www.home-assistant.io/integrations/mitemp_bt/

freekeys commented 3 years ago

Really appreciate your help with this. I get this error with mitemp_bt:

Logger: homeassistant.helpers.entity Source: components/mitemp_bt/sensor.py:157 First occurred: 23:09:38 (1 occurrences) Last logged: 23:09:38

Update for sensor.mitemp_bt_temperature fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_device_update await task File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/mitemp_bt/sensor.py", line 157, in update data = self.poller.parameter_value(self.parameter) File "/usr/local/lib/python3.8/site-packages/mitemp_bt/mitemp_bt_poller.py", line 126, in parameter_value self.fill_cache() File "/usr/local/lib/python3.8/site-packages/mitemp_bt/mitemp_bt_poller.py", line 59, in fill_cache self.firmware_version() File "/usr/local/lib/python3.8/site-packages/mitemp_bt/mitemp_bt_poller.py", line 106, in firmware_version self.battery = int(ord(res_battery)) TypeError: ord() expected a character, but string of length 15 found

freekeys commented 3 years ago

And also:

Logger: homeassistant.components.mitemp_bt.sensor Source: components/mitemp_bt/sensor.py:162 Integration: mitemp_bt (documentation, issues) First occurred: 23:09:54 (21 occurrences) Last logged: 23:19:54

Polling error

freekeys commented 3 years ago

But to be fair it's the v2 of the Mijia sensor so not sure it would work with this integration so guess it would throw an error anyway?

Ernst79 commented 3 years ago

Sorry I didn't got back to you sooner.

V2 version of the sensor should not be the issue.

In Mitemp_bt, you have a similar error.

TypeError: ord() expected a character, but string of length 15 found

Your Home Assistant is both in Mitemp_bt and in BLE monitor getting completely wrong data, it seems. Even before it is even starting to look at the data. If you really want to dig into the issue, I can try to help you with a custom version of BLE monitor, to find the cause of the issue, but I suspect some issue that is possibly hardware related (its a feeling).

Other options to try first are a full restart of the HA system (not only HA). Another option would be using a bluetooth dongle.

Let me know if you want to dig into the issue, I will then create a special version where we can do some debugging.

Ernst79 commented 3 years ago

Any update or can we close this issue?

freekeys commented 3 years ago

Thanks for your help! Think it must be a hardware issue - I gave up and went via a ESP32 instead 😊