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?

  • Why is it necessary to comment k_free() and k_sem_give()? When I try connecting to an ESP32 the test still fails:

    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?

    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.

  • 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().

    msu 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.

    msu 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 :

    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:

  • msu 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. 

    msu 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:

    Here is the log I got for comparison:

  • 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:

Reply
  • 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:

Children
  • 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.

  • 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:

    Do I have to replace functions?

  • I solve this problem by replacing:

    by:

    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:

    Which could be the problem?

  • This reply was deleted.
  • Hello ,

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