-
Notifications
You must be signed in to change notification settings - Fork 173
Description
I'm encountering an issue with the tinygo-org/bluetooth package on macOS when using the bluetooth.DefaultAdapter.Scan function. After the macOS system has been locked for an extended period (e.g., screen lock or sleep mode), the Scan function no longer detects any Bluetooth devices. This issue persists even after calling adapter.Enable() and attempting to rescan.
Steps to Reproduce:
Set up the tinygo-org/bluetooth package on macOS and ensure Bluetooth is enabled.
Use the bluetooth.DefaultAdapter to initiate a scan for Bluetooth devices (e.g., using the provided scanner example).
Lock the macOS screen or let the system enter sleep mode for an extended period (e.g., 3-5 hours).
Unlock the system and attempt to scan again using adapter.Scan.
Optionally, call adapter.Enable() before rescanning.
Expected Behavior:
The Scan function should detect nearby Bluetooth devices after unlocking the system, and the callback function should be invoked, allowing code within it (e.g., deviceName := device.LocalName()) to execute.
Actual Behavior:
After a prolonged lock period, no devices are detected by the Scan function, and the callback function is not triggered. When debugging with breakpoints, the code does not reach the line deviceName := device.LocalName() inside the callback, which it normally would under regular conditions. This persists even after calling adapter.Enable().
Code Snippet:
Here’s the relevant code used for scanning:
err := adapter.Scan(func(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
deviceName := device.LocalName()
log.Printf("Found device: %v, RSSI: %d", deviceName, device.RSSI)
select {
case <-closeChan:
log.Printf("Stop signal received during scan callback")
return
default:
}
select {
case data <- Device{
Adapter: adapter,
Device: device,
DeviceName: deviceName,
UUid: device.Address.UUID.String(),
Rssi: device.RSSI,
}:
case <-closeChan:
log.Printf("Stop signal received while sending device data")
return
default:
log.Printf("Device channel full, skipping device: %v", deviceName)
}
})