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

Sending data from nRF 52810 to the nRF Connect mobile app (or any other app) over BLE

Hi,

I am using the standard ble uart code for ble communication. I am able to receive the data sent from the nrf Connect mobile app and debug it as per my need. All i have to do is edit the  nus_data_handler.

uint32_t i ;
     if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);

        for ( i = 0; i < p_evt->params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                printf("\r\nBLE Data 1 Byte Received : %c\r\n", p_evt->params.rx_data.p_data[i]);
               
                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                    APP_ERROR_CHECK(err_code);
                }

               if(p_evt->params.rx_data.p_data[i] == 'a')
                {
                  printf("Locker ID is %d" , p_evt->params.rx_data.p_data[i]) ;
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
        printf("\r\nData Over  - %d Length - %d \r\n",i,p_evt->params.rx_data.length) ;
        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
        {      
            
            while (app_uart_put('\n') == NRF_ERROR_BUSY);
        }
    }

But I am not getting where should I make changes in my code for the development to send the data to the nRF Connect app and how to see the received data on the app in TX Characteristic.

Parents
  • Hi 

    To send data from the nRF52 side to your app you should use the ble_nus_data_send(..) function, as shown on line 545 of main.c in the ble_app_uart example. 

    Please be aware that you need to enable notifications on the app side in order to see these updates, which you can do by clicking the small button with three arrows next to the TX characteristic. 
    Then you can swipe to the left to see the log, where incoming messages will be shown. 

    Best regards
    Torbjørn

Reply
  • Hi 

    To send data from the nRF52 side to your app you should use the ble_nus_data_send(..) function, as shown on line 545 of main.c in the ble_app_uart example. 

    Please be aware that you need to enable notifications on the app side in order to see these updates, which you can do by clicking the small button with three arrows next to the TX characteristic. 
    Then you can swipe to the left to see the log, where incoming messages will be shown. 

    Best regards
    Torbjørn

Children
No Data
Related