Seamless BLE Device Integration on Linux with BleuIO

Bluetooth Low Energy (BLE) is a wireless communication technology commonly used in various IoT and wearable devices. With the right tools and libraries, working with BLE devices on Linux becomes easy and efficient. In this tutorial, we’ll explore how to use the BleuIO dongle and the associated Python library to scan for nearby BLE devices, connect to a device, and read its characteristics, specifically the device name.

Prerequisites

Before we begin, ensure you have the following:

  • BleuIO Dongle: You’ll need a BleuIO dongle, a versatile BLE device capable of working on any platform.
  • BleuIO Python Library: Install the BleuIO Python library, which provides the necessary tools for interacting with the BleuIO dongle. You can install it using pip:
pip install bleuio

Now that you have the prerequisites in place, let’s dive into the process.

Step 1: Setting up the Python Script

First, let’s set up a Python script to work with the BleuIO dongle. Here’s a script that demonstrates how to scan for nearby BLE devices, connect to one of them, and read characteristics.

import time
from datetime import datetime
from bleuio_lib.bleuio_funcs import BleuIO

# Creating a callback function for scan results
def my_scan_callback(scan_input):
    print("\n\nmy_scan_callback: " + str(scan_input))

# Creating a callback function for events
def my_evt_callback(evt_input):
    cbTime = datetime.now()
    currentTime = cbTime.strftime("%H:%M:%S")
    print("\n\n[" + str(currentTime) + "] my_evt_callback: " + str(evt_input))

# Initiating the BleuIO dongle
my_dongle = BleuIO()

# Registering the callback functions
my_dongle.register_evt_cb(my_evt_callback)
my_dongle.register_scan_cb(my_scan_callback)

# Switch to Central or Dual Gap Role
my_dongle.at_dual()

# Start scanning for devices
my_dongle.at_gapscan(3)

# Wait for a few seconds to allow devices to be discovered
time.sleep(4)

# Connect to a device using its MAC address
my_dongle.at_gapconnect('[1]D1:79:29:DB:CB:CC')

# Wait for the connection to establish
time.sleep(4)

# Read characteristics with handle '0003', which contains the device name
my_dongle.at_gattcread('0003')

# Wait briefly
time.sleep(1)

Step 2: Running the Script

Save the script to a Python file, for example, bleuio_ble_tutorial.py. Then, run the script using your Python interpreter.

The script performs the following actions:

  • Initiates the BleuIO dongle and sets up callback functions for scan results and events.
  • Switches to Central or Dual Gap Role.
  • Scans for nearby BLE devices for a specified duration (3 seconds in this example).
  • Connects to a specific device using its MAC address.
  • Waits for the connection to establish.
  • Reads the characteristics with handle ‘0003’, which typically contains the device name.
  • Waits briefly before exiting.

The scan results and characteristic data will be displayed on the terminal.

Output :

Working with BLE devices on Linux using the BleuIO dongle and Python library is a straightforward process. You can use this script as a starting point to interact with BLE devices and further develop your BLE applications. Remember to customize the script to suit your specific needs, and explore the wealth of possibilities that BLE technology offers in the world of IoT and wireless communication.

Share this post on :

BleuIO Releases Python Library v1.3.1 to support BleuIO firmware v2.4.0

BleuIO, has recently unveiled its latest offering: Python Library v1.3.1. This release brings a range of improvements and features, including support for the SUOTA (Software Updates Over The Air) commands introduced in BleuIO firmware version 2.4.0. Additionally, it addresses a bug that affected MacOS users, making the library more robust and user-friendly.

Support for SUOTA Commands:

One of the standout features of BleuIO’s Python Library v1.3.1 is its support for SUOTA commands. SUOTA, which stands for Software Updates Over The Air, is a critical feature for any BLE device. It allows users to update firmware wirelessly, eliminating the need for physical connections or manual updates. With this library update, developers working with BleuIO now have a powerful tool at their disposal to streamline firmware updates for their BLE devices. Whether it’s fixing bugs or adding new features, the ability to update firmware over the air provides flexibility and convenience, ultimately enhancing the user experience.

Bug Fix for MacOS Users:

The new Python library also includes a significant bug fix for MacOS users. Previously, there was an issue where serial responses were sometimes returned in two parts instead of one when using the library on MacOS. This inconsistency could lead to compatibility problems and hinder the development process. BleuIO has promptly addressed this issue, ensuring that the library can now handle serial responses that come in multiple parts. This improvement guarantees a smoother experience for MacOS users and eliminates a common frustration during development.

The Python Library v1.3.1 by BleuIO is readily available for developers on the Python Package Index (PyPI). You can access and download the library from the following link: BleuIO Python Library on PyPI. This convenient accessibility ensures that developers can easily integrate the library into their projects and start benefiting from the new features and bug fixes immediately.

Share this post on :