BleuIO

BleuIO

  • Get Started
  • Buy Now
  • Manual
  • AT Commands
  • Help

›Python library < v1.2.0

Manual

  • How it works
  • How to use
  • Verbose Mode
  • Known Issues
  • Troubleshooting

Firmware Updates

    BleuIO Pro (SSD025)

    • Firmware Updates
    • Release History

    BleuIO (SSD005)

    • Firmware Updates
    • Release History of BleuIO (SSD005)

AT-Commands

  • List of AT Commands

BleuIO Libraries

  • JavaScript Library
  • Python Library

Scripts & Tutorials

  • Python: iBeacon
  • Python: Eddystone Beacon
  • Python: Scan
  • Python: Scan and Store
  • Python: SPS Script
  • Python: File transfer Script
  • Python: Repeater Script
  • Javascript: Google chrome.serial Beacon
  • C# Console App Example
  • C# WFA Example

Script using libraries

    Python library > v1.2.0

    • Custom Services example using Python library
    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library

    Python library < v1.2.0

    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library
    • SPS example using Python library
    • Security Example using Python library

    JS library

    • Eddystone example using Javascript library
    • IBeacon example using Javascript library
    • Scan example using Javascript library
    • Security Example using Javascript library
    • Get Device Distance

Projects

    Arduino

    • Arduino Example

    Beaglebone

    • Beaglebone Example

    Raspberry Pi

    • Raspberry PI into Beacon
    • Raspberry PI home automation

    Raspberry PI Pico

    • BleuIO integration (Part1)
    • BleuIO integration (Part2)
    • BleuIO integration (Part3)

    Renesas RA4M2

    • Signal Strength Monitoring
    • Real-Time CO2 monitor
    • Monitoring Air Quality

    STM32 Nucleo-144

    • Nucleo-144 board example
    • Smart Bulb Example

    M5Stack's CoreMP135

    • M5Stack's CoreMP135 board example

Build Your Own Firmware

  • Build Your Own Firmware
  • Advertising Example

More

  • Links
Order Now

BleuIO

$19.99

Buy Now

SPS example using Python library

Introduction

In this tutorial, we're going to set up two dongles using Python script to send data back and forth.

Connect a dongle each into two computers that has Python installed.

Dongle

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.

First setup the peripheral dongle using follwing script.

from bleuio_lib.bleuio_funcs import BleuIo
from serial import SerialException
from time import sleep

# This script will receive data from a central dongle
# and echo it back to the central

my_dongle = None
connected_to_dongle = False
connected_to_central = False
message = ""

while not connected_to_dongle:
    try:
        # Specify the COM PORT connected to the dongle
        my_dongle = BleuIo(port="COM6")
        # Start the deamon (background process handler) for RX and TX data.
        my_dongle.start_daemon()

        connected_to_dongle = True
    except SerialException:
        print("Dongle not found. Please connect your dongle")
        sleep(5)

print("Connected to dongle\n\n" "Welcome to the BleuIO SPS example!\n\n")

# Starts advertising so it can be detected
my_dongle.at_advstart()

try:
    time_out_counter = 0
    i = 0
    while not connected_to_central:
        # Get information from the dongle
        # to see if it's connected to the central
        status = my_dongle.at_gapstatus()

        # Checks for information about connection
        if "\\nConnected\\r" in str(status):
            print("\nConnected to central")
            while True:
                # Listen for a received message
                response = str(my_dongle.rx_buffer)
                if "Received" in response:
                    print(response)
                    my_dongle.rx_buffer = b""
        else:
            print("Trying to connect to central")
            sleep(2)

except KeyboardInterrupt:
    # Disconnects and stops the dongle
    my_dongle.at_gapdisconnect()
    my_dongle.stop_daemon()
    exit()

And now set up the central dongle using following script

from bleuio_lib.bleuio_funcs import BleuIo
from serial import SerialException
from time import sleep

my_dongle = None
connected_to_dongle = False
connected_to_peripheral = False
message = ""
target_device_address = ""

# This script will send data from a central dongle(my_dongle)
# to a peripheral device(target_device_address)
# which in turn will echo it back to the central

# Target device needs to be set in peripheral role and be advertising

while not connected_to_dongle:
    try:
        # Specify the COM PORT connected to the dongle
        my_dongle = BleuIo(port="COM3")
        # Start the deamon (background process handler) for RX and TX data.
        my_dongle.start_daemon()

        connected_to_dongle = True
    except SerialException:
        print("Dongle not found. Please connect your dongle")
        sleep(5)

print(
    "Connected to dongle\n\n" "Welcome to the BleuIO SPS example!\n\n"
)  # //TODO byt namn på de andra

# Set the dongle in central role
my_dongle.at_central()

target_device_address = input(
    "Enter the target address:\n" "For example: [0]40:48:FD:E5:2C:EF\n"
)

# Requests connection with target
my_dongle.at_gapconnect(target_device_address)

# Fetch information about the connection
response = my_dongle.rx_response

try:
    time_out_counter = 0

    while not connected_to_peripheral:
        # Checks if a connection been made
        if "CONNECTED." in str(response):
            connected_to_peripheral = True
            print("\nConnected to {}".format(target_device_address))
            sleep(3)
        # Tries to connect 5 times
        elif time_out_counter < 5:
            print("Trying to connect to target device")
            sleep(3)
            time_out_counter += 1
        else:
            print("Connection timed out")
            break

    if connected_to_peripheral:
        while True:
            message = input("\nEnter a message to send to the peripheral:\n")
            # Sends provided message to the connected device
            my_dongle.at_spssend(message)

except KeyboardInterrupt:
    # Disconnects and stops the dongle
    my_dongle.at_gapdisconnect()
    my_dongle.stop_daemon()
    exit()

The script is well commented for easy understanding. Don't forget to put correct COM port for both central and peripheral dongles.

Full source also available on GitHub.


← Scan and store example using Python librarySecurity Example using Python library →
  • Introduction

Support Request

If you have any queries or technical questions, please don't hesitate to send us a message. We will reply within 24 hours.

Message Sent!

Docs
ManualAT CommandsHelp
Community
YouTubeLinkedInFacebook
More
BleuIOSmart Sensor DevicesGitHub
Sales & Support
support@bleuio.comsales@bleuio.com
Copyright © 2025 BleuIO. A product of Smart Sensor Devices