BleuIO

BleuIO

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

›JS library

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

Scan example using Javascript library

Introduction

In this example, we're going to set up the dongle using the following Python script to scan for nearby Bluetooth devices.

First create an Html file called index.html, where you can see the output.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>BleuIO - BLE Scanner</title>
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
      crossorigin="anonymous"
    />
  </head>

  <body>
    <div class="container-md mt-5">
      <div class="row">
        <div class="page-header">
          <h1>BleuIO - <small>BLE Scanner</small></h1>
        </div>
      </div>
      <div class="row mt-5 p-0">
        <div id="buttonRow" class="d-flex justify-content-left">
          <div class="d-flex p-1">
            <button type="button" id="connectButton" class="btn btn-success">
              Connect
            </button>
          </div>
          <div class="d-flex p-1">
            <button
              type="button"
              id="scanButton"
              class="btn btn-success disabled"
            >
              Scan BLE devices
            </button>
          </div>
          <div class="d-flex p-1">
            <h6 class="m-2">Time limit(seconds):</h6>
            <input
              type="text"
              id="scanTimeLimitField"
              class="form-control"
              style="width: 100px;"
              value="1"
            />
          </div>
        </div>
      </div>
      <div class="row mt-5">
        <div class="col-md-12">
          <h5>Output:</h5>
          <div id="output"></div>
        </div>
      </div>
    </div>
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
      crossorigin="anonymous"
    ></script>
    <script src="script.js"></script>
  </body>
</html>

Now create a js file called script.js and paste the following code.

import * as my_dongle from "bleuio";
import "regenerator-runtime/runtime";

const output = document.querySelector("#output");
const connectButton = document.querySelector("#connectButton");
const scanButton = document.querySelector("#scanButton");
const scanTimeLimitField = document.querySelector("#scanTimeLimitField");

let connected = false;

/**
 * Connects / disconnects the dongle
 */
const handleConnect = async () => {
  if (!connected) {
    connect();
  } else {
    disconnect();
  }
};

connectButton.addEventListener("click", handleConnect);

/**
 * Connects the the dongle via the computers COM port
 * Prompts the user to choose port from dialog in chrome
 * Enables the button to start the scan
 */
const connect = async () => {
  // Connect to dongle
  await my_dongle.at_connect();

  connectButton.textContent = "Disconnect";
  output.textContent = "Connected to dongle";

  connected = true;

  // Enable the scan button which is disabled by default to avoid errors
  scanButton.addEventListener("click", handleScanButton);
  scanButton.classList.remove("disabled");
};

/**
 * Disconnects the dongle from the browser
 */
const disconnect = async () => {
  // Stop any ongoing process
  await my_dongle.stop();
  // Disconnects the dongle
  await my_dongle.at_disconnect();

  connected = false;

  output.textContent = "Dongle disconnected";

  // Disable the scan button to avoid errors
  scanButton.removeEventListener("click", handleScanButton);
  scanButton.classList.add("disabled");

  connectButton.textContent = "Connect";
};

/**
 * Handles the scan process.
 * First the dongle will be set in central role.
 * Then perform a scan and print out the response.
 */
const handleScanButton = async () => {
  output.textContent = "";

  scanButton.classList.add("disabled");
  // Set the dongle in central role
  await my_dongle.at_central();

  // Start scanning, at_gapscan() returns a promise with the scan data
  const response = await my_dongle.at_gapscan(scanTimeLimitField.value, false);

  // Print the response to the DOM
  printResponse(response);
  scanButton.classList.remove("disabled");
};

/**
 * Prints a response to the DOM
 * @param {String} response the message to be printed to the DOM
 */
const printResponse = (response) => {
  // Some of the dongles functions returns the data in an Array
  if (Array.isArray(response)) {
    response.forEach((data) => {
      const outputLine = document.createElement("p");
      outputLine.setAttribute("style", "margin: 2px");
      outputLine.textContent = data;

      output.appendChild(outputLine);
    });
  } else {
    const outputLine = document.createElement("p");
    outputLine.setAttribute("style", "margin: 2px");
    outputLine.textContent = response;

    output.appendChild(outputLine);
  }
};

Now open the index.html file in a browser and select the COM port for BleuIO dongle.

Full source also available on GitHub.

← IBeacon example using Javascript librarySecurity Example using Javascript 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