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

Using BLE NUS SERVICE without UART

Hello

I would like to send my sensor data to a mobile application using BLE SDK 15. Someone suggested me to go through the BLE NUS SERVICE example which was a good one. I understood a lot of things but now my sensor values are coming on analog pins and not on UART pins. How do i send those values? Would i have to create a whole new service for doing this or could i somehow modify the same example to work according to my needs. Thanks!  

Parents
  • err_code = 0x05 is NRF_ERROR_NOT_FOUND.

    This means that the ble_nus_data_send() receives an invalid conn_handle.

     

    What conn_handle do you insert?

    in ble_nus_data_send()?

    from the ble_app_uart example:

    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);

     

    Do you get this return value before or after you connect with the phone?

     

    Best regards,

    Edvin

  • Hello Edvin,

    That sounds about right. Actually, i do not understand the concept of connection handle, so i passed the same "m_conn_handle" in my ble_nus_data_send() function. The error comes before connection itself. Can you tell me a little about the connection handle ? or a link where i can learn bout it. Thanks,

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    int main(void)
    {
    bool erase_bonds;
    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hello,

    The explanation is using the unmodified ble_app_uart example:

    The connection handle is, during the startup of the ble_app_uart example, set to BLE_CONN_HANDLE_INVALID (= 0xFFFF).

    In the BLE_GAP_EVT_CONNECTED event in ble_evt_handler in main.c, the conn_handle, m_conn_handle is set to the conn_handle of the connection event, and it remains unchanged until the disconnected-event.

     

    If you look in the same example, in the uart_event_handle() in main.c, which is the only place using the ble_nus_data_send() function, you can see that it ignores returns from ble_nus_data_send if the err_code = NRF_ERROR_INVALID_STATE, NRF_ERROR_BUSY or NRF_ERROR_NOT_FOUND.

     

    It only means that it will not try to send anything if there is no device to send to.

    So you can ignore this error:

    Fullscreen
    1
    2
    3
    4
    5
    err_code = ble_nus_data_send(...)
    if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) && (err_code != NRF_ERROR_NOT_FOUND))
    {
    APP_ERROR_CHECK(err_code);
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    However, you can use these return values to tell your application that the message is not sent, if you need it. The fact that ble_nus_data_send() returns any of these values will not break anything, other than telling you that the message was not sent.

     

    Alternatively, you can check the conn_handle before you try to send:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    if(m_conn_handle !=·BLE_CONN_HANDLE_INVALID)
    {
    err_code = ble_nus_data_send(...);
    if (err_code != NRF_ERROR_INVALID_STATE && err_code != NRF_ERROR_BUSY)
    {
    APP_ERROR_CHECK(err_code);
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

     

    Best regards,

    Edvin

     

  • Hello Edvin,

    I went on to a different project but now i am again back to nrf52832 DK and want to send sensor data to mobile app. 

    I am running the ble app uart example. I have enabled the notification of TX characteristic(3 arrows downward) in nrf connect app but still i cannot send any data from Putty to app. I can not even write anything on my COM listener. Why is that so?    

  • Make sure that you set up the Putty Terminal correct, as described here:

    http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.2.0%2Flib_cli.html&anchor=lib_cli_terminal_settings

    Remember to follow both "Terminal settings" and "UART and USB settings".

    If you are having problems, check out the Termite Terminal. It is a bit more limited, but easier to set up.

    Best regards,

    Edvin

  • Hi , I am trying to do sth similar to arshdeep in the post. Send data via BLE from a custom PCB chip that has nrf52382. I start with the ble_template example in the SDK 15.2. The reason I don't start with ble_app_uart is that that does not work on my PCB device (device doesn't advertise when I flash it). 

    I am editting the ble_template to add NUS service, so that I can use nus_data_send() function. 
    However, when I do so, the code on the device doesn't give me anything, moreover my pcb custom device doesn't even advertise!! 


    Would you have any ideas pertaining this? I can share my code if you would like. It's the ble_template ex as is with just a few edits. 
    Thank you very much!! :) 

Reply
  • Hi , I am trying to do sth similar to arshdeep in the post. Send data via BLE from a custom PCB chip that has nrf52382. I start with the ble_template example in the SDK 15.2. The reason I don't start with ble_app_uart is that that does not work on my PCB device (device doesn't advertise when I flash it). 

    I am editting the ble_template to add NUS service, so that I can use nus_data_send() function. 
    However, when I do so, the code on the device doesn't give me anything, moreover my pcb custom device doesn't even advertise!! 


    Would you have any ideas pertaining this? I can share my code if you would like. It's the ble_template ex as is with just a few edits. 
    Thank you very much!! :) 

Children
No Data