-
Notifications
You must be signed in to change notification settings - Fork 117
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
Replace go-ble/ble with tinygo-org/bluetooth #373
base: main
Are you sure you want to change the base?
Conversation
This was causing issues if multiple scans were being requested one after another quickly.
790fba7
to
7ba27d5
Compare
Tested this on macOS 14.6.1 using a variety of |
Plesantly suprised it worked without changes, I was unable to test on mac so It only worked "in theory". Great :^) |
Ah... scan is still getting stuck 🤬 was testing overnight and it locked up. Not much logs to investigate it unfortunately. Edit:
Here we can see scan is stopped but code from library never finishes, and connection status commands start stacking up. It should show
Working example:
This seems to me that it is an issue with the bluetooth library... (and/or by other applications using the same adapter) EDIT: Another event now with btmon logs... Happened at 17:20:14 By looking at the logs It seems to me that the issues is that another program restarted the adapter while the scan is active. Probably the library doesn't handle such cases yet. |
Alas it was not library bug. What happened:
|
So I have been testing overnight with constant requests to the car and so far I'm happy to report it has been super stable 🤞🥳 we can maybe consider this PR ready to merge. (Obligatory xkcd) |
pkg/connector/ble/device_darwin.go
Outdated
device, err := darwin.NewDevice() | ||
if err != nil { | ||
return nil, err | ||
func IsAdapterError(err error) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function causes make linters
to fail:
pkg/connector/ble/device_darwin.go:8:21: unused-parameter: parameter 'err' seems to be unused, consider removing or renaming it as _ (revive)
I.e., change to IsAdapterError(_ error) bool {
examples/ble/main.go
Outdated
return | ||
} | ||
|
||
// For simplcity, allow 30 seconds to wake up the vehicle, connect to it, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well fix "simplicity" typo next time you do a push
} | ||
device, err := adapter.Connect(target.Address, params) | ||
if err != nil && !connectionCancelled { | ||
errorCh <- err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's still a race condition here; if we enter into this if
branch, and then the main thread sets connectionCancelled = true
, we'll be blocked trying to write to errorCh
and no one will ever unblock us by reading from it. Similarly, there's a race with the else if
branch. We could solve both of these problems by making the errorCh
and deviceCh
channels buffered, which will allow the goroutine to write to them even if no one is listening:
deviceCh := make(chan bluetooth.Device, 1)
errorCh := make(chan error, 1)
This should also obviate teh need to use connectionCancelled
, which is a bit sus anyway since AFAIK reading/writing to non-atom
ic booleans isn't well-defined behavior.
This is just about ready to merge, but I'm about to head out on a vacation with limited availability. @patrickdemers6, if I'm not around and the responses to the above comments look good, I think we can merge. |
Still want to fix an error before merging inside |
I want to wait on tinygo-org/bluetooth#342 before merging |
Hey @sethterashima I have a questing if this is a regression, or not... If I keep the connection open for longer than 30s the car closes connection and if that happens, when i try to open the connection next time it will fail. If I close the connection before 30s it seems to not fail. I don't know if this is issue with tesla, bluez, or tinygo-org/bluetooth, maybe you will know... In the attachment I sent bluetooth and dbus capture you can open with wireshark. You can check packet 628 that fails and then 919 retries and succedes. Again 3062, 3265 (failed twice) and 3547 EDIT: Actually I think this is unrelated to the "30s timeout"... need to figure out what is causing this EDIT: I acually think this is an bluez issue (related ukBaz/BLE_GATT#9) as it is happening even in bluetoothctl tool. I think I need to implement the same workaroundin the bluetooth library. |
Description
As per title... works great with my setup (RPi 3B+, Debian 12).
New stuff:
Small example:
Closes #372
Please select all options that apply to this change:
Checklist:
Confirm you have completed the following steps: