Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
go.bug.st/serial v1.6.4
golang.org/x/term v0.43.0
google.golang.org/protobuf v1.36.11
tinygo.org/x/bluetooth v0.15.0
tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,5 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
tinygo.org/x/bluetooth v0.15.0 h1:hLn8+iZFXvVxBzPIdZfvc6TD8JP32ixF22lCEWHAbIo=
tinygo.org/x/bluetooth v0.15.0/go.mod h1:meayNB+9rC1igTUNmNU7KftlSEzrFHe37rBSQZjHN8Y=
tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6 h1:oRX+XsAJ0HOQa57yUelRxllVZyLoggYjdO6Z/VfvKjo=
tinygo.org/x/bluetooth v0.15.1-0.20260516164426-9314216eb8e6/go.mod h1:meayNB+9rC1igTUNmNU7KftlSEzrFHe37rBSQZjHN8Y=
28 changes: 1 addition & 27 deletions internal/meshx/transport/ble.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,6 @@ import (
"tinygo.org/x/bluetooth"
)

// adapter.Enable() on tinygo-bluetooth v0.15.0 is non-idempotent on
// macOS — a second call from the same process returns "already calling
// Enable function" and aborts. The pump's reconnect loop redials on
// every transport drop, so without this guard every retry would fail
// for the wrong reason. Enable once per process, cache the result —
// but only on success. A failed Enable (timeout, TCC permission not
// yet granted) must be retryable so the daemon doesn't stay bricked
// until restart.
var (
bleEnableMu sync.Mutex
bleEnableSuccess bool
)

func enableBLEAdapterOnce(adapter *bluetooth.Adapter) error {
bleEnableMu.Lock()
defer bleEnableMu.Unlock()
if bleEnableSuccess {
return nil
}
if err := adapter.Enable(); err != nil {
return err
}
bleEnableSuccess = true
return nil
}

// scannedAddrs caches the bluetooth.Address (which carries the
// CBPeripheral pointer on macOS) of every UUID we've successfully
// scanned in this process. The cache lets in-process redials skip
Expand Down Expand Up @@ -155,7 +129,7 @@ const bleReadBuf = 512
// real error before it can panic downstream.
func DialBLE(addr string) (Client, error) {
adapter := bluetooth.DefaultAdapter
if err := enableBLEAdapterOnce(adapter); err != nil {
if err := adapter.Enable(); err != nil {
return nil, fmt.Errorf("enable bluetooth adapter: %w — is Bluetooth on?", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/meshx/transport/ble_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type BLESighting struct {
// deduplicated set.
func ScanBLE(timeout time.Duration) ([]BLESighting, error) {
adapter := bluetooth.DefaultAdapter
if err := enableBLEAdapterOnce(adapter); err != nil {
if err := adapter.Enable(); err != nil {
return nil, fmt.Errorf("enable bluetooth adapter: %w", err)
}

Expand Down