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,

  • I am not able to spot any errors in your implementation. Could you upload the full project so I can try reproducing this here?

  • I see the problem now: your main loop is always running as you have commented the k_fifo_get() function. 

    As a test, try to add a call to k_msleep(1000); in your loop. This will allow the other threads such as the system workqueue to run. 

  • Thanks! Now the connection is established but the pairing still doesn't work. I have uncommented the 'bt_nus_client_send' and 'k_sem_take' functions but no data is received by the ESP32 and the pairing fails after some time:

    *** 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
    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
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    Service discovery completed
    NUS send timeout

    Do you know why this could be happening?

  • Did you add k_msleep(1000) to your main loop? Like this:

    	...
    	for (;;) {
    		/* Wait indefinitely for data to be sent over Bluetooth */
    		//struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
    		//				     K_FOREVER);
    
    		struct uart_data_t *buf;
    		buf->data[0] = 0;
    		buf->data[1] = 1;
    		buf->data[2] = 2;
    		buf->len = 3;
    
    		//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);
    			printk("Failed to send data over BLE connection"
    				"(err %d)\n", err);
    		}
    
    		//err = k_sem_take(&nus_write_sem, NUS_WRITE_TIMEOUT);
    		if (err) {
    			LOG_WRN("NUS send timeout");
    			//printk("NUS send timeout\n");
    		}
    
    		k_msleep(1000);
    	}

Related