bt_nus_client_send\bt_nus_send

  

I'm using 2 nrf52840dk, ncs2.5.0; running the central_uart and peripheral_uart examples, I want to know how to send a string without pressing the "enter" key. For example, central_uart returns character "b" immediately after receiving a character "a" (use bt_nus_client_send() without pressing the "enter" key).

Parents
  • Hi,

    bt_nus_client_send() can be used to send any data. The UART handling in the sample is a bit complex however, and it looks for a line break "\n" or "\r". You can avoid waiting for a line break by commenting out a few lines like this:

    diff --git a/samples/bluetooth/peripheral_uart/src/main.c b/samples/bluetooth/peripheral_uart/src/main.c
    index d42e89071..f0dd16058 100644
    --- a/samples/bluetooth/peripheral_uart/src/main.c
    +++ b/samples/bluetooth/peripheral_uart/src/main.c
    @@ -135,11 +135,11 @@ static void uart_cb(const struct device *dev, struct uart_event *evt, void *user
                            return;
                    }
     
    -               if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    -                   (evt->data.rx.buf[buf->len - 1] == '\r')) {
    -                       disable_req = true;
    +               // if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    +               //     (evt->data.rx.buf[buf->len - 1] == '\r')) {
    +               //      disable_req = true;
                            uart_rx_disable(uart);
    -               }
    +               // }
     
                    break;
     

Reply
  • Hi,

    bt_nus_client_send() can be used to send any data. The UART handling in the sample is a bit complex however, and it looks for a line break "\n" or "\r". You can avoid waiting for a line break by commenting out a few lines like this:

    diff --git a/samples/bluetooth/peripheral_uart/src/main.c b/samples/bluetooth/peripheral_uart/src/main.c
    index d42e89071..f0dd16058 100644
    --- a/samples/bluetooth/peripheral_uart/src/main.c
    +++ b/samples/bluetooth/peripheral_uart/src/main.c
    @@ -135,11 +135,11 @@ static void uart_cb(const struct device *dev, struct uart_event *evt, void *user
                            return;
                    }
     
    -               if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    -                   (evt->data.rx.buf[buf->len - 1] == '\r')) {
    -                       disable_req = true;
    +               // if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    +               //     (evt->data.rx.buf[buf->len - 1] == '\r')) {
    +               //      disable_req = true;
                            uart_rx_disable(uart);
    -               }
    +               // }
     
                    break;
     

Children
No Data
Related