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

IBeacon example using Javascript library

Introduction

iBeacon technology allows Mobile Apps to understand their position on a micro-local scale, and deliver content to users based on location. It is a Bluetooth Low Energy technology. Here is an example of how you can setup the BleuIO to advertise as an iBeacon.

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

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>BleuIO - iBeacon</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>iBeacon</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="iBeaconButton"
              class="btn btn-success disabled"
            >
              Create an iBeacon
            </button>
          </div>
          <div class="d-flex p-1">
            <h6 class="m-2">UUID:</h6>
            <input
              type="text"
              id="uuidInputField"
              class="form-control"
              style="width: 616px;"
              value="5f2dd896-b886-4549-ae01-e41acd7a354a0203010400"
            />
          </div>
        </div>
      </div>
      <div class="row mt-5">
        <div class="col-md-12">
          <h5>Output:</h5>
          <p id="output"></p>
        </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'

// Works the first time I drive
// If I stop it and try to start again, nothing happens

// After trying to insert a sleep () after at_advdatai () (line 102)
// does it work to run it over and over again

// The dongles I have work differently when I run this.
// On the marked dongle I can start a beacon once (if I do not use sleep ())
// so it can not start again if I have stopped it.
// The unmarked dongle will be reset as soon as I try to create an iBeacon


const output = document.querySelector ("# output");
const connectButton = document.querySelector ('# connectButton');
const iBeaconButton = document.querySelector ('# iBeaconButton');
const uuidInputField = document.querySelector ('# uuidInputField');

let isConnected = false;
let isAdvertising = false;

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

connectButton.addEventListener ('click', handleConnectButton);

/ **
 * Connects the dongle via the computers COM port
 * Prompts the user to choose port from dialog in chrome
 * Enables the button to start the beacon
 * /
const connect = async () => {

    // Connect to dongle
    await my_dongle.at_connect ();

    isConnected = true;

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

    // Enable the iBeacon button which is disabled by default to avoid errors
    iBeaconButton.addEventListener ('click', handleIBeaconButton);
    iBeaconButton.classList.remove ('disabled');
}

/ **
 * Stops advertising and disconnects the dongle
 * and disables the button to start the beacon
 * /
const disconnect = async () => {

    // Stop advertising
    await my_dongle.at_advstop ();

    // Disconnects the dongle
    await my_dongle.at_disconnect ();

    // Reset dongle status
    isConnected = false;
    isAdvertising = false;

    output.textContent = 'Dongle disconnected';
    connectButton.textContent = 'Connect';

    // Disable the iBeacon button
    iBeaconButton.classList.add ('disabled');
    iBeaconButton.removeEventListener ('click', handleIBeaconButton);
}

/ **
 * Calls the dongles advertise function (at_advdatai ())
 * and provides a UUID as the data
 * Please notice the "i" in the function .at_advdatai ()
 * which is used when creating an iBeacon
 * /
const handleIBeaconButton = async () => {
    // If the dongle is not advertising, start advertising the iBeacon
    if (! isAdvertising) {
        startAdvertising ();
    } else {
        stopAdvertising ();
    }
}

/ **
 * Starts advertising
 * /
const startAdvertising = async () => {

    // Sets the advertise data
    await my_dongle.at_advdatai (uuidInputField.value);

    // Start advertising
    await my_dongle.at_advstart ();

    isAdvertising = true;

    output.textContent = 'iBeacon created';
    iBeaconButton.textContent = 'Stop the iBeacon';
}

/ **
 * Stops advertising
 * /
const stopAdvertising = async () => {
    // Stop the dongle from advertising
   await my_dongle.at_advstop ();

    isAdvertising = false;

    output.textContent = 'iBeacon stopped';
    iBeaconButton.textContent = 'Create an iBeacon';
}

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

Full source also available on GitHub.

← Eddystone example using Javascript libraryScan 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