Communicate two microcontrollers via BLE

Hello,

I'm using a nRF52 DK to test BLE communication with another microcontroller. What I need to test is the nRF52 pairing with another brand microcontroller, send a data stream and close the connection.

Could you please tell me which example from the Bluetooth samples list I can use for starting?

Thanks for your attention.

Regards,

Parents
  • Hello ,

    Thank you very much. I've reviewed this example and it is supposed to connect with the first device with an strong signal. Is there a way to force the board to connect with the device with a given MAC address?

  • You will get a code assert if you call k_free() on a pointer that has not been allocated from heap, and k_sem_give() is redundant as you are not using k_sem_take().

    Unknown said:
    The ESP32 already has a UUID which allows sending strings from a mobile application. Is there something particular to nRF52 in the implementation of NUS?

    You need to implement your own GATT Client which matches the GATT server on your ESP32. The NUS client will only work with the NUS service: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/bluetooth_services/services/nus.html 

    You may be able to use the existing NUS client as a starting point and change out the UUIDs to match the UUIDs used by the ESP.

    Unknown said:
    Moreover, could you please explain me how the 'pairing_failed' function is called? As it is declared as a callback function it is not clear for me under which situation it is launched.

    The pairing is handled by the Zephyr Bluetooth host and it will invoke the pairing failed or pairing success callback depending on the outcome.

    Are you still getting the pairing error? If so, is there a long (i.e. several seconds) delay before the pairing failed is called?

  • You may be able to use the existing NUS client as a starting point and change out the UUIDs to match the UUIDs used by the ESP.

    In the project I've sent the UUIDs were already changed :

    /** @brief UUID of the NUS Service. **/
    #define BT_UUID_NUS_VAL \
    	BT_UUID_128_ENCODE(0x0000FFFF, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB)
    
    /** @brief UUID of the TX Characteristic. **/
    #define BT_UUID_NUS_TX_VAL \
    	BT_UUID_128_ENCODE(0x0000FF01, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB)
    
    /** @brief UUID of the RX Characteristic. **/
    #define BT_UUID_NUS_RX_VAL \
    	BT_UUID_128_ENCODE(0x0000FF02, 0x0000, 0x1000, 0x8000, 0x00805F9B34FB)

    Are you still getting the pairing error? If so, is there a long (i.e. several seconds) delay before the pairing failed is called?

    Yes, it still fails after several seconds (31 send failed tries). Below the terminal output:

    Starting Bluetooth Central UART example
    scan err: 0
    Scanning
    Scanning successfully started
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    connected conn_err: 0
    Connected: 60:55:F9:F5:29:D2 (public)
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    Service discovery completed

  • Unknown said:
    In the project I've sent the UUIDs were already changed :

    The NUS client is implemented in the SDK tree, so the changes you made were not included in the project you shared. 

    Unknown said:
    Yes, it still fails after several seconds (31 send failed tries). Below the terminal output:

    The Service discovery callback is invoked almost immediately after the connection is established, so I suspect the pairing process is interfering with the discovery procedure in your case.

    Please build your project with the following settings to print the services and characteristics found in the discovery procedure:

    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_LOG_PRINTK=n
    CONFIG_BT_DEBUG_LOG=y
    CONFIG_BT_GATT_DM_DATA_PRINT=y

    Here is the log I got for comparison:

    Starting Bluetooth Central UART example
    Scanning successfully started
    Failed to send data over BLE connection(err -128)
    [00:00:00.016,296] <inf> fs_nvs: nvs_mount: 6 Sectors of 4096 bytes
    [00:00:00.016,326] <inf> fs_nvs: nvs_mount: alloc wra: 0, fb8
    [00:00:00.016,326] <inf> fs_nvs: nvs_mount: data wra: 0, 88
    [00:00:00.016,510] <inf> bt_sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision: 
                                                d8 0c 2d 2f 36 ae e2 5c  80 26 80 4c 3f 4d 16 53 |..-/6..\ .&.L?M.S
                                                50 96 c7 73                                      |P..s             
    [00:00:00.020,233] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.020,263] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)
    [00:00:00.020,294] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 216.11532 Build 3803067951
    [00:00:00.020,935] <inf> bt_hci_core: bt_init: No ID address. App must call settings_load()
    [00:00:00.024,353] <inf> central_uart: main: Bluetooth initialized
    [00:00:00.025,329] <inf> bt_hci_core: bt_dev_show_info: Identity: C4:A1:E3:04:97:3B (random)
    [00:00:00.025,360] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x124b, manufacturer 0x0059
    [00:00:00.025,390] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0x124b
    [00:00:00.033,874] <inf> central_uart: scan_init: Scan module initialized
    [00:00:00.039,367] <inf> central_uart: nus_client_init: NUS Client module initialized
    [00:00:00.050,048] <inf> central_uart: main: Scanning successfully started
    [00:00:00.054,962] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:00.061,187] <wrn> central_uart: main: NUS send timeout
    connected conn_err: 0
    Failed to send data over BLE connection(err -128)
    [00:00:00.430,145] <inf> central_uart: scan_filter_match: Filters matched. Address: E0:73:95:EE:95:5F (random) connectable: 1
    [00:00:00.433,166] <inf> central_uart: scan_filter_match: Filters matched. Address: E0:73:95:EE:95:5F (random) connectable: 0
    [00:00:00.433,197] <wrn> central_uart: scan_connecting_error: Connecting failed
    [00:00:00.534,973] <inf> central_uart: connected: Connected: E0:73:95:EE:95:5F (random)
    [00:00:00.534,973] <wrn> central_uart: connected: Sending pairing req.
    [00:00:00.932,800] <inf> central_uart: security_changed: Security changed: E0:73:95:EE:95:5F (random) level 2
    [00:00:01.061,492] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:01.067,596] <wrn> central_uart: main: NUS send timeout
    Service discovery completed
    ATT[1]:         UUID: 0x2803    Handle: 0x0011  Value:
            Characteristic: 0x6e400003-b5a3-f393-e0a9-e50e24dcca9e  Properties: 0x0010
    ATT[2]:         UUID: 0x6e400003-b5a3-f393-e0a9-e50e24dcca9e    Handle: 0x0012  Value:
    ATT[3]:         UUID: 0x2902    Handle: 0x0013  Value:
            CCCD
    ATT[4]:         UUID: 0x2803    Handle: 0x0014  Value:
            Characteristic: 0x6e400002-b5a3-f393-e0a9-e50e24dcca9e  Properties: 0x000C
    ATT[5]:         UUID: 0x6e400002-b5a3-f393-e0a9-e50e24dcca9e    Handle: 0x0015  Value:
    [00:00:01.882,415] <inf> central_uart: discovery_complete: Service discovery completed
    

  • The NUS client is implemented in the SDK tree, so the changes you made were not included in the project you shared. 

    But are the changes included in the project in my computer?

    Below the log I got:

    *** Booting Zephyr OS build v3.2.99-ncs2 ***
    bt_conn_auth_cb_register
    bt_conn_auth_info_cb_register err: 0
    bt_enable err: 0
    Bluetooth initialized
    uart_init
    scan_init
    Address filter added 60:55:F9:F5:29:D2 (public)
    Scan module initialized
    bt_nus_client_init
    NUS Client module initialized
    
    Starting Bluetooth Central UART example
    scan err: 0
    Scanning
    Scanning successfully started
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:00.017,456] <inf> fs_nvs: nvs_mount: 6 Sectors of 4096 bytes
    [00:00:00.017,486] <inf> fs_nvs: nvs_mount: alloc wra: 0, fe8
    [00:00:00.017,517] <inf> fs_nvs: nvs_mount: data wra: 0, 0
    [00:00:00.017,669] <inf> bt_sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision: 
                                                d8 0c 2d 2f 36 ae e2 5c  80 26 80 4c 3f 4d 16 53 |..-/6..\ .&.L?M.S
                                                50 96 c7 73                                      |P..s             
    [00:00:00.021,026] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.021,057] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)
    [00:00:00.021,087] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 216.11532 Build 3803067951
    [00:00:00.021,667] <inf> bt_hci_core: bt_init: No ID address. App must call settings_load()
    [00:00:00.025,177] <inf> central_uart: main: Bluetooth initialized
    [00:00:00.025,817] <inf> bt_hci_core: bt_dev_show_info: Identity: D7:C8:04connected conn_err: 0
    Connected: 60:55:F9:F5:29:D2 (public)
    :2D:97:BA (random)
    [00:00:00.025,848] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x124b, manufacturer 0x0059
    [00:00:00.025,909] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0x124b
    [00:00:00.034,240] <inf> central_uart: scan_init: Scan module initialized
    [00:00:00.039,733] <inf> central_uart: nus_client_init: NUS Client module initialized
    [00:00:00.052,795] <inf> central_uart: main: Scanning successfully started
    [00:00:00.058,654] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:00.064,880] <wrn> central_uart: main: NUS send timeout
    [00:00:00.117,584] <inf> central_uart: scan_filter_match: Filters matched. Address: 60:55:F9:F5:29:D2 (public) connectable: 1
    [00:00:00.120,239] <inf> central_uart: scan_filter_match: Filters matched. Address: 60:55:F9:F5:29:D2 (public) connectable: 0
    [00:00:00.120,269] <wrn> central_uart: scan_connecting_error: Connecting failed
    [00:00:00.287,994] <inf> central_uart: connected: Connected: 60:55:F9:F5:29:D2 (public)
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:00.586,059] <inf> central_uart: exchange_func: MTU exchange done
    [00:00:01.069,122] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:01.075,317] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:02.079,681] <wrn> central_uart: main: Failed to senreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    d data over BLE connection(err -128)
    [00:00:02.086,212] <wrn> central_uart: main: NUS send timeout
    [00:00:03.090,545] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:03.096,740] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:04.101,104] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:04.107,330] <wrn> central_uart: main: NUS send timeout
    [00:00:05.111,602] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:05.117,797] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:06.122,100] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:06.128,326] <wrn> central_uart: main: NUS send timeout
    [00:00:07.132,598] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:07.139,129] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:08.143,524] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:08.149,719] <wrn> central_uart: main: NUS send timeout
    [00:00:09.153,961] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:09.160,156] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:10.164,459] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:10.170,654] <wrn> central_uart: main: NUS send timeout
    [00:00:11.174,957] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:11.181,182] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:12.185,821] <wrn> central_uart: main: Failed to sreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    end data over BLE connection(err -128)
    [00:00:12.191,925] <wrn> central_uart: main: NUS send timeout
    [00:00:13.196,258] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:13.202,484] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:14.206,756] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:14.212,951] <wrn> central_uart: main: NUS send timeout
    [00:00:15.217,193] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:15.223,388] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:16.227,722] <wrn> central_uart: main: Failed to sreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    end data over BLE connection(err -128)
    [00:00:16.233,947] <wrn> central_uart: main: NUS send timeout
    [00:00:17.238,372] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:17.244,598] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:18.248,870] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:18.255,065] <wrn> central_uart: main: NUS send timeout
    [00:00:19.259,307] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:19.265,533] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:20.269,866] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:20.276,092] <wrn> central_uart: main: NUS send timeout
    [00:00:21.280,303] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:21.286,743] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:22.291,107] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:22.297,302] <wrn> central_uart: main: NUS send timeout
    [00:00:23.301,696] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:23.307,891] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:24.312,286] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:24.318,481] <wrn> central_uart: main: NUS send timeout
    [00:00:25.322,784] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:25.329,010] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:26.333,343] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:26.339,843] <wrn> central_uart: main: NUS send timeout
    [00:00:27.344,207] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:27.350,433] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:28.354,766] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:28.360,992] <wrn> central_uart: main: NUS send timeout
    [00:00:29.365,264] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:29.371,490] <wrn> central_uart: main: NUS send timeout
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    Service discovery completed
    ATT[1]:         UUID: 0x2803    Handle: 0x0029  Value:
            Characteristic: 0xff01  Properties: 0x0008
    ATT[2]:         UUID: 0xff01    Handle: 0x002A  Value:
    ATT[3]:         UUID: 0x2803    Handle: 0x002B  Value:
            Characteristic: 0xff02  Properties: 0x0012
    ATT[4]:         UUID: 0xff02    Handle: 0x002C  Value:
    ATT[5]:         UUID: 0x2902    Handle: 0x002D  Value:
            CCCD
    [00:00:30.293,670] <err> bt_smp: smp_timeout: SMP Timeout
    [00:00:30.294,281] <wrn> central_uart: security_changed: Security failed: 60:55:F9:F5:29:D2 (public) level 1 err 9
    [00:00:30.294,677] <wrn> central_uart: pairing_failed: Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    [00:00:30.375,762] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:30.381,958] <wrn> central_uart: main: NUS send timeout
    [00:00:30.936,035] <inf> central_uart: discovery_complete: Service discovery completed
    [00:00:30.978,515] <err> nus_c: bt_nus_handles_assign: Missing NUS TX CCC in characteristic.
    [00:00:31.436,035] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:32.436,065] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:33.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:34.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:35.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:36.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:37.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:38.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:39.536,010] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:40.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:41.536,071] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:42.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:43.586,029] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:44.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:45.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:46.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:47.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:48.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:49.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:50.536,010] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:51.486,022] <wrn> central_uart: ble_data_sent: ATT error code: 0x01
    [00:00:52.585,998] <wrn> central_uart: ble_data_sent: ATT error code: 0x01

  • Now I can see the pairing is failing due to a timeout. It is probably blocked by the service discovery. 

    The ESP32 uses 16-bit services not 128-bit vendor specific services as NUS does. This means you need to change the UUID declarations from 128-bits to 16-bits uuids with BT_UUID_DECLARE_16().

    But are the changes included in the project in my computer?

    Yes, in your local NCS copy.

Reply Children
  • This means you need to change the UUID declarations from 128-bits to 16-bits uuids with BT_UUID_DECLARE_16().

    I have just made this change and now I have errors like this in many lines:

    error: macro "BT_UUID_INIT_16" passed 2 arguments, but takes just 1
      161 |         gatt_desc = bt_gatt_dm_desc_by_uuid(dm, gatt_chrc, BT_UUID_NUS_RX);

    Do I have to replace functions?

  • I solve this problem by replacing:

    /** @brief UUID of the NUS Service. **/
    #define BT_UUID_NUS_VAL \
    	BT_UUID_16_ENCODE(0xFFFF)
    
    /** @brief UUID of the TX Characteristic. **/
    #define BT_UUID_NUS_TX_VAL \
    	BT_UUID_16_ENCODE(0xFF01)
    
    /** @brief UUID of the RX Characteristic. **/
    #define BT_UUID_NUS_RX_VAL \
    	BT_UUID_16_ENCODE(0xFF02)

    by:

    /** @brief UUID of the NUS Service. **/
    #define BT_UUID_NUS_VAL \
    	(BT_UUID_16_ENCODE(0xFFFF))
    
    /** @brief UUID of the TX Characteristic. **/
    #define BT_UUID_NUS_TX_VAL \
    	(BT_UUID_16_ENCODE(0xFF01))
    
    /** @brief UUID of the RX Characteristic. **/
    #define BT_UUID_NUS_RX_VAL \
    	(BT_UUID_16_ENCODE(0xFF02))

    After having flashed the nRF52 the data is not sent yet and I don't see anymore the UUID in the log (the discovery service is not found). Below the log output:

    *** Booting Zephyr OS build v3.2.99-ncs2 ***
    bt_conn_auth_cb_register
    bt_conn_auth_info_cb_register err: 0
    bt_enable err: 0
    Bluetooth initialized
    uart_init
    scan_init
    Address filter added 60:55:F9:F5:29:D2 (public)
    Scan module initialized
    bt_nus_client_init
    NUS Client module initialized
    
    Starting Bluetooth Central UART example
    scan err: 0
    Scanning
    Scanning successfully started
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:00.017,303] <inf> fs_nvs: nvs_mount: 6 Sectors of 4096 bytes
    [00:00:00.017,333] <inf> fs_nvs: nvs_mount: alloc wra: 0, fe8
    [00:00:00.017,364] <inf> fs_nvs: nvs_mount: data wra: 0, 0
    [00:00:00.017,486] <inf> bt_sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision: 
                                                d8 0c 2d 2f 36 ae e2 5c  80 26 80 4c 3f 4d 16 53 |..-/6..\ .&.L?M.S
                                                50 96 c7 73                                      |P..s             
    [00:00:00.020,843] <inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)
    [00:00:00.020,874] <inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)
    [00:00:00.020,904] <inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 216.11532 Build 3803067951
    [00:00:00.021,453] <inf> connected conn_err: 0
    Connected: 60:55:F9:F5:29:D2 (public)
    bt_hci_core: bt_init: No ID address. App must call settings_load()
    [00:00:00.024,963] <inf> central_uart: main: Bluetooth initialized
    [00:00:00.025,604] <inf> bt_hci_core: bt_dev_show_info: Identity: D7:C8:04:2D:97:BA (random)
    [00:00:00.025,634] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x124b, manufacturer 0x0059
    [00:00:00.025,695] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0x124b
    [00:00:00.034,118] <inf> central_uart: scan_init: Scan module initialized
    [00:00:00.039,611] <inf> central_uart: nus_client_init: NUS Client module initialized
    [00:00:00.052,642] <inf> central_uart: main: Scanning successfully started
    [00:00:00.058,929] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:00.065,124] <wrn> central_uart: main: NUS send timeout
    [00:00:00.069,824] <inf> central_uart: scan_filter_match: Filters matched. Address: 60:55:F9:F5:29:D2 (public) connectable: 1
    [00:00:00.072,082] <inf> central_uart: scan_filter_match: Filters matched. Address: 60:55:F9:F5:29:D2 (public) connectable: 0
    [00:00:00.072,113] <wrn> central_uart: scan_connecting_error: Connecting failed
    [00:00:00.241,516] <inf> central_uart: connected: Connected: 60:55:F9:F5:29:D2 (public)
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:00.539,489] <inf> central_uart: exchange_func: MTU exchange done
    [00:00:01.069,519] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:01.075,714] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:02.080,017] <wrn> central_uart: main: Failed to senreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    d data over BLE connection(err -128)
    [00:00:02.086,242] <wrn> central_uart: main: NUS send timeout
    [00:00:03.090,759] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:03.096,954] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:04.101,257] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:04.107,482] <wrn> central_uart: main: NUS send timeout
    [00:00:05.111,785] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:05.118,011] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:06.122,375] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:06.128,601] <wrn> central_uart: main: NUS send timeout
    [00:00:07.132,904] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:07.139,221] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:08.143,402] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:08.149,627] <wrn> central_uart: main: NUS send timeout
    [00:00:09.153,900] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:09.160,125] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:10.164,520] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:10.170,745] <wrn> central_uart: main: NUS send timeout
    [00:00:11.175,048] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:11.181,274] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:12.185,638] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:12.192,108] <wrn> central_uart: main: NUS send timeout
    [00:00:13.196,350] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:13.202,575] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:14.206,970] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:14.213,195] <wrn> central_uart: main: NUS send timeout
    [00:00:15.217,468] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:15.223,693] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:16.227,996] <wrn> central_uart: main: Failed to sreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    end data over BLE connection(err -128)
    [00:00:16.234,222] <wrn> central_uart: main: NUS send timeout
    [00:00:17.238,525] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:17.244,995] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:18.249,267] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:18.255,462] <wrn> central_uart: main: NUS send timeout
    [00:00:19.259,704] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:19.265,899] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:20.270,263] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:20.276,489] <wrn> central_uart: main: NUS send timeout
    [00:00:21.280,670] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:21.286,895] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:22.291,442] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:22.297,668] <wrn> central_uart: main: NUS send timeout
    [00:00:23.301,940] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:23.308,166] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:24.312,408] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:24.318,634] <wrn> central_uart: main: NUS send timeout
    [00:00:25.322,967] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:25.329,193] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:26.333,435] <wrn> central_uart: main: Failed to senreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    d data over BLE connection(err -128)
    [00:00:26.339,965] <wrn> central_uart: main: NUS send timeout
    [00:00:27.344,238] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:27.350,433] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:28.354,766] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:28.361,022] <wrn> central_uart: main: NUS send timeout
    [00:00:29.365,295] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:29.371,551] <wrn> central_uart: main: NUS send timeout
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    Service not found
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:30.247,192] <err> bt_smp: smp_timeout: SMP Timeout
    [00:00:30.247,802] <wrn> central_uart: security_changed: Security failed: 60:55:F9:F5:29:D2 (public) level 1 err 9
    [00:00:30.248,168] <wrn> central_uart: pairing_failed: Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    [00:00:30.339,447] <inf> central_uart: discovery_service_not_found: Service not found
    [00:00:30.375,793] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:30.382,019] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:31.386,260] <wrn> central_uart: main: Failed to sreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    end data over BLE connection(err -128)
    [00:00:31.392,517] <wrn> central_uart: main: NUS send timeout
    [00:00:32.396,789] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:32.403,015] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:33.407,287] <wrn> central_uart: main: Failed to sendreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
     data over BLE connection(err -128)
    [00:00:33.413,513] <wrn> central_uart: main: NUS send timeout
    [00:00:34.417,907] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:34.424,102] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:35.428,405] <wrn> central_uart: main: Failed to senreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    d data over BLE connection(err -128)
    [00:00:35.434,631] <wrn> central_uart: main: NUS send timeout
    [00:00:36.439,147] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:36.445,251] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:37.449,523] <wrn> central_uart: main: Failed to sreturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    end data over BLE connection(err -128)
    [00:00:37.455,749] <wrn> central_uart: main: NUS send timeout
    [00:00:38.460,052] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:38.466,247] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    [00:00:39.470,550] <wrn> central_uart: main: Failed to sereturn ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout
    nd data over BLE connection(err -128)
    [00:00:39.476,745] <wrn> central_uart: main: NUS send timeout
    [00:00:40.481,018] <wrn> central_uart: main: Failed to send data over BLE connection(err -128)
    [00:00:40.487,243] <wrn> central_uart: main: NUS send timeout
    return ENOTCONN
    Failed to send data over BLE connection(err -128)
    NUS send timeout

    Which could be the problem?

  • This reply was deleted.
  • Hello ,

    Do you have any hint to solve this issue? Thanks for your attention.

  • Hello,

    Do you have a link to where the BT service on the ESP is documented?

Related