Get Bluetooth Device Distance Using BleuIO

July 14, 2021
Get Bluetooth Device Distance Using BleuIO

Distance between Bluetooth devices can be measured using RSSI value. Using the script presented in this article will help us to get device distance using BleuIO. 

This script scans for nearby Bluetooth devices and get an approximation of the distance by using well known RSSI to distance formula.



git clone

The script will an index.html and script.js file. Index.html is just has a connect and scan for device button. upon connecting we will be able to scan for nearby devices and. Once the scanning is completed we will be able to see a list of devices and their distance from my computer.

Here is the index.html file

<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

    <title>Get Device Distance Using BleuIO</title>
    <div class="container"> <br>
    <a href=""> <img src="" alt="BleuIO get device distance"></a>
    <h1>Get Device Distance Using BleuIO</h1>
    <button id="connect" class="btn btn-success">Connect</button>
<button id="scan" class="btn btn-warning">Scan Devices</button> &nbsp; &nbsp;  <span id="scanning" class="d-none"> scanning ...</span>  <br><br><br>
<div id="deviceList"></div>
<script src="./script.js"></script>

    <script src="" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>


The script.js file uses bleuio javascript library to connect and scan for BLE devices. Once we get the device list, we try to sort it out by RSSI value and convert RSSI value to distance. Finally we print the result into a table.

Here is the script.js file

import * as my_dongle from 'bleuio'
document.getElementById('connect').addEventListener('click', function(){

Functions to converts rssi to distance 
const getDistance =(rssi=>{
  let n=2
  let mp=-69
  return 10 ** ((mp - (rssi))/(10 * n))
document.getElementById('scan').addEventListener('click', function(){
  var element = document.getElementById("scanning");
      //convert array string to array of object with key value
      const formated = => {
        const [ id, dev,devid,none,rssi,rssival,devname ] = item.split(' ');
        return { id, dev,devid,none,rssi,rssival,devname};
      //array list unique
      let uniqueArr= formated.filter(y=>y.devname!=undefined)
      //sort based on rssi value
      uniqueArr.sort((a, b) => a.rssival > b.rssival && 1 || -1)
      let withDistance=>{
        r.distance=getDistance(r.rssival).toFixed(2)+' meter'
        return r 
      //generate output
      let mytable = `<h2>Device List</h2>
      <table class='table table-striped table-bordered'>
        mytable += "<tr><td>" +j.devid+" - "+ j.devname + "</td><td>"+ j.rssival+"</td><td>"+j.distance+"</td></tr>";
      mytable += "</table>";
      document.getElementById("deviceList").innerHTML = mytable;

To run this script , we can use a web bundler called parcel.

lets go inside the folder and in terminal type.

parcel index.html

The script will scan for five seconds for nearby devices. You can update the value based on your requirements.

You can also run this script from online at

**Make sure your BleuIO dongle is connected

Read more about how to calculate the distance

Share this post on :
Order Now



Buy Now

Get a FREE product for every 10 pcs ordered.