-
Notifications
You must be signed in to change notification settings - Fork 177
Description
I have implemented a BLE-server with nrf52840 (which was switched to release v0.14.0 some days ago without any problem) and a client with nrf5280.
After switching from release v0.13.0 to v0.14.0 in the client, the scan function returns an error "invalid state, operation disallowed in this state" immediately when the target device (service) was detected. This is caused by the changes in #398 . After revert this one change in the client, it works without an error.
My callback-function looks like this:
callback := func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) {
// result.ManufacturerData() // sometimes causes "index out of range"
if scanTimeout > 0 {
timeOutElapsed = time.Since(startTime) > scanTimeout
}
if timeOutElapsed || result.Address.String() == identifier || result.LocalName() == identifier {
// if the scan is stopped and no connection was done before (no initial connection), the nrf-hardware
// returns "invalid state, operation disallowed in this state" for all later scans - so a stop-scan on a
// timeout leads to a not repairable state, at least on the initial scan
if e := adapter.StopScan(); e != nil {
println("stop scan returns an error:", e.Error())
}
if !timeOutElapsed {
finalResult = result
}
}
}My comment in the code for the "timeout" is maybe the exact same reason, like described in #398. I will name it the "originated problem" now. Therefor I have set my "scanTimeout" to "0" to skip this code. Additionally I do not perform a "reconnect" but wait endless until the first connection is done successfully. This was my workaround for the originated problem.
The error is returned by the second "C.sd_ble_gap_scan_start()" call in the loop at line 74. So my assumption is: calling the function "C.sd_ble_gap_scan_stop()" when the function "C.sd_ble_gap_scan_start()" is still active, would lead to this behavior.
I wonder if the problem can be reproduced by someone else (@deadprogram , @zopieux)?
Maybe the adjustment with #398 needs to be improved, when other than that, the originated problem is fixed (I have not tested it yet by my own - I will remove my workaround in the next step).