Sending and receiving data between two Bluetooth dongle

October 27, 2020
images


In this project, we will demonstrate how two Bluetooth dongles can be paired together and share data between them. To pair two Bluetooth dongle, one of them needs to be configured as Central and other needs to be configured as Peripheral. We already wrote a Python script that sends data back and forth between dongles.

In short :

  1. One dongle will take on the Central role and the other will take on the Peripheral role.
  2. Then they will connect to each other.
  3. The Central dongle will then start off sending a message; “Echo”.
  4. The Peripheral dongle will then receive the message and send it back to the Central dongle which in turn will receive it and send it back and so forth until the script is stopped.

Device Required:

Software Tools Required : 

Step 1 : Install Python on both laptop and connect a USB Dongle on each of them.

Step 2 : For a quick setup, copy the following script and save it on your local directory as sps_example.py . You can also get the source code from our GITHUB PAGE.

Step 3: Change the COM-port in the script on both computers to match the ones your dongles is actually connected to. For the one that will be set up as the Central dongle you will also need to change the target_dongle_mac_address variable to the MAC address of your Peripheral dongle. You can get the MAC address by scanning for the other dongle while it’s advertising. To learn more about how to scan check out our scanning tutorial.

Step 4: Open up the command prompt, on both computers, in the directory where the script is located. Start the script by typing python sps_example.py and press Enter.

Step 5: You should now be prompted to enter 1 or 2 depending on what role the dongle should have. Set one as Peripheral and the other as Central. It is advisable to setup the Peripheral first as the Central will need someone to connect to.

You should now see in the terminal how the dongles send and recieve data to and from each other.

The script will run until you stop it.

And that is an example of how we can send data between two dongles. If you want to stop the script, you can simply press control C.

Full source also available on GitHub.

Project Video

Share this post on :
    LinkedIn