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.1-0.20260516164426-9314216eb8e6
tinygo.org/x/bluetooth v0.15.1-0.20260517055521-fc635e3ddf8c
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1177,3 +1177,5 @@ 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=
tinygo.org/x/bluetooth v0.15.1-0.20260517055521-fc635e3ddf8c h1:J79BLD06N/AbVVFlnkoz010iMkprM6TGCVFy2rRC2Fk=
tinygo.org/x/bluetooth v0.15.1-0.20260517055521-fc635e3ddf8c/go.mod h1:meayNB+9rC1igTUNmNU7KftlSEzrFHe37rBSQZjHN8Y=
13 changes: 8 additions & 5 deletions internal/meshx/transport/ble.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ func DialBLE(addr string) (Client, error) {
if c, err := connectAndWire(adapter, cachedAddr, addr); err == nil {
return c, nil
}
// Cached peripheral didn't connect — peripheral genuinely
// gone (radio rebooted, OS cache evicted), or cached handle
// is stale. Drop the cache and fall through to a fresh scan.
forgetScannedAddr(addr)
// Re-enable after connectAndWire's Reset tore down the central.
if err := adapter.Enable(); err != nil {
return nil, fmt.Errorf("re-enable bluetooth adapter after reset: %w", err)
}
}

// Slow path: scan for the target advertisement.
Expand Down Expand Up @@ -240,11 +241,13 @@ func connectAndWire(
device, err = res.device, res.err
case <-time.After(bleConnectTimeout):
_ = adapter.StopScan()
// Stale CBPeripheral handle — tear down the central manager
// so the next Enable() rebuilds from scratch.
_ = adapter.Reset()
return nil, fmt.Errorf(
"connect %s: CoreBluetooth did not respond within %s "+
"(usual cause: cached peripheral handle invalidated by "+
"OS sleep/wake; the next attempt will drop the cache and "+
"re-scan)",
"OS sleep/wake; adapter reset, next attempt will re-scan)",
addr, bleConnectTimeout,
)
}
Expand Down