Scan and pick first available hci device#369
Scan and pick first available hci device#369baylanger wants to merge 1 commit intoteslamotors:mainfrom
Conversation
|
Per more tests I just ran, when the device jumps from hci0 to hci1, when the kernel encounter an issue with the later, the device goes back to hci0. [edit] it even jumped once to hci2 and reverted later to hci0. Perhaps a better solution would be to allow via command line to specific which device to use but most people only have a single BLE device. |
| return nil, fmt.Errorf("failed to find available Bluetooth adapter: %w", err) | ||
| } | ||
|
|
||
| log.Printf("Using Bluetooth adapter: %s", hciName) |
There was a problem hiding this comment.
This should probably use log.Debug
|
Is there a reliable way to reproduce this on a raspberry Pi? I do most of my Linux-based testing on one and haven't encountered this issue. |
|
If hci jumps around, how about specifying wanted device with it's mac address, or some other unique id? And then search for it? |
|
I have proposed a new PR with my suggestion. |
Same here, I have a few hundred BLE users, I never had this issue, some have this regularly but until now, I did not find the root cause. This PR helps to get rid of the issue, though. |
@Lenart12 I didn't think of going with the BLE MAC addr , I admit I like your approach better than mine as it covers someone with 2+ BLE devices... perhaps for someone with a big house and 2 garages on apposite side that each requires their own dongle :) I'll leave this PR open for now but I vote for your approach. |
|
My PR will not work, check my comment there :^( |
|
I made a PR (#373) that will switch the bluetooth backend to use BlueZ. It allows us to nicely specify which adapter to use (hciX). You can use external tooling to find the wanted hci id (first available/mac address). Hopefully that also means that a lot of wierd bluetooth issues people were experiencing will be fixed. |
|
I made a new attempt to fix this in #389. Hopefully we can get it in a bit faster since its not such a major change as switching the BT backend. |
|
Since it sees like a bigger change to BLE will be deferred, I'm open to revisiting this PR. Is there a way to reproduce the problem? |
|
Now that selecting a specific hci adapter is possible, this PR is condensed to a trivial bash one-liner before invokaton to find the first available one. I question if it is worth it to add a special routine to search the fs |
Description
This PR enables
tesla-controlto automatically select, at least under Linux, the first availablehcidevice. Currently,tesla-controlonly tries to usehci0and lacks the ability to dynamically choose the first available Bluetooth device.In our project, an add-on for Home Assistant,
tesla-controlis used to fetch data and control Tesla vehicles.We’ve received multiple reports from different people seeing always the same issue. This happens on Raspberry Pi (recent and old models), Synology NAS, and similar systems. After a fresh reboot, the Bluetooth device initially appears as hci0, but after a short time, it jumps to hci1. After this,
tesla-controlbecomes useless.I am not a pro Go programmer but the tests I ran seem to be a solution for #261
Fixes #261
Type of change
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps: