Sending data over bluetooth to a peripheral UART

Greetings Nordic Team,

I am trying to pass data from an application on a dk-nrf52840 to a nrf52840-dongle whose uart is connected to the uart on a microcontroller.
Using the example programs for central_uart and peripheral_uart in nrf connect desktop. everything works fine sending data to and from the respective central and peripheral uarts.
However, I need to send internal data from the application on the dk to the dongles uart (and vice versa). I thought it would be simple enough to just use the
bt_nus_client_send() function, and replace the buf->data and buf->len with my own data. Alas, this only results in an error.

//this is my attempt to use bt_nus_client_send()
char internal_data[UART_BUF_SIZE]={"Jim was here."};
uint16_t length = sizeof(internal_data);
err = bt_nus_client_send(&nus_client, internal_data, length);
if (err) {
LOG_WRN("Fudge! Failed to send data over BLE connection"
"(err %d)", err);
}

//this is the error
<wrn> central_uart: Fudge! Failed to send data over BLE connection(err -128)

//this is the working sample code
for (;;) {
/* Wait indefinitely for data to be sent over Bluetooth */
struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
K_FOREVER);

err = bt_nus_client_send(&nus_client, buf->data, buf->len);
if (err) {
LOG_WRN("Failed to send data over BLE connection"
"(err %d)", err);
}

err = k_sem_take(&nus_write_sem, NUS_WRITE_TIMEOUT);
if (err) {
LOG_WRN("NUS send timeout");
}
}
any sugestions?

Parents
  • Greetings Karl,

    There is no arguing that the do while loop is bad form, but for debugging,
    it did reveal that it takes a second for the physical connection to complete.
    I can just put in a delay to wait a few seconds and then start sending data.
    Now the data is sent to and received by peripheral.
    Is there a function to test for connectedness?
    However, as soon as the data is transmitted over to the peripheral, the
    central unit generates an error causing it to restart.
    Can you tell me what might cause this?

    //my code inserted in the central_uart example just before infinite for loop
    char internal_data[UART_BUF_SIZE]={"Jim was here."};
    uint16_t length = sizeof(internal_data);
    nrf_delay_ms(5000);
    printf("\n\rSending %s to nRF52840 dongle",internal_data);

    err = bt_nus_client_send(&nus_client, internal_data, length);
    if (err) {
    LOG_WRN("Initial Error# %d", err);
    }


    //Debug Terminal Output
    <inf>[00:00:00.006,958] [0m<inf> fs_nvs: alloc wra: 0, fb8
    <inf> fs_nvs: data wra: 0, 88
    <inf> sdc_hci_driver: SoftDevice Controller build revision:
    0e e7 c5 66 67 18 3c ac b3 d2 cc 81 a3 dc f1 c0 |...fg.<. ........
    c0 36 02 22 |.6."
    <inf> bt_hci_core: No ID address. App must call settings_load()
    <inf> central_uart: Bluetooth initialized
    <inf> central_uart: Scan module initialized
    <inf> central_uart: NUS Client module initialized
    <inf> central_uart: Filters matched. Address: DF:FE:3E:E2:44:AE (random) connectable: 0
    <inf> central_uart: Connected: DF:FE:3E:E2:44:AE (random)
    <inf> central_uart: Security changed: DF:FE:3E:E2:44:AE (random) level 2
    <inf> central_uart: MTU exchange done
    <inf> central_uart: Service discovery completed

    <err> os: r0/a1: 0x00000004 r1/a2: 0x00000081 r2/a3: 0x00000001
    <err> os: r3/a4: 0x000202ad r12/ip: 0x00000000 r14/lr: 0x00023f7b
    <err> os: xpsr: 0x41000000
    <err> os: Faulting instruction address (r15/pc): 0x0002a854
    <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    <err> os: Current thread: 0x20001a20 (unknown)
    <err> fatal_error: Resetting system

  • Hello again, jim-ellyson

    Thank you for your extreme patience with this. I have been out of office for some time, but now I am back.

    Do you still require technical support with this issue?

    To round off the remaining questions from the previous comment:

    Jim Ellyson said:
    I can just put in a delay to wait a few seconds and then start sending data.
    Now the data is sent to and received by peripheral.
    Is there a function to test for connectedness?

    Yes, you can use the connection handle, for instance, to see this - I would recommend this approach rather than waiting for an arbitrary number of seconds, since the connection can take longer for many different reasons.

    Jim Ellyson said:
    However, as soon as the data is transmitted over to the peripheral, the
    central unit generates an error causing it to restart.
    Can you tell me what might cause this?

    It seems to me that it never makes it to the code you have included, could you post more of the relevant code?
    Is the shown lines the only modification you've made to the default central_uart code?

    Best regards,
    Karl

  • Hi  ,

    How did you resolve this issue?

    Hi  

    I also get the same error when I tried to modify the code for the central_uart to send command. What is the fix for the errors? 

    Thanks,

    oli

  • Hello Oli,

    In the case that Jim does not reply to this I would recommend that you create a separate ticket for your issue so that you can elaborate on what you are trying to achieve, the changes you have made, and the errors you are encountering.

    Best regards,
    Karl

  • Greetings Oli and Karl,

    I'm sorry, for the slow response. I have been having issues trying to log into this site the past few weeks and not getting a response from nordic with password reset.

    Seems to be working great now(the login). Karl, hope you enjoyed your vacation.

    I have not resolved issue with the central_uart example using bl_nus_client_send() function in the nRF Connect for Desktop. It just reboots right after sending.

    As a workaround:

    Currently I'm using the nRF5 SDK example ble_app_uart_c which uses the function ble_nus_c_string_send(). That works fine. And I have been developing my project around those examples.

    It would be nice to be able to use the newer examples and the newer developer framework.

    To answer an earlier question, no, Karl I didn't change anything in the sample code except for the snipet I posted.

    Thank you. 

  • Hi Jim, 

    Thanks for the response. I think I just found the answer to the errors that you and I had. I found it in this issue: Central node crashes just after sending data 

    I tried it and it does not crash anymore. I don't know if there would be implications in removing this part of the code. Probably  would be able to shed some light. 

    Thanks,

    oli

Reply Children
Related