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 Reply
  • I made a mistake, I forgot you are operating as the central and the process is a bit different. 

    The connection instance object is set in the function 'bt_nus_handles_assign' in nrf\subsys\bluetooth\services\nus_client.c:168

    	/* Assign connection instance. */
    	nus_c->conn = bt_gatt_dm_conn_get(dm);

    The GATT Discovery Manager is run after a connection has been established in order to read a connected peripheral's GATT services and characteristics. In the NUS client sample this library is used to identify whether the connected peripheral has a NUS service, and to store a given connection instance object if it does.

Children
  • This time the 'bt_nus_client_send' function returns the -128 error as the nRF52 cannot connect to the ESP32. is there something missing in how I have configured the filtering function?

    Right now I cannot establish a connection with the ESP32. Is there anything wrong with the configuration I've set for the filter?

  • Enable debug logs for the nrf_bt_scan module and verify that you are using the correct address. I'm suspecting that you are using the wrong byte-order or endianess. 

    It might also be the use of the 'match_all' flag when only one filter is used. 

  • I can establish the connection but after some seconds the microcontroller resets:

    Connected: 60:55:F9:F5:29:D2 (public)
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    Service discovery completed
    ASSERTION FAIL [conn] @ WEST_TOPDIR/zephyr/subsys/bluetooth/host/gatt.c:5034
            invalid parameters
    
    *** Booting Zephyr OS build v3.2.99-ncs2 ***

    If I add the line for sending data over NUS (call to 'bt_nus_client_send' function) it fails with -128 error.

    1. The ble peer failed pairing.

    2.  /zephyr/subsys/bluetooth/host/gatt.c:5034: "__ASSERT(conn, "invalid parameters\n");"
      What means that bt_gatt_subscribe was not called with a valid connection object. This can be a consequential error due to the failed pairing attempt. 
  • I have added a call to the 'bt_gatt_dm_conn_get' function in the 'discovery_complete' function as follows:

    static void discovery_complete(struct bt_gatt_dm *dm,
    			       void *context)
    {
    	struct bt_nus_client *nus = context;
    	LOG_INF("Service discovery completed");
    	printk("Service discovery completed\n");
    
    	bt_gatt_dm_data_print(dm);
    
    	/* Assign connection instance. */
    	nus_client.conn = bt_gatt_dm_conn_get(dm);
    
    	bt_nus_handles_assign(dm, nus);
    	bt_nus_subscribe_receive(nus);
    
    	bt_gatt_dm_data_release(dm);
    }

    This way the microcontroller doesn't reset anymore. Nevertheless, the pairing still fails:

    Starting Bluetooth Central UART example
    scan err: 0
    Scanning
    Scanning successfully started
    connected conn_err: 0
    Connected: 60:55:F9:F5:29:D2 (public)
    Pairing failed conn: 60:55:F9:F5:29:D2 (public), reason 9
    Service discovery completed

    How can I solve this problem?

Related