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

Custom Services example using Python library

Introduction

The Python library comes with a range of convenient AT commands that can be used to control various aspects of the BleuIO dongle, including scanning, advertising, connecting, and, most importantly, setting up custom services. Custom BLE services can be configured with just a few lines of Python code, to meet the specific requirements of the application.

This script will work on BleuIO Python library 1.2.0 or above

Creating a Custom Service with BleuIO’s Python Library

An example Python script that showcases how to create a custom BLE service using BleuIO’s Python library:

# (C) 2023 Smart Sensor Devices AB

import time
from datetime import datetime

from bleuio_lib.bleuio_funcs import BleuIO

# This example will show how to setup your own service
# Press Ctrl-C to exit the script.


# Scan result Callback function
def my_scan_callback(scan_input):
    print("\n\nmy_scan_callback: " + str(scan_input))


# Event Callback function
def my_evt_callback(scan_input):
    print("\n\nmy_evt_callback: " + str(scan_input))


# Start BleuIO
my_dongle = BleuIO()
# Register callback functions for scan results and events
my_dongle.register_evt_cb(my_evt_callback)
my_dongle.register_scan_cb(my_scan_callback)

# Run ATI Command
resp = my_dongle.ati()
print(resp.Cmd)
print(resp.Ack["errMsg"])
print(resp.Rsp)

print("My Role: " + my_dongle.status.role)
print("Is Adv: " + str(my_dongle.status.isAdvertising))
print("Is Connected: " + str(my_dongle.status.isConnected))

# Set role to dual if it isn't set already
if not my_dongle.status.role == my_dongle.gaproles.DUAL:
    resp = my_dongle.at_dual()
    print(resp.Cmd)
    print(resp.Ack)

# Disconnect if we're connected
if my_dongle.status.isConnected:
    resp = my_dongle.at_gapdisconnectall()
    print(resp.Cmd)
    print(resp.Ack)

# Stop Advertising if we're advertising
if my_dongle.status.isAdvertising:
    resp = my_dongle.at_advstop()
    print(resp.Cmd)
    print(resp.Ack)

# Stop custom service just in case it had been started previously
resp = my_dongle.at_customservice_stop()
print(resp.Cmd)
print(resp.Ack)

# Service

# Set service UUID
resp = my_dongle.at_customservice(
    0, my_dongle.UUID, "ee6ec068-7447-4045-9fd0-593f3ba3c2ee"
)
print(resp.Cmd)
print(resp.Ack)

# Characteristic 1

# Set characteristic 1 UUID
resp = my_dongle.at_customservice(
    2, my_dongle.UUID, "018f55d9-d747-4c4e-a87b-e9b074ffd2b6"
)
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 1 value length
resp = my_dongle.at_customservice(1, my_dongle.CHAR_LENGTH, "100")
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 1 value
# Here we set it to the current time in hours, minutes and seconds format.
cbTime = datetime.now()
char1_data = cbTime.strftime("%H:%M:%S")
resp = my_dongle.at_customservice(1, my_dongle.CHAR_VALUE, char1_data)
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 1 permissions
resp = my_dongle.at_customservice(1, my_dongle.CHAR_PERMISSION, "R")
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 1 properties
# We set it to Read and Notify
resp = my_dongle.at_customservice(1, my_dongle.CHAR_PROPERTY, "NR")
print(resp.Cmd)
print(resp.Ack)

# Characteristic 2

# Set characteristic 2 UUID
resp = my_dongle.at_customservice(
    2, my_dongle.UUID, "a693ba2c-f0df-40cb-aea7-8ae47281d997"
)
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 2 value length
resp = my_dongle.at_customservice(2, my_dongle.CHAR_LENGTH, "100")
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 2 value
# Here we set it to the current time in month, days and years format.
cbTime = datetime.now()
char2_data = cbTime.strftime("%m/%d/%Y")
resp = my_dongle.at_customservice(2, my_dongle.CHAR_VALUE, char2_data)
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 2 permissions
resp = my_dongle.at_customservice(2, my_dongle.CHAR_PERMISSION, "R")
print(resp.Cmd)
print(resp.Ack)

# Set characteristic 2 properties
# We set it to Read and Indicate
resp = my_dongle.at_customservice(2, my_dongle.CHAR_PROPERTY, "IR")
print(resp.Cmd)
print(resp.Ack)

# Here we check that the service data we set has gone in
resp = my_dongle.at_customservice()
print(resp.Cmd)
print(resp.Ack)
print(resp.Rsp)
print(resp.End)

# Here we start the custom service so next time we advertise and someone connects they will see the new service
resp = my_dongle.at_customservice_start()
print(resp.Ack)

# Here we start advertising so other devices can detect us and connect
resp = my_dongle.at_advstart()
print(resp.Ack)

# Going in a never ending loop that will just update the values of Characteristic 1 and 2 every second.
# If anyone is subscribed we will notify/indicate them.
while True:
    cbTime = datetime.now()
    notiCharTime = cbTime.strftime("%H:%M:%S")
    resp = my_dongle.at_customservice(1, my_dongle.CHAR_VALUE, notiCharTime)
    print(resp.Cmd)
    print(resp.Ack)

    indiCharTime = cbTime.strftime("%m/%d/%Y")
    resp = my_dongle.at_customservice(2, my_dongle.CHAR_VALUE, indiCharTime)
    print(resp.Cmd)
    print(resp.Ack)
    time.sleep(1)


The example script demonstrates the process of setting up a custom service with two characteristics. Characteristic 1 holds the current time in hours, minutes, and seconds format, while Characteristic 2 contains the date in month, day, and year format. The script registers callbacks for scan results and events, sets up the service UUID, characteristic UUIDs, permissions, properties, and starts advertising the custom service.


← PreviousEddystone example using Python library →
  • Introduction
    • Creating a Custom Service with BleuIO’s Python Library

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