This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to know softdevice state

I am using s120 for central device, and my central device connects to multiple BLE slaves. After connection, some slaves may lost connection due to power off of that device. The device might be powered on again after sometime.

The way I am currently doing is to send connection command sd_ble_gap_connect(). For one-peripheral case, it works ok. But for multiple peripherals, softdevice will return "NRF_ERROR_INVALID_STATE" error.

My question is can we know the softdevice state before call "sd_ble_gap_connect()"?

Is there a better way to know the slave is powered on again (it will still broadcast), when the central is in connection state?

Thanks.

  • Your Central should always send a connect request sd_ble_gap_connect only when it gets an advertising report event BLE_GAP_EVT_ADV_REPORT from that slave. From the advertisement report you can parse the information of that slave. If your central is doing active scanning then you can get more information in BLE_GAP_EVT_SCAN_REQ_REPORT event.

    When you get one of this event and your central is able to parse the information to know that it came from the slave device you want to connect, then sending connect request is safe as you know that slave was advertising at-most 150us ago.

    You can look in some of the central examples in SDK. I do not see any other way of polling non connected device states.

  • Thanks Aryan for your answer. Your suggestion is correct for the very beginning of the connection establishment.

    For S120, the specification says " Up to 8 concurrent links supported as a Central. Observer can run concurrently with a central in a connection." So I suppose, after a connected slave is power off, then on again, I could receive advertising report after calling sd_ble_gap_scan_start() in the central device with S120. This seems also the suggested method in another post: devzone.nordicsemi.com/.../

    However, there is no advertising report event received. (The slave is still advertising). Any assumption to call "sd_ble_gap_scan_start()"? Thanks.

  • Hi YSquare,

    What is the advertisement interval from the peripheral side and what are scan interval and window size on central side?

    If central is not getting ADV report from peripheral then something is wrong, i recommend you to sniff the packets to see if peripheral packets are coming out into air and still central side is not able to get them. Also debug your central to see if it has hardfaulted or something else.

Related