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

in \connect SDK\v1.5.0\nrf\samples\bluetooth\peripheral_uart,data number is limited 20 bytes, more than 20bytes BLE will part data in two or more packs to send or receive

in \connect SDK\v1.5.0\nrf\samples\bluetooth\peripheral_uart,data number is limited 20 bytes, more than 20bytes BLE will part data in two or more packs to send or receive .how can i chang to data number to more bytes. for example , i want to send 200 bytes through COM  in one time and BLE receive 200bytes i one time , relatively HOW to send 200bytes data in one time  through BLE ,not separate 200bytes data in many pack to send

  • Hi,

    20 byte is the maximum payload you get per packet without using DLE (GAP payload is 23 byte, and 3 byte GATT header leaving 20 byte data). To send longer packets you need to use data length extension. To support that you need to set CONFIG_BT_USER_DATA_LEN_UPDATE=y in your prj.conf and use bt_conn_le_data_len_update() to initiate the DLE procedure. You can see an example of this sin the Bluetooth: Throughput sample.

  • thank Einar Thorsrud ,in example throughput  need "

    Testing

    After programming the sample to both kits, test it by performing the following steps:

    ",now i have only one nrf5340dk board ,the test is a bluetooth APP in a phone with nrf5340dk , i cannot flash APP ,the APP GAP payload is more than 200 BYTES ,how can i send more than 20 bytes in a bluetooth packet to APP in example peripheral_uart

  • The example is intended for two DKs yes, but you can refer to the example to see how you can support data length update (DLE). You can see relevant configurations in the prj.conf. Specifically you should add:

    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

    If you want to start the DLE procedure from the nRF you call bt_conn_le_data_len_update()

  • in example peripheral_uart ,in function main() use err = bt_enable(NULL) creat two thread:

     /* TX thread */
    k_thread_create(&tx_thread_data, tx_thread_stack,
    K_KERNEL_STACK_SIZEOF(tx_thread_stack),
    hci_tx_thread, NULL, NULL, NULL,
    K_PRIO_COOP(CONFIG_BT_HCI_TX_PRIO),
    0, K_NO_WAIT);

    /* RX thread */
    k_thread_create(&rx_thread_data, rx_thread_stack,
    K_KERNEL_STACK_SIZEOF(rx_thread_stack),
    (k_thread_entry_t)hci_rx_thread, NULL, NULL, NULL,
    K_PRIO_COOP(CONFIG_BT_RX_PRIO),
    0, K_NO_WAIT);

    but in the file main.c , example use  below code to creat anther bluetooth TX thread and anther blue RX callback function :

    void ble_write_thread(void)
    {
    /* Don't go any further until BLE is initialized */
    k_sem_take(&ble_init_ok, K_FOREVER);

    for (;;) {
    /* Wait indefinitely for data to be sent over bluetooth */

    struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
    K_FOREVER);

    if (bt_nus_send(NULL, buf->data, buf->len)) {
    LOG_WRN("Failed to send data over BLE connection");
    }

    k_free(buf);

    }
    }

    K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL,
    NULL, PRIORITY, 0, 0);

    static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
    uint16_t len)
    {
    int err;
    char addr[BT_ADDR_LE_STR_LEN] = {0};

    bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

    LOG_INF("Received data from: %s", log_strdup(addr));

    for (uint16_t pos = 0; pos != len;) {
    struct uart_data_t *tx = k_malloc(sizeof(*tx));

    if (!tx) {
    LOG_WRN("Not able to allocate UART send data buffer");
    printk("Not able to allocate UART send data buffer");
    return;
    }

    /* Keep the last byte of TX buffer for potential LF char. */
    size_t tx_data_size = sizeof(tx->data) - 1;

    if ((len - pos) > tx_data_size) {
    tx->len = tx_data_size;
    } else {
    tx->len = (len - pos);
    }

    memcpy(tx->data, &data[pos], tx->len);

    pos += tx->len;

    /* Append the LF character when the CR character triggered
    * transmission from the peer.
    */

    if ((pos == len) && (data[len - 1] == '\r')) {
    tx->data[tx->len] = '\n';
    tx->len++;
    }

    err = uart_tx(uart, tx->data, tx->len, SYS_FOREVER_MS);
    if (err) {
    k_fifo_put(&fifo_uart_tx_data, tx);
    }

    }
    }

    WHAT'S RELATIONSHIP BETWEEN  thread/function created by FUNCTION bt_enable() and file main.c ?

  • Hi,

    The first code snippet is from the implementation of bt_enable(), which is in the host layer of the BT stack. So these are not something you normally need to think of at all as it is internal to the stack.

    The ble_write_thread() on the other hand is a thread implemented in the sample app that uses the BT API, and in an eternal loop pops incoming UART data from a queue and sends it over BLE NUS.

Related