Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

room assistant on rpi frequently reports not able to connect to devices #895

Closed
gadric opened this issue Sep 7, 2021 · 8 comments
Closed
Labels

Comments

@gadric
Copy link

gadric commented Sep 7, 2021

Describe the bug
I have a couple of rpis (rpi0, rpi4 and pi3) around here which I use for room-assistant. I am using BLE, ios companion app and Android Beacon Simulator to track phones.

Lately, I am using monit to monitor the error messages of room-assistant as it occurred a couple of times that room assistant where not able to track my devices. Some of the error messages seems to be weird.

For example:

Sep   7 07:41:19 xxx room-assistant[690]: 7.9.2021, 07:41:19 - error - BluetoothService: Failed to connect to 49:09:xxxx: timed out

I am not using Bluetooth Classic at all. Why is room-assistant report that it cannot connect?

The second one:

Sep   7 06:49:23 yyy room-assistant[10268]: 9/7/2021, 6:49:23 AM - error - BluetoothLowEnergyService: Failed to search for companion app at tag <tag>: timed out

I think this error occurs when the device is not in range. Is there a way to tell room-assistant not to report if the device is not around?

To reproduce
No specific reproducing steps, just let it run for a day or two.

Relevant logs
the relevant logs are in the text above

Relevant configuration
Paste the relevant parts of your configuration below.

global:
  instanceName: <name>
  integrations:
    - homeAssistant
    - bluetoothLowEnergy
cluster:
  autoDiscovery: false
  weight: 5
  port: 6425
  peerAddresses:
    - 192.168.xx.y1:6425
    - 192.168.xx.y2:6425
    - 192.168.xx.y3:6425
homeAssistant:
  mqttUrl: 'mqtts://zzzzzz:8883'
  mqttOptions:
    username: ****
    password: ****
    rejectUnauthorized: false
bluetoothLowEnergy:
  timeout: 120
  updateFrequency: 5
  allowlist:
    - <UUID of IOS companion App>
    - <UUID of Androind Beacon Scanner>
  tagOverrides:
    <UUID of IOS companion App>:
      name: iphone
    <UUID of Androind Beacon Scanner>:
      name: android

Expected behavior

  1. Do not connect to Bluetooth Classic
  2. Do not report error, if the device is not around

Environment

  • room-assistant version: 2.18.4
  • installation type: NodeJS
  • hardware: Raspberry Pi Zero W, Raspberry Pi 3, Raspberry Pi 4
  • OS: Linux, Raspberry Pi OS

Additional context
Add any other context about the problem here.

@gadric gadric added the bug label Sep 7, 2021
@PeteBa
Copy link
Contributor

PeteBa commented Sep 7, 2021

Both of these messages are created for Low Energy devices (BluetoothLowEnergyService uses BluetoothService).

The first error message occurs when RA cant connect to the LE device. This could be because the device is on the edge of reception or the device could already be connected to something and thus not available. I have seen this happen when two RA instances are both trying to connect to the same LE device at the same time.

The second error occurs when the connection was made but the LE device failed to respond to the subsequent read request. This could be because the device is again at the edge of reception or that the device is doing something else and not ready to respond. I have also seen this happen when the LE device is low on battery and is unable to power the read response.

In all cases, queries of LE devices only occurs off the back of a received advertisement message. This way RA knows that the device is highly likely to be in range and able to respond.

@gadric
Copy link
Author

gadric commented Sep 7, 2021

Thanks for the clarification. That explains alot.

Do you know any workarounds? Can maxDistance solve these problems?

@PeteBa
Copy link
Contributor

PeteBa commented Sep 7, 2021

I think maxDistance is a filter that happens downstream of the companion app detection process so wouldnt help. I dont know an existing work-around but others may have suggestions on this. Can you filter these out using Monit's ignore content test.

Out of interest, how many of these error messages do you get a day and is it more prevalent for a specific pi or phone ? There is an argument to downgrade those messages to be info rather than error as connection failures with BLE are an expected occurrence and there is a "re-try in 15 seconds" mechanism in place. Maybe error on every third retry.

@gadric
Copy link
Author

gadric commented Sep 7, 2021

In my monit settings, it send an notification, as soon as room-assistant shows an error 10 times in 20 cycles. If this happens, then room-assistant is restarted. After room-assistant has restarted, this problem is gone for a while. But starts again later.

Current impression after 4 days:
rpi0 und rpi3 are reporting this much more often and produce much more issues. Curerntly 5 to 6 alerts from monit each from rpi0 and rpi3 everyday. The problems seems to be more often with iOS. The android seems have less issues.

I have actually deployed this solution because room-assistant happens to stop working and does not detect one or both phones. A solution was whether to restart room-assistant or sometimes I have to restart the pis completely. Generally it is not a big deal. I just would like to automate this process. like: detect that a room assistant is not working on a pi. then first restart room-assistant, then restart the pi.

@gadric
Copy link
Author

gadric commented Sep 11, 2021

Update:

I am currently testing a new approach: I am matching only defined error messages. Currently I have:

.*room-assistant\[[0-9]+\]:.*- error - BluetoothService: Command failed: hciconfig hci\[0-9\] reset.*
.*room-assistant\[[0-9]+\]:.*- error - BluetoothLowEnergyService: Failed to search for companion app at tag .*: timed out
.*room-assistant\[[0-9]+\]:.*- error - BluetoothService: Failed to start advertising instance via BLE: Command Disallowed
.*room-assistant\[[0-9]+\]:.*- warn - BluetoothLowEnergyService: Failed to discover companion app ID due to error: timed out
.*room-assistant\[[0-9]+\]:.*- warn - BluetoothService: Did not detect any low energy advertisements in a while, resetting

However, I am not sure if those patterns will match if an Android device cannot be detected. Does anyone know how a regular error message looks like if an Android BLE shows errors?

@PeteBa
Copy link
Contributor

PeteBa commented Sep 11, 2021

The error messages are the same irrespective of the BLE devices type. So the ones you identified should be a good list.

Given the frequency of errors, have you tried the beta version of room-assistant that disables bleno ? This removes the ability to automatically toggle companion app on/off as your phone moves in/out of range. There have been issues with this feature on some set-ups so the beta version might be worth trying. There is also PR #887 that is not quite ready yet but should hopefully improve things.

@gadric
Copy link
Author

gadric commented Sep 12, 2021

The error messages are the same irrespective of the BLE devices type. So the ones you identified should be a good list.

But what is the MAC address? Should I take the MAC address of the bluetooth device? I was not sure because BLE works will UUIDs.

Given the frequency of errors, have you tried the beta version of room-assistant that disables bleno ? This removes the ability to automatically toggle companion app on/off as your phone moves in/out of range. There have been issues with this feature on some set-ups so the beta version might be worth trying. There is also PR #887 that is not quite ready yet but should hopefully improve things.

Not yet. But I will test this in the next days.

@gadric
Copy link
Author

gadric commented Oct 11, 2021

Currently, it works pretty good.

@gadric gadric closed this as completed Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants