This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ncs 1.6.1 peripheral_uart difference between nRFConnect for Mobile and nRFToolBox UART

Hi,

I work with win10 laptop, Toolchain  nrf Connect SDK 1.6.1 on a nrf5340dk.

I modifyed peripheral_uart to use 240 bytes like it's explain into  "ncs 1.6.1 peripheral_uart example - increasing NUS size" ticket:

https://devzone.nordicsemi.com/f/nordic-q-a/79654/ncs-1-6-1-peripheral_uart-example---increasing-nus-size/337721#337721

First question:

It's work perfectly with nRFToolBox but I realized that it's work diffrently with nRFConnect for Mobile.

With nRFToolBox I can send 239 bytes with Rx Characteristc and Tx charateristic.

But if i try with nRFConnect I can't send more then 19 bytes with Tx Characteristic and more then 36 bytes with Rx Characteristic.

On Rx I have the "error 9 (0x9) Gatt prepare Q full" when I send 37 bytes and on Tx I have the warning" No Att channel for MTU 24 / no buffer available to send notification / fialed to send data over BLE connection" when I send 20 bytes.

Why is that not working on nRFConnect ?

Second question:

During a BLE formation in France I learned that there is a negociation between the central and the peripheral before etablishing a connection about the size of MTU.

I need to transfert a lot of data by the uart connection and I want to be sure that I can send paquet of 239 bytes for each connection with any smartphone (Android).

Do you know how to retrieve the result of the negociation between the central (smartphone) and the peripheral (nrf5340dk) ?

Best Regards,

Rob.

Parents
  • It seems like more prepare writes are being performed than the config (CONFIG_BT_ATT_PREPARE_COUNT=2) set. Try to increase this size. It would be really good get a sniffer trance of the whole transaction in the not working setup (mobile) to get an even deeper understanding of the communication between your device and the mobile app.

  • Additionnal information:

    With "CONFIG_BT_ATT_PREPARE_COUNT=6" I 'm limited to 108 bytes on Rx characteristic.

    I put "CONFIG_BT_ATT_PREPARE_COUNT=15" then I can send more then 239 bytes on Rx characteristic, but I have a log inf:

    <log_strdup alloc failed>

    What does it mean ?

    Best Regards,

    Rob.

Reply
  • Additionnal information:

    With "CONFIG_BT_ATT_PREPARE_COUNT=6" I 'm limited to 108 bytes on Rx characteristic.

    I put "CONFIG_BT_ATT_PREPARE_COUNT=15" then I can send more then 239 bytes on Rx characteristic, but I have a log inf:

    <log_strdup alloc failed>

    What does it mean ?

    Best Regards,

    Rob.

Children
  • Not sure what is happening on the receiver end. A sniffer log would help a lot to understand the issue looking at the communication in detail. The logs are not very informative. Please share your modifications so that i can reproduce this or add detail sniffer logs for this communication.

  • Hi Susheel,

    Thank you for your help.

    I managed to get the sniffer to work.

    There is the communication and the log with nRF ToolBox UART:

    nrfToolBox_UART_peripheral_uart_256a.pcapng

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    [00:00:00.294,738] <inf> fs_nvs: 2 Sectors of 4096 bytes
    [00:00:00.294,738] <inf> fs_nvs: alloc wra: 0, fd0
    [00:00:00.294,738] <inf> fs_nvs: data wra: 0, 2c
    [00:00:00.314,880] <wrn> bt_ecc: ECC HCI commands not available
    [00:00:00.314,880] <inf> bt_hci_core: No ID address. App must call settings_load()
    [00:00:00.314,880] <inf> peripheral_uart_256a: Bluetooth initialized
    [00:00:00.322,174] <inf> peripheral_uart_256a: Starting Nordic UART service example
    [00:00:27.178,100] <inf> peripheral_uart_256a: Connected 67:9E:09:94:6D:66 (random)
    INCITAT environnement
    [00:00:29.662,414] <inf> peripheral_uart_256a: Received data from: 67:9E:09:94:6D:66 (random)
    01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678[00:00:32.831,878] <inf> peripheral_uart_256a: Received data from: 67:9E:09:94:6D:66 (random)
    01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678[00:00:34.734,741] <inf> peripheral_uart_256a: Received data from: 67:9E:09:94:6D:66 (random)
    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567801234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678[00:00:35.755,828] <inf> peripheral_uart_256a: Received data from: 67:9E:09:94:6D:66 (random)
    [00:00:36.730,804] <inf> peripheral_uart_256a: Received data from: 67:9E:09:94:6D:66 (random)
    [00:02:24.467,926] <inf> peripheral_uart_256a: Disconnected: 67:9E:09:94:6D:66 (random) (reason 19)
    

    I can see on line 1285 a sent write request where I send a packet 246 bytes (reassambled) and on line 4313 I received handle value notification a packet of 247 bytes (reassambled).

    There is the communication and the log with nRFConnect:

    nrfConnect_peripheral_uart_256a.pcapng

    *** Booting Zephyr OS build v2.6.0-rc1-ncs1  ***
    [00:00:00.266,571] <inf> fs_nvs: 2 Sectors of 4096 bytes
    [00:00:00.266,571] <inf> fs_nvs: alloc wra: 0, fd0
    [00:00:00.266,571] <inf> fs_nvs: data wra: 0, 2c
    [00:00:00.286,712] <wrn> bt_ecc: ECC HCI commands not available
    [00:00:00.286,712] <inf> bt_hci_core: No ID address. App must call settings_load()
    [00:00:00.286,743] <inf> peripheral_uart_256a: Bluetooth initialized
    [00:00:00.294,036] <inf> peripheral_uart_256a: Starting Nordic UART service example
    [00:00:14.707,366] <inf> peripheral_uart_256a: Connected 42:4B:13:7B:50:9B (random)
    [00:00:41.223,632] <wrn> bt_att: No ATT channel for MTU 30
    [00:00:41.223,632] <wrn> bt_gatt: No buffer available to send notification
    [00:00:41.223,632] <wrn> peripheral_uart_256a: Failed to send data over BLE connection
    01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789[00:01:05.717,132] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.717,285] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.717,437] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.717,590] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.717,742] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.717,895] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.718,048] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.718,231] <inf> peripheral_uart_256a: Received data from: 42:4B:13:7B:50:9B (random)
    [00:01:05.718,383] <inf> peripheral_uart_256a: Received data from: <log_strdup alloc failed>
    [00:01:05.718,505] <inf> peripheral_uart_256a: Received data from: <log_strdup alloc failed>
    [00:01:05.718,658] <inf> peripheral_uart_256a: Received data from: <log_strdup alloc failed>
    [00:01:05.718,841] <inf> peripheral_uart_256a: Received data from: <log_strdup alloc failed>
    [00:01:14.638,214] <inf> peripheral_uart_256a: Disconnected: 42:4B:13:7B:50:9B (random) (reason 19)
    

    I can see on line 9365 I received handle value notification a packet of 18 bytes.

    I cannot see the packet with more then 20 bytes send, where you have the warning "bt_att: No ATT channel for MTU 30 / bt_gatt: No buffer available to send notification / peripheral_uart_256a: Failed to send data over BLE connection" on the log message.

    I can see on line 10799 a sent write request where I send a packet of 18 bytes,

    line 10805 18 bytes more, line 10811 18bytes more, line 10817 18 bytes more..

    For a total 12 packet of 18 bytes where send (216 bytes).

    There is my project:

    3162.prj.conf4743.nrf5340dk_nrf5340_cpuapp.overlay

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    cmake_minimum_required(VERSION 3.13.1)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(NONE)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/main.c
    )
    # NORDIC SDK APP END
    
    zephyr_library_include_directories(.)
    
    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    source "Kconfig.zephyr"
    
    menu "Nordic UART BLE GATT service sample"
    
    config BT_NUS_THREAD_STACK_SIZE
    	int "Thread stack size"
    	default 1024
    	help
    	  Stack size used in each of the two threads
    
    config BT_NUS_UART_BUFFER_SIZE
    	int "UART payload buffer element size"
    	default 240
    	help
    	  Size of the payload buffer in each RX and TX FIFO element
    
    config BT_NUS_SECURITY_ENABLED
    	bool "Enable security"
    	default y
    	select BT_SMP
    	help
    	  "Enable BLE security for the UART service"
    
    config BT_NUS_UART_RX_WAIT_TIME
    	int "Timeout for UART RX complete event"
    	default 50
    	help
    	  Wait for RX complete event time in milliseconds
    
    endmenu
    

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    /** @file
     *  @brief Nordic UART Bridge Service (NUS) sample
     */
    
    #include <zephyr/types.h>
    #include <zephyr.h>
    #include <drivers/uart.h>
    
    #include <device.h>
    #include <soc.h>
    
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt.h>
    #include <bluetooth/hci.h>
    
    #include <bluetooth/services/nus.h>
    
    #include <dk_buttons_and_leds.h>
    
    #include <settings/settings.h>
    
    #include <stdio.h>
    
    #include <logging/log.h>
    
    #define LOG_MODULE_NAME peripheral_uart_256a
    LOG_MODULE_REGISTER(LOG_MODULE_NAME);
    
    #define STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
    #define PRIORITY 7
    
    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN	(sizeof(DEVICE_NAME) - 1)
    
    #define RUN_STATUS_LED DK_LED1
    #define RUN_LED_BLINK_INTERVAL 1000
    
    #define CON_STATUS_LED DK_LED2
    
    #define KEY_PASSKEY_ACCEPT DK_BTN1_MSK
    #define KEY_PASSKEY_REJECT DK_BTN2_MSK
    
    #define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE
    #define UART_WAIT_FOR_BUF_DELAY K_MSEC(50)
    #define UART_WAIT_FOR_RX CONFIG_BT_NUS_UART_RX_WAIT_TIME
    
    static K_SEM_DEFINE(ble_init_ok, 0, 1);
    
    static struct bt_conn *current_conn;
    static struct bt_conn *auth_conn;
    
    static const struct device *uart;
    static struct k_work_delayable uart_work;
    
    struct uart_data_t {
    	void *fifo_reserved;
    	uint8_t data[UART_BUF_SIZE];
    	uint16_t len;
    };
    
    static K_FIFO_DEFINE(fifo_uart_tx_data);
    static K_FIFO_DEFINE(fifo_uart_rx_data);
    
    static const struct bt_data ad[] = {
    	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    };
    
    static const struct bt_data sd[] = {
    	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
    };
    
    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	ARG_UNUSED(dev);
    
    	static uint8_t *current_buf;
    	static size_t aborted_len;
    	static bool buf_release;
    	struct uart_data_t *buf;
    	static uint8_t *aborted_buf;
    
    	switch (evt->type) {
    	case UART_TX_DONE:
    		if ((evt->data.tx.len == 0) ||
    		    (!evt->data.tx.buf)) {
    			return;
    		}
    
    		if (aborted_buf) {
    			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
    					   data);
    			aborted_buf = NULL;
    			aborted_len = 0;
    		} else {
    			buf = CONTAINER_OF(evt->data.tx.buf, struct uart_data_t,
    					   data);
    		}
    
    		k_free(buf);
    
    		buf = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);
    		if (!buf) {
    			return;
    		}
    
    		if (uart_tx(uart, buf->data, buf->len, SYS_FOREVER_MS)) {
    			LOG_WRN("Failed to send data over UART");
    		}
    
    		break;
    
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
    		buf->len += evt->data.rx.len;
    		buf_release = false;
    
    		if (buf->len == UART_BUF_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);
    		} else if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
    			  (evt->data.rx.buf[buf->len - 1] == '\r')) {
    			k_fifo_put(&fifo_uart_rx_data, buf);
    			current_buf = evt->data.rx.buf;
    			buf_release = true;
    			uart_rx_disable(uart);
    		}
    
    		break;
    
    	case UART_RX_DISABLED:
    		buf = k_malloc(sizeof(*buf));
    		if (buf) {
    			buf->len = 0;
    		} else {
    			LOG_WRN("Not able to allocate UART receive buffer");
    			k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
    			return;
    		}
    
    		uart_rx_enable(uart, buf->data, sizeof(buf->data),
    			       UART_WAIT_FOR_RX);
    
    		break;
    
    	case UART_RX_BUF_REQUEST:
    		buf = k_malloc(sizeof(*buf));
    		if (buf) {
    			buf->len = 0;
    			uart_rx_buf_rsp(uart, buf->data, sizeof(buf->data));
    		} else {
    			LOG_WRN("Not able to allocate UART receive buffer");
    		}
    
    		break;
    
    	case UART_RX_BUF_RELEASED:
    		buf = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t,
    				   data);
    		if (buf_release && (current_buf != evt->data.rx_buf.buf)) {
    			k_free(buf);
    			buf_release = false;
    			current_buf = NULL;
    		}
    
    		break;
    
    	case UART_TX_ABORTED:
    			if (!aborted_buf) {
    				aborted_buf = (uint8_t *)evt->data.tx.buf;
    			}
    
    			aborted_len += evt->data.tx.len;
    			buf = CONTAINER_OF(aborted_buf, struct uart_data_t,
    					   data);
    
    			uart_tx(uart, &buf->data[aborted_len],
    				buf->len - aborted_len, SYS_FOREVER_MS);
    
    		break;
    
    	default:
    		break;
    	}
    }
    
    static void uart_work_handler(struct k_work *item)
    {
    	struct uart_data_t *buf;
    
    	buf = k_malloc(sizeof(*buf));
    	if (buf) {
    		buf->len = 0;
    	} else {
    		LOG_WRN("Not able to allocate UART receive buffer");
    		k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
    		return;
    	}
    
    	uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);
    }
    
    static int uart_init(void)
    {
    	int err;
    	struct uart_data_t *rx;
    
    	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
    	if (!uart) {
    		return -ENXIO;
    	}
    
    	rx = k_malloc(sizeof(*rx));
    	if (rx) {
    		rx->len = 0;
    	} else {
    		return -ENOMEM;
    	}
    
    	k_work_init_delayable(&uart_work, uart_work_handler);
    
    	err = uart_callback_set(uart, uart_cb, NULL);
    	if (err) {
    		return err;
    	}
    
    	return uart_rx_enable(uart, rx->data, sizeof(rx->data), 50);
    }
    
    static void connected(struct bt_conn *conn, uint8_t err)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	if (err) {
    		LOG_ERR("Connection failed (err %u)", err);
    		return;
    	}
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    	LOG_INF("Connected %s", log_strdup(addr));
    
    	current_conn = bt_conn_ref(conn);
    
    	dk_set_led_on(CON_STATUS_LED);
    }
    
    static void disconnected(struct bt_conn *conn, uint8_t reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Disconnected: %s (reason %u)", log_strdup(addr), reason);
    
    	if (auth_conn) {
    		bt_conn_unref(auth_conn);
    		auth_conn = NULL;
    	}
    
    	if (current_conn) {
    		bt_conn_unref(current_conn);
    		current_conn = NULL;
    		dk_set_led_off(CON_STATUS_LED);
    	}
    }
    
    #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
    static void security_changed(struct bt_conn *conn, bt_security_t level,
    			     enum bt_security_err err)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (!err) {
    		LOG_INF("Security changed: %s level %u", log_strdup(addr),
    			level);
    	} else {
    		LOG_WRN("Security failed: %s level %u err %d", log_strdup(addr),
    			level, err);
    	}
    }
    #endif
    
    static struct bt_conn_cb conn_callbacks = {
    	.connected    = connected,
    	.disconnected = disconnected,
    #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
    	.security_changed = security_changed,
    #endif
    };
    
    #if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
    static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Passkey for %s: %06u", log_strdup(addr), passkey);
    }
    
    static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	auth_conn = bt_conn_ref(conn);
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Passkey for %s: %06u", log_strdup(addr), passkey);
    	LOG_INF("Press Button 1 to confirm, Button 2 to reject.");
    }
    
    
    static void auth_cancel(struct bt_conn *conn)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Pairing cancelled: %s", log_strdup(addr));
    }
    
    
    static void pairing_confirm(struct bt_conn *conn)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	bt_conn_auth_pairing_confirm(conn);
    
    	LOG_INF("Pairing confirmed: %s", log_strdup(addr));
    }
    
    
    static void pairing_complete(struct bt_conn *conn, bool bonded)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Pairing completed: %s, bonded: %d", log_strdup(addr),
    		bonded);
    }
    
    
    static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Pairing failed conn: %s, reason %d", log_strdup(addr),
    		reason);
    }
    
    
    static struct bt_conn_auth_cb conn_auth_callbacks = {
    	.passkey_display = auth_passkey_display,
    	.passkey_confirm = auth_passkey_confirm,
    	.cancel = auth_cancel,
    	.pairing_confirm = pairing_confirm,
    	.pairing_complete = pairing_complete,
    	.pairing_failed = pairing_failed
    };
    #else
    static struct bt_conn_auth_cb conn_auth_callbacks;
    #endif
    
    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");
    			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);
    		}
    	}
    }
    
    static struct bt_nus_cb nus_cb = {
    	.received = bt_receive_cb,
    };
    
    void error(void)
    {
    	dk_set_leds_state(DK_ALL_LEDS_MSK, DK_NO_LEDS_MSK);
    
    	while (true) {
    		/* Spin for ever */
    		k_sleep(K_MSEC(1000));
    	}
    }
    
    static void num_comp_reply(bool accept)
    {
    	if (accept) {
    		bt_conn_auth_passkey_confirm(auth_conn);
    		LOG_INF("Numeric Match, conn %p", (void *)auth_conn);
    	} else {
    		bt_conn_auth_cancel(auth_conn);
    		LOG_INF("Numeric Reject, conn %p", (void *)auth_conn);
    	}
    
    	bt_conn_unref(auth_conn);
    	auth_conn = NULL;
    }
    
    void button_changed(uint32_t button_state, uint32_t has_changed)
    {
    	uint32_t buttons = button_state & has_changed;
    
    	if (auth_conn) {
    		if (buttons & KEY_PASSKEY_ACCEPT) {
    			num_comp_reply(true);
    		}
    
    		if (buttons & KEY_PASSKEY_REJECT) {
    			num_comp_reply(false);
    		}
    	}
    }
    
    static void configure_gpio(void)
    {
    	int err;
    
    	err = dk_buttons_init(button_changed);
    	if (err) {
    		LOG_ERR("Cannot init buttons (err: %d)", err);
    	}
    
    	err = dk_leds_init();
    	if (err) {
    		LOG_ERR("Cannot init LEDs (err: %d)", err);
    	}
    }
    
    void main(void)
    {
    	int blink_status = 0;
    	int err = 0;
    
    	configure_gpio();
    
    	err = uart_init();
    	if (err) {
    		error();
    	}
    
    	bt_conn_cb_register(&conn_callbacks);
    
    	if (IS_ENABLED(CONFIG_BT_NUS_SECURITY_ENABLED)) {
    		bt_conn_auth_cb_register(&conn_auth_callbacks);
    	}
    
    	err = bt_enable(NULL);
    	if (err) {
    		error();
    	}
    
    	LOG_INF("Bluetooth initialized");
    
    	k_sem_give(&ble_init_ok);
    
    	if (IS_ENABLED(CONFIG_SETTINGS)) {
    		settings_load();
    	}
    
    	err = bt_nus_init(&nus_cb);
    	if (err) {
    		LOG_ERR("Failed to initialize UART service (err: %d)", err);
    		return;
    	}
    
    	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
    			      ARRAY_SIZE(sd));
    	if (err) {
    		LOG_ERR("Advertising failed to start (err %d)", err);
    		printk("Advertising failed to start\n");
    	}
    
    	//printk("Starting Nordic UART service example\n");
    	LOG_INF("Starting Nordic UART service example");
    
    	for (;;) {
    		//printk("loop while\n");
    		//LOG_INF("loop while");
    		
    		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
    		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
    	}
    }
    
    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);
    

    Best Regards,

    Rob.

  • Additionnal information:

    I resolved the log inf: <log_strdup alloc failed>, by insering in prj.conf file:

    CONFIG_LOG_STRDUP_MAX_STRING=251
    CONFIG_LOG_STRDUP_BUF_COUNT=15

    but I still have the problem with:

    [00:00:41.223,632] <wrn> bt_att: No ATT channel for MTU 30
    [00:00:41.223,632] <wrn> bt_gatt: No buffer available to send notification
    [00:00:41.223,632] <wrn> peripheral_uart_256a: Failed to send data over BLE connection

    I cannot send from the computer to the smartphone more then 19 bytes with nRFConnect.

  • Hi Susheel,

    I find this post:

    https://devzone.nordicsemi.com/f/nordic-q-a/74604/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/309239#309239

    That explain how to modify MTU size on the app nRFConnect, on the top right the there is 3 dots ranged verticaly, there I can modify "request MTU". I put 239 and I no more error, I can send enougth bytes with nRFConnect now !

  • Great, 

    The IOS version I have does not seem to support this.functionality.

Related