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?

  • Does my nus_data_handler seem valid for accepting the 2 discrete values from the central, a ssid and pwd?

  • Hi.

    mjconnor57 said:

        (void)NRF_LOG_PROCESS();

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

    }

    This is probably why it generates multiple APP_UART_DATA_READY. idle_state_handle() will be called every time the program iterates in the main loop. Instead of moving uart_event_handle(APP_UART_DATA_READY) to idle_state_handle() try this:

    1. Receive data from UART and fill a buffer in APP_UART_DATA_READY.
    2. Check if the buffer is filled by checking if the size of the buffer is equal to 20 bytes.
    3. If the buffer is filled then set a flag.
    4. In the main loop, check if the flag is set, if it's set then call ble_nus_data_send() to send the data to the peer.
    mjconnor57 said:

    I think I may have solved it by adding in the index++

    to

       if ((m_conn_handle != BLE_CONN_HANDLE_INVALID) && (index == 1))
       {
          uart_event_handle(APP_UART_DATA_READY);
          nus_data_handler(BLE_NUS_EVT_RX_DATA);
          index++;
       }

    I am just not sure how "good" of a solution it is. It only send the data once then waits for a response

    Seems like you already found an alternative solution to your problem. 

    regards

    Jared 

Related