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

NRF_ERROR_INVALID_STATE before android app (central) connected to peripheral ble 52832

I am sorry to ask a stupid question as i supposed to fix firmware issue with my zero knowledge.

Before android app (central) connected to peripheral ble 52832, If I press/touch watch sensor, I got NRF_ERROR_INVALID_STATE error and then firmware stopped working.

But after connection is established between devices, it is working. Only the issue occur before connection is made.

I use external driver st7735, nrf52832, pca10040 board, sdk 15.3, s132 and ses arm 4.22.

I want to do is to keep firmware working until connection is made ( to ignore event from the sensor unless the connection is made between android app and peripheral ble device).

Is there a possible way to prevent that case?

  • What is your issue? Is it still NRF_ERROR_INVALID_STATE? If so, what function is returning this? If it's something else, could you be more specific? What function is failing, and what error code is it returning?

    Check out the video below, which shows how to debug your project using SES.

    Best regards,

    Simon

  • hi sorry for late response. Yes issue is still NRF_ERROR_INVALID_STATE which is encountered in bsp_event_handler function as

  • Could you be more specific, where exactly does the error occur? In the bsp_event_handler function, there are two functions that runs (see code snippet below),.

    void bsp_event_handler(bsp_event_t event)
    {
        uint32_t err_code;
        switch (event)
        {
            case BSP_EVENT_SLEEP:
                sleep_mode_enter();
                break;
    
            case BSP_EVENT_DISCONNECT:
                err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            case BSP_EVENT_WHITELIST_OFF:
                if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
                {
                    err_code = ble_advertising_restart_without_whitelist(&m_advertising);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
                break;
    
            default:
                break;
        }
    }
    

    in the first function (sd_ble_gap_disconnect(..)) the error NRF_ERROR_INVALID_STATE  is simply ignored. My assumption is that the error happens in  bsp_event_handler()-->case BSP_EVENT_WHITELIST_OFF-->ble_advertising_restart_without_whitelist()-->ble_advertising_start(). Could you confirm this by showing the call stack (outlined in red in image below) after the error occurs?

    Best regards,

    Simon

Related