how to send data over ble using NUS service

Hi nordic family,

I want to send this data to nrf Connect app.

void send_data_via_nus(float X, float Y, ble_nus_t nus_service)
{
uint8_t data[8];
memcpy(data, &X, sizeof(X));
memcpy(data + sizeof(X), &Y, sizeof(Y));

uint16_t length = sizeof(X) + sizeof(Y);
ret_code_t err_code;
err_code = ble_nus_data_send(&m_nus, data, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND))
{
APP_ERROR_CHECK(err_code);
}

}
 

 I am using ble_uart_example but I can't figure how to move forward in these specific parts nus_data_handler and in uart_event_handle, with this data 

Nrf SDK 16.00, S132, nrf52832

Parents Reply Children
  • I can't see any data transmitting on nrf Connect app when I enable notifications( nothing shows up there).

    I think so maybe I have not integrated NUS service properly because I am a newbie at Nordic devices and coding For example  I don't properly know how to call the variable "data" in nus_data_handler .
    And when I try to test that if I am getting data by printing that data to serial print nothing shows up there

  • I suggest you start playing with the example as is and modify it slightly so that you learn how it works. Essentially it does what you describe out of the box, just that the data you are sending is collected via UART, and the data array is sent with ble_nus_data_send() when there is a new-line.

    AIRAM said:
    I don't properly know how to call the variable "data" in nus_data_handler .

    The nus_data_handler function in the example is a callback that is called when data is received on the nRF side (so for the peripheral example here, that means data was sent from the central - nRF Connect app on a phone in your case). This is not relevant for sending data from the nRF to the phone. But again, I suggest you start with the example, play with it, perhaps add more logging and/or use a debugger just so you get a better understanding on how this works. Then you will be in a better position to modify things later.

Related