Cannot reconfigure BLE peripheral UART example to send data I have stored in buffer please help

Hello I have seen ALOT of posts referencing to first build and run ble peripheral uart example and then from there that it will be easy to remove the uart from the functionality if so desired but I cannot seem to get this to work.

I have tried many different approaches over the past few weeks and no matter what I do I cannot get an app up and running that allows me to use my PCB as peripheral that automatically sends a buffer of data (a bunch of SSIDs concatenated) on connection of central device (NRF Connect app). Is there please a snippet of code you can provide me that shows how to go from using the uart to having my own custom service that just sends a buffered message over ble?

  • Hi there,

    Are you using nRF Connect SDK or the nRF5SDK and which version are you using?

    regards

    Jared 

  • HI Jared our project is based on using the UART BLE peripheral example in NRF5SDK SDK version 17.1. Thank you for your quick response.

  • Hi Matt,

    Essentially, the ble_app_uart example works as a bridge between your BLE peer device (often a mobile phone) and your serial device (often a computer). 

    The application is notified of data coming from the serial device in the uart_event_handle() callback handler and sends the data with ble_nus_data_send(). 

    Similarly, the application is notified of data coming from the BLE peer device in the nus_data_handler() and forwards the data to the serial device by calling app_uart_put(). 

    If you want to only send data from your application directly to your peer device, you can omit nus_data_handler() and instead only use ble_nus_data_send(). 

    I have tried many different approaches over the past few weeks and no matter what I do I cannot get an app up and running that allows me to use my PCB as peripheral that automatically sends a buffer of data (a bunch of SSIDs concatenated) on connection of central device (NRF Connect app).

    Could you elaborate on what you have tried so far and specify how it failed?

    regards

    Jared

  • I actually just managed to get ble_nus_data_send() workign yesterday afternoon, kind of, by employing:

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t index = 0;
        uint32_t       err_code;

        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&txBuff[index]));
                index++;

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

                            do
                            {
                                uint16_t length = (uint16_t)index;
                                err_code = ble_nus_data_send(&m_nus, txBuff, &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);
                        }

                    }

                break;

    and

    static void idle_state_handle(void)
    {
        app_sched_execute();

        cli_process();

        (void)NRF_LOG_PROCESS();

       if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
       {
          uart_event_handle(APP_UART_DATA_READY);
       }
    }

    but now I am running into a new problem, the data I need to send is around 256 bytes, in length and anytime I increase my MTU to more than the default:

    /** @brief Default ATT MTU, in bytes. */
    #define BLE_GATT_ATT_MTU_DEFAULT          23

    I get an asserition failure.

    Is there a way to repeatedly call data in a loop ble nus data send () and step trhough my 256 byte string in 20 byte snippets?

    Thank you

  • mjconnor57 said:
    Is there a way to repeatedly call data in a loop ble nus data send () and step trhough my 256 byte string in 20 byte snippets?

    Yes, just call ble_nus_data_send() in a for loop where you increment the array parameter 20 byte for each call until you've sent the data. 

Related