This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

why it returns NRF_ERROR_INVALID_STATE when calling sd_ble_gap_adv_start()?

Hi,

The err_code shows NRF_ERROR_INVALID_STATE when called sd_ble_gap_adv_start(). I want to know why it happen, and how to handle it. This happened upon the ble disconnected.

Thanks a lot.

  • Hi,

    If you try to start advertising while you're in a state when it's not allowed to start advertise, then you will get that error code. For instance, if you start advertising while you're in a connection. You can see a explanation of the error codes given by the call in ble_gap.h:

    /**@brief Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).
     *
     * @param[in] p_adv_params Pointer to advertising parameters structure.
     *
     * @return @ref NRF_SUCCESS The BLE stack has started advertising.
     * @return @ref NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
     * @return @ref NRF_ERROR_INVALID_STATE Invalid state to perform operation.
     * @return @ref NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied, check the accepted ranges and limits.
     * @return @ref BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address supplied.
     * @return @ref BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
    

    Best regards Håkon

  • certainly, I have seen the explaination, but any way to know the certain state?In this case, maybe it is in connection, or advertising, or others. I need to check out the exact status.

    Thanks.

  • The states are triggered by the application, so there's no softdevice-call to figure out which state you're in. Since the softdevice gives you events back for each condition, it's the applications job to know what state it's in.

    BR Håkon

  • When you're disconnecting a link, are you waiting for the appropriate event (BLE_GAP_EVT_DISCONNECTED) back from the softdevice before starting the advertisement again? This is because sd_ble_gap_disconnect() will send a disconnect command over air before you're actually disconnected.

Related