Bluetooth help - invalid state

I’m porting an app from another Bluetooth stack (Broadcom/Cypress Wiced) to the standard SDK.
I need to be able to start and stop advertising during operation.

I’m calling le_adv_start() and le_adv_stop(), but I’m often getting the return code 2 (GAP_CAUSE_INVALID_STATE)
Can anyone provide some assistance as to what I’m doing wrong to cause this error code?

I also need to run passive scans whilst advertising is enabled. I’m calling le_scan_start() and le_scan_stop() but I can’t get it to work. Sometimes these functions also return code 2.

The BT application doc doesn’t seem to cover the case of advertising and scanning in the same app. Is it possible?

Thanks.

1 Like

help you tag someone @wyy who knows this matter better

you should refer to the BLE_Scatternet example for how to configure for Central + Peripheral operation.
BLE_Scatternet can be enabled with the ATBf command, after which it will begin advertising. You can then use the ATBS command to perform BLE scanning while the scatternet advertisement is still active.

I had to work on some other projects, but back on this now.
I managed to fix the wrong state issue. I had coded it to configure the advertising data by calling le_adv_set_param(), and then immediately called le_adv_start(), which was running before the set param had completed.

The next issue I have is with scanning. I need to scan for 1 second, seeing what devices are present. I will then process the data, and then scan for another second etc.
I can’t find any documentation that shows if le_scan_start() scans until stopped, or for a time period, or just once.

I can see the gap_scan_state changed to GAP_SCAN_STATE_SCANNING and then almost immediately it changes to GAP_SCAN_STATE_IDLE.

Am I supposed to call le_scan_start() again myself when it goes back to Idle, or can I configure it to scan repeatedly by itself?
Thanks.

le_scan_start() starts scanning continuously until le_scan_stop() is called.

have you configured scan parameters first using le_scan_set_param() before starting a scan?

Thanks. I had set the scan parameters, but seems my window/interval values were not valid, causing it to immediately return to idle with cause 0x112.
After changing the values, and doing the 1 second timer in application code, it all looks to be working well.

1 Like