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?

  • I have another nRF52 DK nRF52832 PCA10040 3.0.0. Is this MCU concerned by the bug? Both boards I have use the same MCU model. I have just flashed it with the BlueTooth sniffer and the port is not detected by Wireshark. Is there any other way I can check the BlueTooth traffic? Or is there any other configuration I can try in order to send readable data to the ESP32?

    Is the bug in the MCU's interface the reason why the interfaces are not shown after 'extcap'?

    When I ran the ' ./nrf_sniffer_ble.sh --extcap-interfaces' command I see that the interfaces are not shown after 'extcap':

    Additionnaly, I'd like to now if the Wireshark communication problem also exists with the nRF52840 dongle.

    UPDATE:

    I have installed the sniffer in Windows and the interface is detected. Nevertheless, it is not possible to capture frames as the following errors are displayed:

    Error2

  • Unknown said:
    Is the bug in the MCU's interface the reason why the interfaces are not shown after 'extcap'?

    Yes.

    Unknown said:
    Additionnaly, I'd like to now if the Wireshark communication problem also exists with the nRF52840 dongle.

    No, the 52840 Dongle is not impacted by said bug. Did you with the dongle on Linux too? You can install nrf-udev to ensure your user gets the neccessary read/write permissions. 

  • Did you with the dongle on Linux too?

    I don't have the dongle. I have to buy one but I wanted to be sure that it is not impacted by the same problem present in the DK before ordering it.

    You can install nrf-udev to ensure your user gets the neccessary read/write permissions. 

    Can this solve the problem with the DK? Or do I have to install it only for the dongle?

  • Unknown said:
    Can this solve the problem with the DK? Or do I have to install it only for the dongle?

    We currently don't have any workaround or fix for using nRF52 DK v.3.0.0 with wireshark.

     WireShark Error with BLE Sniffer at nRF52DK (PCA10040 v3.0.0) - Could not find interface, FIFO does not exist  

  • Hello  ,

    In order to send data to the ESP32 the frame format explained in this link must be followed. I've modified the main function as follows to send 7 bytes of data within a frame 12 bytes of length:

    void main(void)
    {
    	int err;
    	struct uart_data_t buffer;
    	uint8_t byte_0 = 0x4D /* Type */, byte_1 = 0x0 /* Frame control */, byte_2 = 0x0/* Sequence number */, byte_3 = 0x7 /* Data length */, byte_4 = 'A' /* Data */, byte_5 = 2 /* Checksum */;
    	err = bt_conn_auth_cb_register(&conn_auth_callbacks);
    	if (err) {
    		LOG_ERR("Failed to register authorization callbacks.");
    		return;
    	}
    	printk("bt_conn_auth_cb_register\n");
    
    	err = bt_conn_auth_info_cb_register(&conn_auth_info_callbacks);
    	printk("bt_conn_auth_info_cb_register err: %i\n", err);
    	if (err) {
    		printk("Failed to register authorization info callbacks.\n");
    		return;
    	}
    
    	err = bt_enable(NULL);
    	printk("bt_enable err: %i\n", err);
    	if (err) {
    		LOG_ERR("Bluetooth init failed (err %d)", err);
    		printk("Bluetooth init failed (err %d)\n", err);
    		return;
    	}
    	printk("Bluetooth initialized\n");
    	LOG_INF("Bluetooth initialized");
    
    	if (IS_ENABLED(CONFIG_SETTINGS)) {
    		settings_load();
    	}
    
    	int (*module_init[])(void) = {uart_init, scan_init, nus_client_init};
    	for (size_t i = 0; i < ARRAY_SIZE(module_init); i++) {
    		err = (*module_init[i])();
    		//printk("i: %i\n", i);
    		if (err) {
    			return;
    		}
    	}
    	printk("\n");
    
    	printk("Starting Bluetooth Central UART example\n");
    
    	err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
    	if (err) {
    		LOG_ERR("Scanning failed to start (err %d)", err);
    		printk("Scanning failed to start (err %d)\n", err);
    		return;
    	}
    
    	LOG_INF("Scanning successfully started");
    	printk("Scanning successfully started\n");
    
    	for (;;) {
    		/* Wait indefinitely for data to be sent over Bluetooth */
    		buffer.data[0] = byte_0;
    		buffer.data[1] = byte_1;
    		buffer.data[2] = byte_2;
    		buffer.data[3] = byte_3;
    		buffer.data[4] = byte_4;
    		buffer.data[5] = 'B';
    		buffer.data[6] = 'C';
    		buffer.data[7] = 'D';
    		buffer.data[8] = 'E';
    		buffer.data[9] = 'F';
    		buffer.data[10] = byte_2;
    
    		buffer.data[11] = byte_5;
    		buffer.len = 12;
    
    		if (discovery_service_ok)
    		{
    			err = bt_nus_client_send(&nus_client, buffer.data, buffer.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);
    			}
    
    			if (err) {
    				LOG_WRN("NUS send timeout");
    				printk("NUS send timeout\n");
    			}
    			byte_2++; /* Increment sequence number. */
    		}
    		k_msleep(1000); 
    	}
    }

Reply
  • Hello  ,

    In order to send data to the ESP32 the frame format explained in this link must be followed. I've modified the main function as follows to send 7 bytes of data within a frame 12 bytes of length:

    void main(void)
    {
    	int err;
    	struct uart_data_t buffer;
    	uint8_t byte_0 = 0x4D /* Type */, byte_1 = 0x0 /* Frame control */, byte_2 = 0x0/* Sequence number */, byte_3 = 0x7 /* Data length */, byte_4 = 'A' /* Data */, byte_5 = 2 /* Checksum */;
    	err = bt_conn_auth_cb_register(&conn_auth_callbacks);
    	if (err) {
    		LOG_ERR("Failed to register authorization callbacks.");
    		return;
    	}
    	printk("bt_conn_auth_cb_register\n");
    
    	err = bt_conn_auth_info_cb_register(&conn_auth_info_callbacks);
    	printk("bt_conn_auth_info_cb_register err: %i\n", err);
    	if (err) {
    		printk("Failed to register authorization info callbacks.\n");
    		return;
    	}
    
    	err = bt_enable(NULL);
    	printk("bt_enable err: %i\n", err);
    	if (err) {
    		LOG_ERR("Bluetooth init failed (err %d)", err);
    		printk("Bluetooth init failed (err %d)\n", err);
    		return;
    	}
    	printk("Bluetooth initialized\n");
    	LOG_INF("Bluetooth initialized");
    
    	if (IS_ENABLED(CONFIG_SETTINGS)) {
    		settings_load();
    	}
    
    	int (*module_init[])(void) = {uart_init, scan_init, nus_client_init};
    	for (size_t i = 0; i < ARRAY_SIZE(module_init); i++) {
    		err = (*module_init[i])();
    		//printk("i: %i\n", i);
    		if (err) {
    			return;
    		}
    	}
    	printk("\n");
    
    	printk("Starting Bluetooth Central UART example\n");
    
    	err = bt_scan_start(BT_SCAN_TYPE_SCAN_ACTIVE);
    	if (err) {
    		LOG_ERR("Scanning failed to start (err %d)", err);
    		printk("Scanning failed to start (err %d)\n", err);
    		return;
    	}
    
    	LOG_INF("Scanning successfully started");
    	printk("Scanning successfully started\n");
    
    	for (;;) {
    		/* Wait indefinitely for data to be sent over Bluetooth */
    		buffer.data[0] = byte_0;
    		buffer.data[1] = byte_1;
    		buffer.data[2] = byte_2;
    		buffer.data[3] = byte_3;
    		buffer.data[4] = byte_4;
    		buffer.data[5] = 'B';
    		buffer.data[6] = 'C';
    		buffer.data[7] = 'D';
    		buffer.data[8] = 'E';
    		buffer.data[9] = 'F';
    		buffer.data[10] = byte_2;
    
    		buffer.data[11] = byte_5;
    		buffer.len = 12;
    
    		if (discovery_service_ok)
    		{
    			err = bt_nus_client_send(&nus_client, buffer.data, buffer.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);
    			}
    
    			if (err) {
    				LOG_WRN("NUS send timeout");
    				printk("NUS send timeout\n");
    			}
    			byte_2++; /* Increment sequence number. */
    		}
    		k_msleep(1000); 
    	}
    }

Children
No Data
Related