BleuIO’s Multiple devices use Bluetooth LE hub functions

This article will discuss how to use the Bleu.io multi-connection features, communicate using BLE devices connected to them, and transfer data from those devices.

BleuIO's : BLE 5.0 USB Adapter

Materials

BleuIO’s

Bluetooth low-energy technology supplies a pioneering approach to connecting with smart gadgets. The term IoT or Internet of Things has some pioneering technologies. The IoT states that everything is interconnected, and Bluetooth has greatly improved the interconnection of devices. A central device can establish and maintain connections among several Bluetooth Low Energy peripherals devices.

The BleuIO’s Bluetooth low energy design makes it the fastest and easiest way to explore any of the BLE 5.0 functions. With its multi-connection capability, the BleuIO easily connects to multiple BLE devices and transfers information between them.

This article will teach you how to use the BleuIO device’s multi-connection features, connect to multiple Bluetooth Low Energy devices, and transfer data between them. We will require three small BleuIO devices for this project, one central and two peripheral. The central one will transmit data to the peripherals, which will also load data simultaneously.

We will create a custom python script that will make for easy execution of the task.

Step 1:

  • Let’s create a python file called py_serial_transfer.py and copy the following code.
  • Source code is also available on GitHub.

https://github.com/smart-sensor-devices-ab/ble_multi_connection_example.git

import serial import time import string import random target_dongle_mac_address = ( “[0]40:48:FD:E5:2D:AF” # Change this to the 1st peripheral’s mac address. ) target_dongle_mac_address2 = ( “[0]40:48:FD:E5:2D:B5” # Change this to the 2nd peripheral’s mac address. ) your_com_port = “COM7″ # Change this to the com port your dongle is connected to. connecting_to_dongle = True trying_to_connect = False trying_to_connect2 = False def id_generator(size=10, chars=string.ascii_uppercase + string.digits): return ”.join(random.choice(chars) for _ in range(size)) print(“Connecting to dongle…”) # Trying to connect to dongle until connected. Make sure the port and baudrate is the same as your dongle. # You can check in the device manager to see what port then right-click and choose properties then the Port Settings # tab to see the other settings while connecting_to_dongle: try: console = serial.Serial( port=your_com_port, baudrate=57600, parity=”N”, stopbits=1, bytesize=8, timeout=0, ) if console.is_open.__bool__(): connecting_to_dongle = False except: print(“Dongle not connected. Please reconnect Dongle.”) time.sleep(5) print(“Connected to Dongle.”) connected = “0” connected2 = “0” while 1 and console.is_open.__bool__(): console.write(str.encode(“AT+DUAL”)) console.write(“\r”.encode()) time.sleep(0.1) print(“Putting dongle in Dual role and trying to connect to other dongle.”) while connected == “0”: time.sleep(0.5) if not trying_to_connect: console.write(str.encode(“AT+GAPCONNECT=”)) console.write(str.encode(target_dongle_mac_address)) console.write(“\r”.encode()) trying_to_connect = True dongle_output2 = console.read(console.in_waiting) time.sleep(2) print(“Trying to connect to Peripheral 1…”) if not dongle_output2.isspace(): if dongle_output2.decode().__contains__(“\r\nCONNECTED.”): connected = “1” print(“Connected to 1st device!”) time.sleep(5) if dongle_output2.decode().__contains__(“\r\nDISCONNECTED.”): connected = “0” print(“Disconnected!”) trying_to_connect = False dongle_output2 = ” ” while connected2 == “0”: time.sleep(0.5) if not trying_to_connect2: console.write(str.encode(“AT+GAPCONNECT=”)) console.write(str.encode(target_dongle_mac_address2)) console.write(“\r”.encode()) trying_to_connect2 = True dongle_output2 = console.read(console.in_waiting) time.sleep(2) print(“Trying to connect to Peripheral 2…”) if not dongle_output2.isspace(): if dongle_output2.decode().__contains__(“\r\nCONNECTED.”): connected2 = “1” print(“Connected to 2nd device!”) time.sleep(5) if dongle_output2.decode().__contains__(“\r\nDISCONNECTED.”): connected2 = “0” print(“Disconnected!”) trying_to_connect2 = False dongle_output2 = ” ” while connected == “1” and connected2 ==”1″: dongle_output3 = console.read(console.in_waiting) delay=10 close_time=time.time()+delay i=0 while True: myConIndex = (‘0000’ if i%2 == 0 else ‘0001’) console.write(str.encode(“AT+TARGETCONN=”)) console.write(str.encode(myConIndex)) console.write(“\r”.encode()) console.write(str.encode(“AT+SPSSEND=”)) console.write(str.encode(id_generator()+’-‘+myConIndex)) console.write(“\r”.encode()) time.sleep(0.2) i+=1 if time.time()>close_time: break console.write(str.encode(“AT+SPSSEND=[DONE]\r”)) time.sleep(0.2) print(“Sending complete!\r\n”) print(“Exiting script…”) exit()

The script in this menu will be run on the BleuIO dongle. We need to find the dongle port number and the endpoint address of the peripheral computer.

Step 2:

  • Connect three separate BleuIO adapters on your PC. You can perform the process on three different computers or Raspberry Pis.
  • The process of connecting both the central and the peripheral decency with the capability to simultaneously access a single computer.
  • Using the integrated ports that connect the dongles, opening up the accordance with the device driver (Windows) The area of each dongle must be found.
BleuIO's ble-port.

The BleuIO dongles are connected to ports 7, 8, and 18 on my PC. Make COM7 the center node, and COM8 and COM18 the periphery nodes.

Now open the scripts and change line 12 to the port number. We also need to know the mac address of the peripheral dongles.

To do so, simply use the AT+ADVSTART command to promote the dongle.

BleuIO's ble-advertising

Repeat the procedure with the other peripheral dongle.

Both peripheral dongles are now advertising. To find their mac address, we can run a gap scan from central.

Look for your docking station called BleuIO.

BleuIO's ble-scan-device

Update the peripheral address (lines 6, 9) in the next line of the script.

Step 3 :

  • Let’s execute the script now.
  • Type python py serial transfer.py in the script folder.
  • It will establish a connection with both peripheral dongles and send data at random.
  • The responses will appear on the web terminal screen.
  • To gain a better understanding, please watch the video.
BleuIO’s Multiple devices use Bluetooth LE hub functions beuIO 1 1