Real-Time BLE Proximity-Based LED Blinking with BleuIO: A Practical Guide

BleuIO, a versatile BLE USB dongle, simplifies BLE application development with its powerful AT commands and cross-platform compatibility. This tutorial demonstrates how to use BleuIO with Python to build a real-time BLE proximity-based LED control system.

In this example, we focus on monitoring the RSSI (Received Signal Strength Indicator) of a specific BLE device and controlling the LED blinking rate of BleuIO based on proximity. The closer the device, the faster the blinking rate. The script also ensures clean termination, turning off the LED when the program exits.

This tutorial uses the BleuIO Python library to showcase a practical use case. However, the concepts can be implemented in any programming language.

Devices and Tools Needed

  1. BleuIO Pro BLE USB Dongle
  2. Python Installed (Python 3.6 or newer recommended)
  3. BleuIO Python Library
    Install the library using
    pip install bleuio
  4. Source Code
    Get the complete source code from GitHub:
    GitHub Repository

Use Case: Real-Time LED Blinking Based on Proximity

Objective:

  1. Continuously monitor the RSSI value of a specific BLE device.
  2. Adjust the LED blinking rate of the BleuIO dongle based on the device’s proximity.
  3. Ensure the LED turns off when the script is terminated.

Workflow:

  1. Scan for BLE devices: Identify the target device using its MAC address.
  2. Read RSSI values: Fetch real-time signal strength data.
  3. Control LED: Adjust the blinking rate based on proximity:
    • Very Close: Fast blinking.
    • Close: Moderate blinking.
    • Far: Slow blinking.
    • Very Far: Very slow blinking.
  4. Graceful Exit: Turn off the LED when the script ends.

The Python Script

Below is the complete script for this project:

import time
import json
import atexit
from bleuio_lib.bleuio_funcs import BleuIO

rssi_value = None
dongle = None  

def scan_callback(scan_input):
    global rssi_value  
    try:
        device_data = json.loads(scan_input[0])  
        if device_data.get("addr") == "[1]6B:C0:5C:BD:CF:14":
            rssi_value = device_data["rssi"]  
            print(f"\nDevice Found! Address: {device_data['addr']}, RSSI: {rssi_value}")
    except json.JSONDecodeError as e:
        print(f"Error decoding JSON: {e}")
    except Exception as e:
        print(f"Unexpected error: {e}")

def send_led_command(dongle, rssi):
    if rssi is not None:  
        if rssi > -40:
            print(f"RSSI: {rssi} | Sending LED Command: 50/50")
            dongle.at_led(toggle="T", on_period="50", off_period="50")
        elif -60 <= rssi <= -40:
            print(f"RSSI: {rssi} | Sending LED Command: 100/100")
            dongle.at_led(toggle="T", on_period="100", off_period="100")
        elif -90 <= rssi < -60:
            print(f"RSSI: {rssi} | Sending LED Command: 200/200")
            dongle.at_led(toggle="T", on_period="200", off_period="200")
        else:
            print(f"RSSI: {rssi} | Sending LED Command: 300/300")
            dongle.at_led(toggle="T", on_period="300", off_period="300")
    else:
        print("No RSSI value available for LED command.")


def cleanup():
    if dongle:
        print("\n--- Turning off LED and cleaning up ---")
        dongle.at_led(0)

# Main logic
def main():
    global rssi_value, dongle  
    dongle = BleuIO()

    atexit.register(cleanup)

    dongle.register_scan_cb(scan_callback)

    print("\n--- Starting BLE Task ---\n")

    print("Setting device role to Central...")
    central_response = dongle.at_central()

    try:
        while True:
            print("\nStarting scan for 2 seconds...")
            dongle.at_gapscan(2)  
            time.sleep(3)  

            send_led_command(dongle, rssi_value)

            print("\nScan cycle completed. Restarting...\n")
            time.sleep(1)
    except KeyboardInterrupt:
        print("\n--- Script Terminated by User ---")

# Run the main function
if __name__ == "__main__":
    main()

How It Works

  1. Initialization: The script initializes the BleuIO dongle and sets it to Central role for scanning.
  2. Scan Callback: The scan_callback function extracts the RSSI value of the target device in real-time.
  3. LED Control: Based on the RSSI value:
    • RSSI > -40: Fast blinking (50ms on/off).
    • -60 <= RSSI <= -40: Moderate blinking (100ms on/off).
    • -90 <= RSSI < -60: Slow blinking (200ms on/off).
    • RSSI < -90: Very slow blinking (300ms on/off).
  4. Graceful Termination: The script turns off the LED when terminated with Ctrl + C.

Output

This example demonstrates how easy it is to use BleuIO for BLE applications. Whether you’re building proximity-based solutions or exploring BLE capabilities, BleuIO’s AT commands and Python library make it simple to get started.

Take this script, adapt it to your needs, and unlock the potential of BLE with BleuIO!

Share this post on :

New Firmware Release for BleuIO and BleuIO Pro: Enhanced Stability and Bug Fixes

We’re excited to announce the release of new firmware updates for our popular BleuIO and BleuIO Pro Bluetooth Low Energy USB dongles. These updates focus on improving the stability and performance of the devices while addressing some critical bugs reported by our users.

With these firmware releases, both BleuIO and BleuIO Pro are now better equipped to handle connection and scan operations, ensuring a smoother experience for developers building Bluetooth Low Energy (BLE) applications.

BleuIO Pro Firmware v1.0.2

The latest firmware for BleuIO Pro brings significant stability improvements and important bug fixes.

Key Updates

Stability Improvements:

  • Improved general stability for more consistent performance.
  • Enhanced stability during connection and scan operations.

Bug Fixes:

  • Resolved issues with incorrectly formatted verbose responses.
  • Fixed a bug where notifications/indications and GATT read operation responses would be cut off if they exceeded a certain length.
  • Fixed an issue where advertising would not automatically restart after a disconnection in verbose mode.

These improvements ensure a seamless experience for developers using BleuIO Pro in their BLE projects, whether for scanning devices, establishing connections, or maintaining robust advertising.


BleuIO Firmware v2.7.7

The new firmware for BleuIO focuses on improving the dongle’s overall stability and addressing bugs that could hinder performance.

Key Updates

Stability Improvements:

  • Enhanced general stability for day-to-day operations.
  • Improved connection and scan stability to ensure reliable performance during development and testing.

Bug Fixes:

  • Resolved issues with incorrectly formatted verbose responses.

These updates further solidify BleuIO as a reliable solution for developers working on BLE applications across various platforms.

How to Update Your Firmware

To take advantage of these updates, download the latest firmware from our firmware page. Ensure you select the correct firmware for your device—BleuIO or BleuIO Pro.

We’ve included a detailed step-by-step guide on the firmware page to make the update process simple and straightforward.

We encourage all users to update their firmware to the latest version to benefit from these stability improvements and bug fixes.

Share this post on :

BleuIO Featured in Renesas’ Success Story: A Testament to Innovation and Excellence

Renesas, a global leader in semiconductor solutions, has highlighted our Bluetooth Low Energy (BLE) USB dongle BleuIO in their Success Stories section. This recognition is a testament to the innovation and dedication behind BleuIO, making it easier for developers to create BLE applications.

A Seamless Way to Add Bluetooth Connectivity

In their feature titled A Seamless Way to Add Bluetooth Low Energy Connectivity to IoT Devices, Renesas acknowledges BleuIO’s plug-and-play simplicity and versatility. Built around Renesas’ SmartBond™ DA14695 Bluetooth chip, BleuIO helps developers to create secure and efficient BLE 5.2 applications with minimal effort. Whether you’re a beginner or an experienced developer, BleuIO eliminates complexities, allowing you to focus on your application logic.

Driving Innovation with Renesas

Renesas’ support has been instrumental in BleuIO’s success. Their contributions have enabled us to deliver a product that meets the highest standards of performance and reliability. As highlighted in their article, our partnership with Renesas has helped us scale globally, reaching new markets and delivering innovative solutions to our customers.

Read the full article on Renesas’ website here and discover how BleuIO can empower your IoT projects.

Share this post on :

Creating a BLE Chat Application Using BleuIO USB Dongle

Bluetooth Low Energy (BLE) has become a core technology in the modern world, enabling secure and efficient communication for IoT devices, wearables, healthcare gadgets, and more. One of the fascinating applications of BLE is in creating private communication systems. In this tutorial, we will explore how to create a BLE chat application using the BleuIO USB dongle, a powerful yet simple device for BLE application development.

Why This Project?

With increasing concerns about privacy, BLE chat offers a solution that keeps communication entirely local. Unlike internet-based messaging systems, BLE chat does not rely on servers or cloud storage, ensuring that no data leaves your devices. This project demonstrates a simple prototype of such a BLE-based communication system.

How It Works

The project involves two laptops, each connected to a BleuIO USB dongle. For simplicity, we designate one laptop as User 1 (Central role) and the other as User 2 (Peripheral role). Here’s a high-level breakdown of the workflow:

  1. Setup:
    Each laptop runs a script to initialize its BleuIO dongle. User 1 starts in a dual role and acts as the central device. User 2 also sets its dongle in a dual role but begins advertising itself.
  2. Connection:
    Once User 2 starts advertising, it displays its MAC address. User 1 uses this MAC address to connect to User 2.
  3. Messaging:
    After establishing a connection, the users can send and receive messages in real time. The communication is direct and local, with no reliance on external servers.

Setting Up the Project

The source code for this project is available on GitHub: BLE Chat Source Code. You can explore, experiment, and build on it to fit your needs.

Steps to Set Up the Project:

  1. Clone the Repository
    Open a terminal on both computers and run
    git clone https://github.com/smart-sensor-devices-ab/ble-chat.git
  2. Install Dependencies
    Navigate to the project directory and install the required Node.js dependencies
    cd ble-chat
    npm install
  3. Run the Server
    Start the server by running
    node server.js
    Ensure the server is running on both computers. The terminal should display messages confirming the dongle is detected.

Running the Scripts

Once the servers are running on both computers, follow these steps to use the BLE chat application:

  1. User 1 Setup:
    • Open the browser and navigate to http://localhost:3000.
    • Click “Chat as User 1.” This will initialize the BleuIO dongle in dual role mode.
  2. User 2 Setup:
    • On the second computer, open the browser and navigate to http://localhost:3000.
    • Click “Chat as User 2.” This will initialize the BleuIO dongle in dual role mode and start advertising. You’ll also see the MAC address of the dongle displayed on the screen. ble chat user 2
  3. Connecting the Devices:
    • Copy the MAC address from User 2’s screen and enter it on User 1’s screen in the provided input field.
    • Click “Connect” on User 1. Once the connection is established, you’ll see a confirmation message.
      ble chat user 1
  4. Start Chatting:
    • Use the chat interface on both devices to send messages back and forth. Messages sent from one device will instantly appear on the other device’s screen.
      ble chat screen

Output

In the video below, we demonstrate how this project works with two BleuIO dongles connected to two different computers. To provide a complete view, we are sharing the screen of the second computer to showcase how the chat functions in real-time.

Use Cases for BLE Chat

The BLE chat prototype we’ve created can inspire real-world applications. Here are some potential use cases:

Secure Local Communication:
BLE chat can be used for private messaging within offices, factories, or homes without the need for internet connectivity.

Education Projects:
BLE chat can be a great project for students learning about BLE technology and its applications.

Why Choose BleuIO for Your BLE Projects?

The BleuIO USB dongle makes BLE application development accessible for everyone, from beginners to advanced developers. Its built-in AT commands allow you to quickly prototype applications without diving into complex BLE stacks or SDKs. Whether you’re working on a small hobby project or an enterprise-level IoT solution, BleuIO provides the tools you need.

Here are some standout features of BleuIO:

  • Cross-Platform Compatibility: Works seamlessly on Windows, macOS, and Linux.
  • Simple AT Commands: No need for extensive coding; just use the built-in commands to control the dongle.
  • Lightweight and Portable: Easy to carry and set up for on-the-go development.

This BLE chat application demonstrates the power and simplicity of BLE communication using the BleuIO USB dongle. While it’s a prototype, it showcases how BLE can enable private, secure, and efficient messaging without relying on external networks.

If you’re interested in exploring this further, the source code for the project is available. You can modify and extend it to fit your specific needs. With BleuIO, the possibilities are endless.

Order Your BleuIO USB Dongle Today!
Ready to create your own BLE applications? Visit BleuIO’s to learn more and order your dongle today.

Share this post on :

BleuIO Pro Now Available on Digi-Key – Smart Sensor Devices Expands Global Accessibility for Advanced BLE Development

Stockholm, SwedenSmart Sensor Devices, a leading innovator in IOT and Bluetooth Low Energy (BLE) solutions, is thrilled to announce the availability of its flagship product, BleuIO Pro, on Digi-Key, one of the world’s largest distributors of electronic components. This strategic move will provide global access to the BleuIO Pro, enabling developers worldwide to effortlessly enhance their BLE applications using Bluetooth 5.2 technology.

The BleuIO Pro is the latest addition to the BleuIO product line, designed specifically for developers working on advanced BLE applications. With support for Bluetooth 5.2, the BleuIO Pro offers improved data transfer speeds, extended range, and enhanced performance, making it the ideal tool for complex IoT, smart home, healthcare, and industrial BLE projects.

“Making the BleuIO Pro available on Digi-Key expands our reach and provides developers across the globe with easy access to the latest in Bluetooth Low Energy technology,” said Axel Hammar, CEO of Smart Sensor Devices. “We are committed to supporting innovation in BLE development, and the BleuIO Pro is a key part of that mission, offering the performance and flexibility needed to bring solutions to life.”

A Commitment to Global Innovation

By partnering with Digi-Key, Smart Sensor Devices ensures that the BleuIO Pro is readily accessible to developers in every corner of the world. With Digi-Key’s established distribution network, the BleuIO Pro can now be purchased quickly and easily, with dependable international shipping and top-tier customer support.

Availability

The BleuIO Pro is now available for purchase through Digi-Key and can also be found on the BleuIO website at www.bleuio.com. With this launch, developers now have an even more convenient way to access one of the most advanced BLE dongles on the market.

About Smart Sensor Devices

Smart Sensor Devices is a leading solution provider of IOT and Bluetooth Low Energy (BLE), specializing in providing powerful, easy-to-use tools for BLE application development. The company’s products, including HibouAir and BleuIO series, help developers create innovative and efficient solutions across various industries, including IoT, healthcare, automotive, and smart home technologies. The company was founded by Axel Hammar, who serves as the CEO.

For more information on the BleuIO Pro and other products, visit www.bleuio.com.

Contact
Smart Sensor Devices
Website: www.bleuio.com
Email: sales@bleuio.com
Phone: +46 703 709 706

Share this post on :

BleuIO Pro Firmware Update v1.0.1 – Exciting New Features, Improvements, and Bug Fixes

We are excited to announce the release of BleuIO Pro (SSD005) Firmware v1.0.1. This latest update brings several new features, enhancements, and bug fixes, ensuring a more stable and flexible experience for developers using the BleuIO Pro (SSD025) device. Below, we’ll explore the key highlights of this update and how it will improve your BLE application development.

Key Features in Firmware v1.0.1

1. Integration of Commands from BleuIO Versions 2.7.5 and 2.7.6

One of the most significant additions to BleuIO Pro firmware v1.0.1 is the inclusion of commands from BleuIO versions 2.7.5 and 2.7.6. This means BleuIO Pro is now fully up to date with the latest functionality available in the BleuIO series, while also maintaining exclusive commands that are specific to the Pro model.

2. Unique Organization ID (UOI) Support

With this update, BleuIO Pro introduces the ability to set a Unique Organization ID (UOI). This ID will be stored in the device’s flash memory, ensuring it persists even after power cycles. The Unique Organization ID can be displayed in the ATI command response if it is set, providing a simple and effective way for developers to manage and identify their devices across larger projects or multiple devices.

3. Extended ASCII Character Support

As part of our continued effort to enhance the functionality and versatility of BleuIO Pro, this firmware update includes support for Extended ASCII characters. This change allows for the handling of a broader range of characters, expanding the potential use cases for your BLE applications.

4. Device Address Type Command (ATSAT)

Firmware v1.0.1 introduces a new command, ATSAT, which allows developers to toggle the visibility of the device’s address type in the advertising data/scan responses. This feature applies to the AT+FINDSCANDATA and AT+SCANTARGET commands, as well as the AT+GAPSCAN command, which will always show the device address type. This added flexibility allows developers to easily track whether devices are using a Private or Public address type, making it easier to manage multiple devices in your BLE applications.

5. Enhanced Bonded Device Storage

One of the significant improvements in this update is the increased storage capacity for bonded devices. Previously, BleuIO Pro could store information for up to 8 bonded devices. With the v1.0.1 update, this number has been expanded to 16 devices. When the number of bonded devices exceeds 16, the firmware will automatically remove the first device in the list that is not currently connected, ensuring that bonding can continue seamlessly. This improvement ensures that BleuIO Pro can handle larger device networks, especially in scenarios with multiple connections.

New Commands in Firmware v1.0.1

Along with the new features, firmware v1.0.1 introduces several important commands:

  • AT+SETUOI – Set the Unique Organization ID, which will be stored in flash memory and persist through power cycles.
  • AT+CLRUOI – Clear any set Unique Organization ID.
  • ATSAT – Toggle the visibility of the device address type in scan results for AT+FINDSCANDATA and AT+SCANTARGET.

These commands offer greater control over device management, especially in environments with many BLE devices.

Bug Fixes in v1.0.1

Firmware updates aren’t just about adding new features – they also address known issues to improve the overall stability and performance of the device. In v1.0.1, we’ve resolved several bugs that impacted the performance of BleuIO Pro:

  • Device Reset During Scanning: A bug has been fixed where BleuIO Pro would reset when scanning and connecting to two or more devices, especially during a disconnection event.
  • Command Handling Improvements: Several fixes have been implemented for commands that require parameters. Previously, some commands would cause BleuIO Pro to reset if parameters were not provided, especially immediately after boot. This issue has now been resolved.
  • Error Handling for String Parameters: We’ve fixed a bug that caused errors when certain commands with string parameters, such as AT+DEVICENAME, AT+SCANPARAM=NAME, and AT+SETUOI, included an equal sign (=) within the string.
  • AT+AUTOEXEC Command Fix: The AT+AUTOEXEC command, which failed to execute in certain cases, is now fully operational.

How to Update Your BleuIO Pro

To take advantage of the new features and bug fixes in firmware v1.0.1, simply download the latest firmware from our website and follow the provided update instructions. We recommend upgrading to the latest version to ensure your device is running optimally and to access the newest functionality available.

Share this post on :

BleuIO Pro Now Available on Tindie

We are excited to announce that our BleuIO Pro (SSD025) is now available for purchase on Tindie, the premier marketplace for innovative electronic products. This marks a significant milestone as it expands accessibility for developers seeking easy-to-use solutions for Bluetooth Low Energy (BLE) application development.

In addition to the BleuIO Pro, our standard BleuIO (SSD005), which was listed earlier, is also available on Tindie. Both products aim to simplify BLE application development by providing an efficient and developer-friendly experience with the help of built-in AT commands.

Introducing BleuIO Pro (SSD025)

The BleuIO Pro builds on the capabilities of BleuIO by introducing enhanced features tailored for advanced development projects. With improved performance and additional support for demanding BLE applications, BleuIO Pro is perfect for developers looking to create robust and scalable BLE solutions.

Whether you’re working on IoT projects, industrial automation, or custom BLE devices, the BleuIO Pro provides the tools and flexibility required to bring your ideas to life.

Why Tindie?

Tindie is a trusted marketplace for unique electronic products and development tools. By listing both BleuIO and BleuIO Pro on Tindie, we aim to make these tools more accessible to developers worldwide. With Tindie’s shopping experience, finding the right BLE development dongle for your project has never been easier.

Visit the BleuIO store today on Tindie to order your desired BleuIO product.

Share this post on :

BleuIO Firmware Update v2.7.6 – Unique Organization ID and Extended ASCII Support

We are excited to announce the release of BleuIO firmware version 2.7.6! 

This update brings important new features, bug fixes, and enhanced functionality that will make BLE application development even smoother. Here’s a breakdown of what’s included in this latest release:

New Features in v2.7.6

  • Unique Organization ID
    A key new feature in this update is the ability to set a Unique Organization ID (UOI). This ID will be stored in the device’s flash memory, allowing it to persist through power cycles. If the Unique Organization ID is set, it will be displayed in the response to the ATI command. This is particularly useful for users managing multiple BLE devices, as it helps uniquely identify each device by the organization. The Unique Organization ID can also be cleared as needed.
  • Support for Extended ASCII Characters
    BleuIO now handles Extended ASCII characters, broadening the range of compatible inputs for developers. This improvement enhances the device’s ability to handle more complex data and increases flexibility when working with BLE communication.

New Commands

With this firmware update, two new commands have been introduced to set and clear the Unique Organization ID:

  • AT+SETUOISet Unique Organization ID
    This command allows you to set a Unique Organization ID, which will be saved in flash memory and persist through power cycles. When set, the Unique Organization ID will be displayed in the response to the ATI command. You can set a Unique Organization ID up to 100 characters in length.
  • AT+CLRUOIClear Unique Organization ID
    If you need to clear the Unique Organization ID that was previously set, this command will allow you to do so. It removes the ID and resets the field to its default state.

Bug Fixes

  • Fixed Stability Issue During Device Connections
    A bug has been fixed in this update where BleuIO would reset when connected to two or more devices while scanning, especially when a disconnection event occurred. This issue could cause instability and interrupts during device connections. With the release of v2.7.6, this problem has been resolved, ensuring smoother operation when connecting to multiple BLE devices.

How to Update

Visit our firmware download page to access the latest firmware and ensure your BleuIO device benefits from these enhanced capabilities. Be sure to select the correct firmware version for your device model—BleuIO or BleuIO Pro—before downloading.

This update makes BleuIO more powerful, with improved stability and added flexibility for developers. The new Unique Organization ID feature and Extended ASCII support will certainly enhance the way you can use BleuIO in your projects. If you haven’t already, be sure to download the latest firmware and take advantage of these exciting new features!

Share this post on :

Building a Remote BLE Interface: Access BLE devices from Any Location

This article will discuss about accessing a Bluetooth Low Energy (BLE) device—specifically the BleuIO BLE USB dongle—from a cloud-based computer. This setup is invaluable for developers, researchers, and organizations that need to control or monitor BLE devices located in remote or hard-to-reach locations. We will explain how to set up both local and cloud servers, and how to establish a secure connection between them, allowing you to send commands and receive data from a remote BLE device with ease.

Why Do We Need Remote Access to BLE Devices?

Remote access to BLE devices opens up new possibilities in IoT, distributed applications, and various remote monitoring and management scenarios. Here are a few key use cases where this approach can be especially beneficial:

Remote Device Monitoring: In scenarios where BLE devices like sensors or trackers are deployed in different physical locations—such as environmental monitoring stations, healthcare devices in hospitals, or industrial sensors in manufacturing facilities—remote access allows centralized monitoring and control. For example, an environmental monitoring company could deploy BLE sensors in different regions and access data from all devices from a single central hub.

Distributed Development and Testing: Developers and QA engineers can use remote access for testing and debugging BLE applications from any location, without needing to be physically near the BLE devices. This is particularly useful for teams working on IoT applications who want to test BLE functionality across different device types or networks. For instance, a developer could work on BLE application features from home, while the test device is connected to a machine in the office.

Centralized Management of BLE Devices: Organizations that manage multiple BLE devices across various locations, such as in retail stores, hospitals, or warehouses, can benefit from a centralized server setup to communicate with and manage all devices remotely. A central server could send updates, retrieve data, or manage configurations for multiple BLE devices, providing an efficient and scalable solution for distributed IoT applications.

Remote Troubleshooting and Maintenance: For businesses that deploy BLE devices at customer sites or in field locations, remote access allows technical support teams to troubleshoot issues without requiring on-site visits. This can reduce downtime and improve customer satisfaction. For example, a support technician could diagnose issues with a BLE-enabled device at a remote client site, identifying and resolving problems directly from the company’s central office.

By using BleuIO with AT commands, we make BLE application development much simpler and more accessible. The BleuIO dongle is compatible with Windows, macOS, and Linux, allowing consistent development across platforms.

Project Structure and Components

In this project, we’ll use the following components to remotely access and control BLE devices:

  • Device with BleuIO Connected (Local Device): This is the device with the BleuIO dongle physically attached, acting as the local interface for sending and receiving BLE commands. It will run a small server to manage communication with the BLE dongle over a serial connection.
  • Remote Access Server (Cloud Server): This is the server that provides remote access to the local device. By connecting to the local server, it enables us to send commands and receive data from the BLE dongle remotely.
  • LocalTunnel: We’ll use LocalTunnel to generate a secure public URL, allowing the cloud server to communicate with the local device without needing complex router configurations. This URL acts as a bridge, making the local device accessible from anywhere with internet access.
  • Node.js: Both the local device and the cloud server will use Node.js to run simple server scripts that facilitate communication between the cloud server and the BLE dongle.

Step-by-Step Guide

Step 1: Setting Up the Local Server with BleuIO dongle connected to it

Local device is where the BleuIO dongle is physically connected. We’ll set up a Node.js server that communicates with the dongle through the serial port. This server will accept commands from the cloud server and send them to the BLE dongle, then return the response.

Install Node.js (if not already installed) on Local device.

Create a project folder and initialize a Node.js project:
mkdir local_serial_server
cd local_serial_server
npm init -y

Install Dependencies:

  • Install serialport to handle serial communication with the BLE dongle.Install socket.io to manage WebSocket connections.
npm install serialport socket.io

Create the Local Serial Server Script:

  • Create a file named local_serial_server.js. This script will:
    • Listen for WebSocket connections from the cloud server.Accept commands, pass them to the BleuIO dongle, and send back responses.

const http = require('http');
const { SerialPort } = require('serialport');
const socketIo = require('socket.io');

const server = http.createServer();
const io = socketIo(server);

// Define the serial port path and baud rate
const portPath = 'COM592'; // Replace 'COM3' with your dongle's port
const serialPort = new SerialPort({ path: portPath, baudRate: 9600 });

// Listen for incoming connections from the cloud server
io.on('connection', (socket) => {
console.log('Connected to cloud server');

// Receive command from cloud and send to serial port
socket.on('sendCommand', (command) => {
const formattedCommand = `${command}\r\n`;
console.log(`Sending command to serial port: ${formattedCommand}`);
serialPort.write(formattedCommand);
});

// Send serial responses to cloud server
serialPort.on('data', (data) => {
console.log(`Data received from serial port: ${data}`);
socket.emit('serialResponse', data.toString());
});
});

// Start the server on a specified port
const LOCAL_PORT = 4000; // Choose any port, ensure firewall allows it
server.listen(LOCAL_PORT, () => {
console.log(`Local Serial Server running on http://localhost:${LOCAL_PORT}`);
});

Find and Set the Serial Port Path:

In your local_serial_server.js, specify the correct serial port path for your BLE dongle (e.g., COM3 on Windows or /dev/ttyUSB0 on Linux).

Run the Local Serial Server:

  • Start the server by running: node local_serial_server.js

At this point, the local server is ready, but it’s only accessible to itself. Next, we’ll use LocalTunnel to make it accessible to the cloud server.

Step 2: Exposing the Local Server to the Internet Using LocalTunnel

Since local device 1 and cloud device are on different networks, we’ll need to create a public URL for the local server. There are several options to make a local server accessible publicly, including tools like ngrok, Pagekite, and LocalTunnel. For this tutorial, we’ll be using LocalTunnel as it’s free and easy to set up, but feel free to explore other solutions if they better meet your needs.

  1. Install LocalTunnel:
    • On local device, install LocalTunnel globally npm install -g localtunnel
  2. Start LocalTunnel:
    • Open a new terminal window on local device and run lt --port 4000
    • LocalTunnel will generate a public URL (e.g., https://five-sides-live.loca.lt). This URL will allow cloud device to access the local server running on port 4000 of Local device.
  3. Save the LocalTunnel URL:
    • Copy the URL provided by LocalTunnel. This URL will be used in the cloud server configuration on Cloud device.

Step 3: Setting Up the Cloud Server on Cloud device

In this setup, Cloud device will act as the cloud server that connects to local device’s LocalTunnel URL, allowing remote access to the BLE dongle. Cloud device can be any machine with Node.js installed—located anywhere, such as a remote computer in New York. You could also deploy this server on a cloud platform like Heroku, Replit, or Vercel for persistent access.

For simplicity, in this example, we’ll demonstrate how to set up the cloud server on another computer running Node.js, not connected to the same network as local device.

Create a Project Folder on cloud device and Initialize Node.js:

Open a terminal or command prompt on cloud device and create a folder for the cloud server mkdir cloud_serial_server
cd cloud_serial_server
npm init -y

Install Dependencies:

You’ll need express to serve the front-end pages and socket.io to manage WebSocket communication.

Install socket.io-client to allow the cloud server to connect to the LocalTunnel URL created on Local device
npm install express socket.io socket.io-client

Create the Cloud Server Script: In the cloud_serial_server folder, create a file named cloud_server.js. This script will Connect to the LocalTunnel URL (generated by Local device) and forward BLE commands to the local server.Serve the front-end pages (index.html and page2.html) for interacting with the BLE device remotely.

const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const ioClient = require('socket.io-client'); // Client for local serial server

const app = express();
const server = http.createServer(app);
const io = socketIo(server);

// Connect to the local serial server via WebSocket
const LOCAL_SERVER_URL = 'https://real-poets-count.loca.lt';
const localSocket = ioClient(LOCAL_SERVER_URL);

// Serve static files (frontend files for Page 1 and Page 2)
app.use(express.static('public'));

// Handle messages from Page 2 and forward to local serial server
io.on('connection', (socket) => {
  console.log('Client connected to cloud server');

  // Receive command from Page 2 and forward to local serial server
  socket.on('sendCommand', (command) => {
    console.log(`Forwarding command to local server: ${command}`);
    localSocket.emit('sendCommand', command); // Send to local serial server
  });

  socket.on('disconnect', () => {
    console.log('Client disconnected from cloud server');
  });
});

// Receive data from local serial server and forward to clients
localSocket.on('serialResponse', (data) => {
  console.log(`Received data from local serial server: ${data}`);
  io.emit('serialResponse', data); // Broadcast to connected clients
});

const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
  console.log(`Cloud server is running on http://localhost:${PORT}`);
});

Update the LocalTunnel URL in Cloud Server:

Replace the LOCAL_SERVER_URL in cloud_server.js with the LocalTunnel URL you generated on Local device (e.g., https://five-sides-live.loca.lt).

Run the Cloud Server:

Start the cloud server by running:bashCopy codenode cloud_server.js

This will start a server that listens for connections on Cloud device. You can open a web browser on Cloud device and go to http://localhost:3000 to access the front-end pages.

Access the Front-End Pages:

Open a browser and navigate to http://localhost:3000/index.html (for displaying BLE responses) and http://localhost:3000/page2.html (for sending commands).

Note: If you decide to deploy this server to a cloud platform (e.g., Heroku, Replit, or Vercel), replace localhost with the appropriate URL provided by the platform.

With this setup, Cloud device can be anywhere in the world, allowing you to control and receive data from the BLE dongle on Local device (in Stockholm) remotely.

Source code

The source code is available here at https://github.com/smart-sensor-devices-ab/remote_bleuio.git

Output

This tutorial demonstrates the potential of combining Node.js, BLE technology, and tunneling services for remote BLE access. The BleuIO dongle’s compatibility and simplicity make it an excellent choice for developers interested in building BLE applications across various operating systems.

Share this post on :

Firmware Update v2.7.5 for BleuIO: Enhanced Bonding and Device Address Type Display

We’re excited to announce the latest firmware update for the BleuIO Bluetooth Low Energy USB dongle: Firmware Version 2.7.5. This update introduces valuable new features and optimizations designed to improve usability and functionality. Here’s an in-depth look at what’s new and improved with this release.

Key Features and Improvements in v2.7.5

New Command: ATSAT

With version 2.7.5, BleuIO introduces a new command, ATSAT, which allows users to view the device address type—indicating whether the address is public or private—within scan results. This functionality is particularly useful for users looking to distinguish between public and private address types during Bluetooth scanning. When enabled, ATSAT will display:

  • [1] for private addresses
  • [0] for public addresses The ATSAT command works seamlessly with the AT+FINDSCANDATA and AT+SCANTARGET commands, which display the address type in scan results. Additionally, AT+GAPSCAN now always shows the device address type, ensuring that users have visibility into the address type for more effective management of scanned devices.

Expanded Bonded Device Capacity

In a significant enhancement to the device’s bonding functionality, this update expands the number of bonded devices that BleuIO can store from 8 to 16. Previously, when the bonding capacity reached the limit of 8 devices, new bonding was not possible until the user manually removed one or all existing bonded devices using the AT+GAPUNPAIR command. With the updated firmware, BleuIO can now store bonding information for up to 16 devices, simplifying the management of Bluetooth connections.

Automatic Removal of Oldest Bonded Devices:

When the 16-device limit is reached, BleuIO will now automatically remove the oldest bonded device that is not currently connected. Given that BleuIO supports a maximum of 8 simultaneous connections, there will always be at least 8 devices in the list that are not actively connected. This new functionality ensures users can always establish a new bond without the need to manually manage bonded devices, thereby improving convenience and user experience.

How to Update

Visit our firmware download page to access the latest firmware and ensure your BleuIO device benefits from these enhanced capabilities. Be sure to select the correct firmware version for your device model—BleuIO or BleuIO Pro—before downloading.

Share this post on :