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?

Parents
  • I think the reason you are getting this error is because you are trying to notify a value without a valid connection. Since notifications are only supported while connected, you will get an error.

    A solution for this could be to simply ignore the error, like it's done in the ble_app_uart peripheral example:

    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
        if ((err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }

    Best regards,

    Simon

Reply
  • I think the reason you are getting this error is because you are trying to notify a value without a valid connection. Since notifications are only supported while connected, you will get an error.

    A solution for this could be to simply ignore the error, like it's done in the ble_app_uart peripheral example:

    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
        if ((err_code != NRF_ERROR_INVALID_STATE) &&
            (err_code != NRF_ERROR_RESOURCES) &&
            (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }

    Best regards,

    Simon

Children
  • It is located here: nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\ble_app_uart

  • Hi simon, I only use ble_app_proximity example project.

  • I added as you suggested to the project. but issue is still

      case APP_UART_DATA_READY:
        // Handled in NUS handle
        //added by zap
        UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;

                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(data_array, index);

                        do
                        {
                            uint16_t length = (uint16_t)index;
                            err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                            if ((err_code != NRF_ERROR_INVALID_STATE) &&
                                (err_code != NRF_ERROR_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_RESOURCES);
                    }

                    index = 0;
                }
        break;

  • 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

Related