Recently, Bluetooth Low Energy (BLE) has become one of the most popular wireless standards for IoT devices. Most applications are now using this technology to transfer sensitive information between devices. Therefore, designers looking to integrate BLE into their products should be aware of the BLE security features and limitations.
The main security issues with the pairing between devices with BLE are passive eavesdropping, man in the middle (MITM) attacks and identity tracking.
BLE offers several security features and levels for communication between devices. A designers has to be aware of the specific security threats facing BLE, and try to implement and mitigate security risk in both hardware and firmware design.
BleuIO team is continuously updating its firmware and libraries to make the BLE connection more secure between devices.
At the moment, we have Numeric Comparison, Just Works or Passkey Entry for pairing and bonding.
Numeric Comparison: In this scenario, both the devices have a display unit able to display a six-digit number. Both displays show the same number, and the user is asked to confirm that these numbers match.
Passkey Entry: The Passkey Entry is initially intended for the case that one device has a keyboard, but no display unit and the other device has at least a display unit, for example, a BLE and a PC keyboard scenario. The user is shown a six-digit number (from “000000” to “999999”) on the device with a display and then is asked to enter the number on the other device. If the value entered on the second device is correct, the pairing is successful.
Just Works: This model is primarily intended for the most constrained devices in terms of I/O. The Just Works association model uses the Numeric Comparison protocol, but the user is never shown a number, and the application may simply ask the user to accept the connection. This method doesn’t offer protection against a Man in the Middle (MITM) attack, but it provides the same protection level against passive eavesdropping as the Numeric Comparison.
BleuIO security features :
Set the passkey for passkey authentication on your dongle yourself.
Set the minimum security level your dongle will use. This can be done either when already connected to a device or before. If the device you are connecting to does not meet the security level requirement, the dongle will disconnect from it.
Choose if the dongle should auto accept the numeric comparison authentication request or manually.
Can access protected characteristics that need an increased Security Level.
Please take a look at our Get Started guide to know more about it.
Following video shows how to securely pair between two BleuIO devices.
In this article, we will see how to send BLE data to the cloud. Together with the BleuIO javascript library and BleuIO USB dongle, we will get BLE data from HibouAir. After getting the advertised data, we will pass it to a simple function that will give us an object with meaningful air quality data numbers. Then we will send the data to the firebase cloud.
Once it’s installed, go to the app folder and type parcel index.html
You will have your app running on the browser.
Step 4:
Connect your dongle to your pc.
Open the app on your browser and click connect.
Click on the device information. If you see the device is in peripheral mode than you have to make it central.
Click on the central button. And recheck device information.
Step 4:
Lets scan for nearby devices.
Click on the scan button and look at the list of the scanned device on your console log. Pick any HibouAir devices and copy the device information.
Open the index.js file and go to line 95
replace the scan target information with the one you copied.
Update firebaseconfig.js with
Now save the page and click on send data to the cloud. If your firebase configuration is correct, you should see data showing on your cloud database.
Here is the code for index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl"
crossorigin="anonymous"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-database.js"></script>
<title>BLE data to google firebase</title>
</head>
<body>
<div class="container">
<h2>Send BLE data to cloud</h2>
<p>
This script helps you to connect to BleuIO and sends data to Firebase
cloud.
</p>
<p>
Learn more about BleuIO.
<a href="https://www.bleuio.com/">https://www.bleuio.com/</a>
</p>
<br />
<button class="btn btn-success" id="connect">Connect</button>
<button class="btn btn-success" id="deviceinfo">Device Info</button>
<!-- To get Ble data from HibouAir (Peripheral device), BleuIO has to be on central mode -->
<button class="btn btn-success" id="central">Central Mode</button>
<button class="btn btn-success" id="scan">Scan for devices</button>
<button class="btn btn-success" id="sendDataTCloudBtn">
Send data to cloud Data
</button>
<button class="btn btn-success" id="stopSendingData">
Stop Sending Data
</button>
<br /><br />
<h5><div id="log"></div></h5>
</div>
<script src="./firebaseconfig.js"></script>
<script src="./index.js"></script>
</body>
</html>
Here is the code for index.js file
import * as my_dongle from 'bleuio'
document.getElementById('connect').addEventListener('click', function(){
my_dongle.at_connect()
})
document.getElementById('deviceinfo').addEventListener('click', function(){
my_dongle.ati().then((data)=>console.log(data))
})
document.getElementById('central').addEventListener('click', function(){
my_dongle.at_central().then((data)=>console.log(data))
})
document.getElementById('scan').addEventListener('click', function(){
my_dongle.at_gapscan(2).then((data)=>console.log(data))
})
const parseSensorData = ((input) =>{
let counter = 13;
if (input.includes("5B070503")) {
counter = 17;
}
let sensorData = {
sensorid:
input[counter + 1] +
input[counter + 2] +
input[counter + 3] +
input[counter + 4] +
input[counter + 5] +
input[counter + 6],
pressure:
parseInt(
input[counter + 13] +
input[counter + 14] +
input[counter + 11] +
input[counter + 12],
16
) / 10,
temperature:
parseInt(
input[counter + 17] +
input[counter + 18] +
input[counter + 15] +
input[counter + 16],
16
) / 10,
humidity:
parseInt(
input[counter + 21] +
input[counter + 22] +
input[counter + 19] +
input[counter + 20],
16
) / 10,
voc:
parseInt(
input[counter + 25] +
input[counter + 26] +
input[counter + 23] +
input[counter + 24],
16
) / 10,
als: parseInt(
input[counter + 9] +
input[counter + 10] +
input[counter + 7] +
input[counter + 8],
16
),
pm1:
parseInt(
input[counter + 29] +
input[counter + 30] +
input[counter + 27] +
input[counter + 28],
16
) / 10,
pm25:
parseInt(
input[counter + 33] +
input[counter + 34] +
input[counter + 31] +
input[counter + 32],
16
) / 10,
pm10:
parseInt(
input[counter + 37] +
input[counter + 38] +
input[counter + 35] +
input[counter + 36],
16
) / 10}
return sensorData
})
const sendDataToCloud = (()=>{
//get the scan target device id by scanning for device.
my_dongle.at_scantarget('[1]F9:0D:35:E7:72:65',2).then((data)=>{
let theAdvData = data.filter(element => element.includes("ADV"));
if(theAdvData && theAdvData.length>0){
console.log(theAdvData)
let advData = theAdvData[0].split("[ADV]: ")
// converting advertising string to meaningfull numbers
//and pass it to an array of objects
let airQualityData = parseSensorData(advData[1])
console.log(airQualityData)
// save the data to database
let database = firebase.database(); // which gets the database
let ref = database.ref("records");
//pushing the object to the reference
ref.push(airQualityData)
}
})
})
var intervalId
document.getElementById('sendDataTCloudBtn').addEventListener('click', function(){
sendDataToCloud()
if (intervalId) {
clearInterval(intervalId);
}
intervalId = setInterval(sendDataToCloud ,5000);
document.getElementById("log").innerHTML="Sending data to cloud. Click stop sending data to stop the process.";
})
document.getElementById('stopSendingData').addEventListener('click', function(){
clearInterval(intervalId)
document.getElementById("log").innerHTML="Sending data stopped.";
})
document.getElementById('stopProcess').addEventListener('click', function(){
console.log(my_dongle.stop())
})
Right now, its sending data every 5 seconds.
You can stop the process by clicking stop sending data.
Have a look at the following video for a better understanding.
Protection of private information is essential for every wireless low energy device, from fitness band to payment systems. Privacy mechanisms prevent devices from being tracked by untrusted devices.
Secure communications keep data safe while also preventing unauthorized devices from injecting data to trigger the system’s unintended operation.
In Bluetooth Low Energy (BLE), devices connected to a link can pass sensitive data by setting up a secure encrypted connection, which means making the data unreadable to all but the Bluetooth master and slave devices.
BleuIO has introduced security feature into its latest release (firmware v1.3.0 ). User can now use Numeric Comparison, Just Works or Passkey Entry to make data transmission more secure when working with Bluetooth low energy application using BleuIO.
Numeric Comparison: In this scenario, both devices have a display unit capable of displaying a six-digit number. Both displays output the same number, and the user is asked to confirm that these numbers match.
Passkey Entry: The Passkey Entry is primarily intended for the case that one device has a keyboard but no display unit and the other device has at least a display unit, for example, a PC and a BLE keyboard scenario. The user is shown a six-digit number (from “000000” to “999999”) on the device with a display and then is asked to enter the number on the other device. If the value entered on the second device is correct, the pairing is successful.
Just Works: This model is primarily intended for the most constrained devices in terms of I/O. The Just Works association model uses the Numeric Comparison protocol, but the user is never shown a number, and the application may simply ask the user to accept the connection. This method doesn’t offer protection against a Man in the Middle (MITM) attack, but it provides the same protection level against passive eavesdropping as the Numeric Comparison.
Use the following AT commands to apply secure connection.
AT Commands :
AT+SETPASSKEY for setting or querying set passkey for passkey authentication.
AT+SECLVL for setting or querying minimum security level used when connected to other devices.
AT+NUMCOMPA for accepting a numeric comparison authentication request or enabling/disabling auto-accepting numeric comparisons.
Following video shows how to pair between two BleuIO devices and apply above mentioned security.
This project will show how to collect Realtime Bluetooth low energy data and show it on web browser.
For this project, I am using Bluetooth Low Energy USB dongle called BlueIO, which will act as a central device to retrieve data. Hibou Air Quality Monitor which will serve as a peripheral device to transmit the data. The script is simple to use and can be used for other purposes such as store the data into database or cloud.
The article assumes you have some general knowledge of how Bluetooth Low Energy (BLE) work. Since the Chrome Serial specification on Google Chrome is not finalized yet, you will have to go to enable the highlighted flag, and restart Chrome. open chrome://flags/#enable-experimental-web-platform-features in chrome browser. In this example, we are going to use JavaScript + html (and some CSS for styling) to setup the BleuIO and quickly start scanning.
The index.html file contains the layout of the script. There are two main buttons. Connect, scan and stop getting data. The connect button will use web serial to connect to BleuIO dongle. After that the scan BLE devices button will send some AT commands to the dongle and the respnse will be printed on the scree.
Here is the index.html file
<!DOCTYPE html>
<html lang="en">
<head>
<title>BleuIO Web Bluetooth Example</title>
<meta charset="utf-8" />
<meta name="ssd" content="beaconexample" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" type="image/png" href="images/favicon.png" />
<script>
// Redirect to HTTPS if HTTP is requested.
if (window.location.protocol === "http:") {
window.location.href = "https:" + window.location.href.substring(5);
}
</script>
<link rel="stylesheet" href="style.css" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<div
id="carouselExampleFade"
class="carousel slide carousel-fade"
data-ride="carousel"
>
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="col-md-9 caption">
<img src="images/logo.png" />
<h1>Bluetooth® low energy adapter</h1>
<a
class="btn btn-info btn-lg"
href="https://www.bleuio.com/"
target="_blank"
>Learn More</a
>
</div>
<div class="col-md-3">
<img
src="images/bleuIO_white_withlogo.png"
class="d-block w-100"
alt="..."
/>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-md-9 caption">
<img src="images/logo.png" />
<h1>Create your own BLE applications</h1>
<a
class="btn btn-info btn-lg"
href="https://www.bleuio.com/"
target="_blank"
>Learn More</a
>
</div>
<div class="col-md-3">
<img
src="images/bleuIO_black_withlogo.png"
class="d-block w-100"
alt="..."
/>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row">
<div class="col-md-9 caption">
<img src="images/logo.png" />
<h1>Quick, Innovative, Simple</h1>
<a
class="btn btn-info btn-lg"
href="https://www.bleuio.com/"
target="_blank"
>Learn More</a
>
</div>
<div class="col-md-3">
<img
src="images/bleuIO_black_withlogo.png"
class="d-block w-100"
alt="..."
/>
</div>
</div>
</div>
</div>
</div>
<!-- end carousel -->
</div>
<!-- end container -->
<div class="codesection">
<div class="container">
<h1>Get realtime data from BLE device</h1>
<main class="main">
<div id="notSupported" class="hidden alert alert-danger">
Sorry, <b>Web Serial</b> is not supported on this device, make sure
you're running Chrome 78 or later and have enabled the
<code>#enable-experimental-web-platform-features</code> flag in
<code>chrome://flags</code> <br />
Open
<strong>
chrome://flags/#enable-experimental-web-platform-features</strong
>
in Google Chrome browser.
</div>
<br />
<button id="butConnect" type="button" class="btn btn-success">
Connect
</button>
<br /><br />
<div class="row">
<div class="col-md-3">
<button
id="butScan"
type="button"
disabled
class="btn btn-primary"
>
Scan BLE Devices
</button>
</div>
<div class="col-md-3">
<select
class="devices form-control"
id="devices"
onchange="getSelectedDevice(this)"
>
<option value="">Select a Device</option>
</select>
</div>
<div class="col-md-3">
<button
id="butGetData"
type="button"
disabled
class="btn btn-primary"
>
Get Data
</button>
</div>
</div>
<br /><br />
<pre id="log" class="mt-5 d-none"></pre>
<div id="dataIntoTable" class="mt-5"></div>
<div style="background: white"></div>
</main>
</div>
</div>
<div class="footer text-center mt-3">
Powered by <a href="https://www.bleuio.com/" target="_blank">BleuIO</a> .
A product of
<a href="http://smartsensordevices.com/" target="_blank"
>Smart Sensor Devices</a
>
</div>
<!-- end container -->
<!-- JS, Popper.js, and jQuery -->
<script
src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"
></script>
<script src="script.js" defer></script>
</body>
</html>
The Script.js file contains all the JavaScript codes to connect to the dongle and get advertised data from the air quality monitoring device. After getting the advertised data we try to decodes it to get a meaningful format.
"use strict";
let port;
let reader;
let inputDone;
let outputDone;
let inputStream;
let outputStream;
let isScanning = false;
let isGettingData = false;
let hibouDevices = [];
let rightDevice = false;
let scannedSensorData = []
const log = document.getElementById("log");
const butConnect = document.getElementById("butConnect");
const butScan = document.getElementById("butScan");
const butGetData = document.getElementById("butGetData");
const outputTable = document.getElementById('dataIntoTable')
let outputData='';
document.addEventListener("DOMContentLoaded", () => {
butScan.addEventListener("click", clickScan);
butGetData.addEventListener("click", clickGetData);
butConnect.addEventListener("click", clickConnect);
const notSupported = document.getElementById("notSupported");
notSupported.classList.toggle("hidden", "serial" in navigator);
});
/**
* @name connect
* Opens a Web Serial connection to a serial device such as a Smart USB Dongle 2.0 and sets up the input and
* output stream.
*/
async function connect() {
// - Request a port and open a connection.
port = await navigator.serial.requestPort();
// - Wait for the port to open.
await port.open({ baudRate: 9600 });
const encoder = new TextEncoderStream();
outputDone = encoder.readable.pipeTo(port.writable);
outputStream = encoder.writable;
let decoder = new TextDecoderStream();
inputDone = port.readable.pipeTo(decoder.writable);
inputStream = decoder.readable.pipeThrough(
new TransformStream(new LineBreakTransformer())
);
reader = inputStream.getReader();
readLoop().catch((error) => {
toggleUIConnected(false);
port = null;
log.textContent = "Dongle Disconnected!";
});
}
/**
* @name disconnect
* Closes the Web Serial connection.
*/
async function disconnect() {
// Close the input stream (reader).
if (reader) {
await reader.cancel();
await inputDone.catch(() => {});
reader = null;
inputDone = null;
}
// Close the output stream.
if (outputStream) {
await outputStream.getWriter().close();
await outputDone;
outputStream = null;
outputDone = null;
}
// Close the port.
await port.close();
port = null;
log.textContent = "Dongle Disconnected!";
}
/**
* @name clickConnect
* Click handler for the connect/disconnect button.
* Checks if port != null
* If true: Checks if any beacons is advertising or scans are running and stops the advertsing or scan if so. Then runs disconnect() and set toggleUIConnected to false.
* if false: Runs connect() then set toggleUIConnected to true.
*/
async function clickConnect() {
log.textContent = "";
if (port) {
// If disconnected while scanning the dongle will restart
if (isScanning) {
writeCmd("\x03");
butScan.textContent = "Scan BLE Devices";
isScanning = false;
}
await disconnect();
toggleUIConnected(false);
return;
}
await connect();
toggleUIConnected(true);
}
function getSelectedDevice(selectObject) {
var selectedDevice = selectObject.value;
localStorage.setItem("selectedDevice", selectedDevice);
}
/**
* @name clickScan
* Click handler for the Scan button.
* Checks if a scan is already running by checking the boolean isScanning.
* If isScanning = true: Stops scanning and goes back to peripheral mode, changes the button text and shows the beacon buttons. Finally sets isScanning = false.
* If isScanning = false: Goes into Central mode and starts scanning for ble devices. Also changes button text and hides the beacon buttons. Finally sets isScanning = true.
*/
function clickScan() {
console.log("SCAN BUTTON PRESSED");
if (isScanning) {
writeCmd("\x03"); // Ctrl+C to stop the scan
setTimeout(() => {
writeCmd("AT+PERIPHERAL"); // Set the dongle in Peripheral mode needed for advertising.
}, 500); // Waiting half a bit to make sure each command will get through separately.
isScanning = false;
butGetData.removeAttribute("disabled");
butScan.textContent = "Scan BLE Devices";
return;
}
hibouDevices = [];
writeCmd("AT+CENTRAL"); // Set the dongle in Central mode needed for scanning.
setTimeout(() => {
writeCmd("AT+GAPSCAN=2");
}, 500); // Waiting half a bit to make sure each command will get through separately.
butScan.textContent = "Stop Scanning...";
butGetData.setAttribute("disabled", "true");
log.classList.toggle("d-none", false);
isScanning = true;
}
/**
* @name clickGetData
* Click handler for the 'Get Data' button.
* Checks if a getData scan is already running by checking the boolean isGettingData.
* If isGettingData = true: Stops scanning and goes back to peripheral mode, changes the button text and shows the scan button. Finally sets isGettingData = false.
* If isGettingData = false: Goes into Central mode and starts scanning for ble devices data. Also changes button text and hides the scan button. Finally sets isGettingData = true.
*/
function clickGetData() {
console.log("GET DATA BUTTON PRESSED");
if (isGettingData) {
writeCmd("\x03"); // Ctrl+C to stop the scan
setTimeout(() => {
writeCmd("AT+PERIPHERAL"); // Set the dongle in Peripheral mode needed for advertising.
}, 500); // Waiting half a bit to make sure each command will get through separately.
isGettingData = false;
butScan.removeAttribute("disabled");
butGetData.textContent = "Get Data";
return;
}
writeCmd("AT+CENTRAL"); // Set the dongle in Central mode needed for scanning.
setTimeout(() => {
writeCmd("AT+FINDSCANDATA=FF5B07"); // Will just scan for adv data that contains 'FF5B07' which is the tag for Manufaturing Specific Data (FF) and our Company ID (5B07).
}, 500); // Waiting half a bit to make sure each command will get through separately.
butGetData.textContent = "Stop Getting Data...";
butScan.setAttribute("disabled", "true");
log.classList.toggle("d-none", false);
isGettingData = true;
}
/**
* @name readLoop
* Reads data from the input stream and displays it on screen.
*/
async function readLoop() {
let i=0;
while (true) {
i++;
const { value, done } = await reader.read();
if (value && (!isScanning && !isGettingData)) {
log.textContent += value + "\n";
}
if (value && isScanning) {
if(value === "SCAN COMPLETE") {
isScanning = false;
butScan.textContent = "Scan BLE Devices";
log.textContent += "\n" +"Scan Done" + "\n";
butGetData.removeAttribute("disabled");
log.classList.toggle("d-none", false);
}
let lineValueArray = value.split(" ");
if (lineValueArray[6] === "(HibouAIR)") {
if(lineValueArray[2]) {
hibouDevices.push("["+lineValueArray[2].replace("[1]", "") +"]");
}
log.textContent = "\n" + "hibouDevices found: " + hibouDevices.length + "\n";
}
if(value === "SCAN COMPLETE") {
var select = document.getElementById("devices");
hibouDevices.map(function(item){
var option = document.createElement("option");
option.value = item;
option.text = item;
select.appendChild(option)
});
}
}
if (value && isGettingData) {
if(value === "SCAN COMPLETE") {
isGettingData = false;
butGetData.textContent = "Get Data";
log.textContent += "\n" +"Scan Done" + "\n";
butScan.removeAttribute("disabled");
log.classList.toggle("d-none", false);
}
let lineValueArray = value.split(" ");
if (lineValueArray[0] === localStorage.getItem("selectedDevice") && lineValueArray[3] === "[ADV]:") {
scannedSensorData = parseSensorData(lineValueArray[4]);
outputData = ''
if((i%30) === 0) {
outputData += 'Time: '+new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds()+' '
outputData += 'Pressure: '+scannedSensorData.p+' '
outputData += 'Temperature: '+scannedSensorData.t+' '
outputData += 'Humidity: '+scannedSensorData.h+' '
outputData += 'ALS: '+scannedSensorData.als+' '
outputData += 'PM1.0: '+scannedSensorData.pm1+' '
outputData += 'PM2.5: '+scannedSensorData.pm25+' '
outputData += 'PM10: '+scannedSensorData.pm10+' '
//log.innerHTML += "\n" + "SensorData= " + JSON.stringify(scannedSensorData) + "\n";
log.innerHTML += "\n" +outputData
}
}
}
if (done) {
console.log("[readLoop] DONE", done);
reader.releaseLock();
break;
}
}
}
/**
* @name writeCmd
* Gets a writer from the output stream and send the command to the Smart USB Dongle 2.0.
* @param {string} cmd command to send to the Smart USB Dongle 2.0
*/
function writeCmd(cmd) {
// Write to output stream
const writer = outputStream.getWriter();
console.log("[SEND]", cmd);
writer.write(cmd);
// Ignores sending carriage return if sending Ctrl+C
if (cmd !== "\x03") {
writer.write("\r"); // Important to send a carriage return after a command
}
writer.releaseLock();
}
/**
* @name LineBreakTransformer
* TransformStream to parse the stream into lines.
*/
class LineBreakTransformer {
constructor() {
// A container for holding stream data until a new line.
this.container = "";
}
transform(chunk, controller) {
// Handle incoming chunk
this.container += chunk;
const lines = this.container.split("\r\n");
this.container = lines.pop();
lines.forEach((line) => controller.enqueue(line));
}
flush(controller) {
// Flush the stream.
controller.enqueue(this.container);
}
}
/**
* @name toggleUIConnected
* Changes the text on butConnect depending on the action it actually will preform in the current state.
* @param {boolean} connected true if connected, false if disconnected.
*/
function toggleUIConnected(connected) {
let lbl = "Connect";
if (connected) {
lbl = "Disconnect";
butGetData.removeAttribute("disabled");
butScan.removeAttribute("disabled");
}
butScan.classList.toggle("disabled", !connected);
butGetData.classList.toggle("disabled", !connected);
butConnect.textContent = lbl;
}
/**
* @name parseSensorData
* Parse the data from advertising data string.
* @param {string} input advertising data string.
* @returns {object ={sensorid:{string}, p:{int}, t:{int}, h:{int}, als:{int}, pm1:{int}, pm25:{int}, pm10:{int}}}
*/
function parseSensorData(input) {
let counter = 13;
if (input.includes("5B070503")) {
counter = 17;
}
let sensorData = {
sensorid:
input[counter + 1] +
input[counter + 2] +
input[counter + 3] +
input[counter + 4] +
input[counter + 5] +
input[counter + 6],
p:
parseInt(
input[counter + 13] +
input[counter + 14] +
input[counter + 11] +
input[counter + 12],
16
) / 10,
t:
parseInt(
input[counter + 17] +
input[counter + 18] +
input[counter + 15] +
input[counter + 16],
16
) / 10,
h:
parseInt(
input[counter + 21] +
input[counter + 22] +
input[counter + 19] +
input[counter + 20],
16
) / 10,
voc:
parseInt(
input[counter + 25] +
input[counter + 26] +
input[counter + 23] +
input[counter + 24],
16
) / 10,
als: parseInt(
input[counter + 9] +
input[counter + 10] +
input[counter + 7] +
input[counter + 8],
16
),
pm1:
parseInt(
input[counter + 29] +
input[counter + 30] +
input[counter + 27] +
input[counter + 28],
16
) / 10,
pm25:
parseInt(
input[counter + 33] +
input[counter + 34] +
input[counter + 31] +
input[counter + 32],
16
) / 10,
pm10:
parseInt(
input[counter + 37] +
input[counter + 38] +
input[counter + 35] +
input[counter + 36],
16
) / 10}
return sensorData
}
The term IoT or Internet of Things, is bringing new technologies to transform and make the world in the era of connectivity. The IoT says that everything is connected and Bluetooth has made it much easier to work.
There are several names: Bluetooth Smart, Bluetooth 4.0+ and BLE (Bluetooth Low Energy). We can say that BLE is the friendliest version in terms of application and Bluetooth power. which helps mobility industry an easy connection in the world of applications.
Have you noticed that when you start a scan on your cell phone’s Bluetooth connection, you find several devices around, including the name (ID) of these solutions, without using any password, without making any pairing? And these devices can work simply with small batteries and with a long duration.
Unlike traditional Bluetooth that was created to transmit long files, such as music, photos or other media, consuming a lot of energy, on the other hand, BLE transmits little information in a short time, with minimum consumption of energy.
What benefits can this bring to our security world?
Specialists mentioned that, in 2025, everything will be connected; for example, an intrusion sensor will be connected to the camera and door devices.
And with BLE that future is already knocking on our doors, we already have smart locks that allow opening through cellular devices, we can also control window opening, automate gates, and control other devices, all safely, with protected and extremely friendly way. This technology will replace wires in the future. The information will be transmitted from device to device, forming a large network, with alternative routes and redundancies.
We will increasingly have the use of “do it yourself”, where the user will install everything necessary, configure (the system will be self-configurable), in addition to monitoring everything through tablets and cell phones.
Smart Sensor Devices has developed an amazing device called BleuIO to create BLE application easily. It has an integrated ready to use software that enables the user to easily create new BLE applications with simple AT-Commands scripts. You can update the firmware or flash your own applications with the integrated bootloader of the dongle.
This project will show how to collect real-time BLE data and export as csv using web browser.
For this project, I am using Bluetooth Low Energy USB dongle called BlueIO, which will act as a central device to retrieve data. Hibou Air Quality Monitor which will serve as a peripheral device to transmit the data. The script is simple to use and can be used for other purposes such as store the data into database or cloud.
The article assumes you have some general knowledge of how Bluetooth Low Energy (BLE) work. Since the Chrome Serial specification on Google Chrome is not finalized yet, you will have to go to enable the highlighted flag, and restart Chrome.
open chrome://flags/#enable-experimental-web-platform-features in chrome browser.
In this example, we are going to use JavaScript + html (and some CSS for styling) to setup the BleuIO and quickly start scanning.
Smart Sensor Devices announces that its Bluetooth low energy USB dongle called BleuIO will be available for immediate shipment worldwide through Digi-Key Electronics, a global electronic components distributor, as a result of a new distribution agreement.
The product is listed on Digikey and available for purchase.
“Through our distribution partnership with Digi-Key we are making it easier for the maker community worldwide to quickly and reliably access our solutions and accelerate their BLE application development efforts,”
said Axel G. Hammar Founder & CEO of Smart Sensor Devices.
About BleuIO
This BleuIO is a Bluetooth low energy USB dongle that can be used to create new BLE 5.0 application in the fastest and easiest way. Just use the AT Commands available on the device. Details about the AT commands can be found on getting started guide which will help anyone make a fast peripheral or central application (or both) without having to develop a single line of embedded code.
It is a fully integrated solution, providing MCU and Bluetooth radio in one chip, based on Dialog Semiconductor latest Bluetooth chip DA14683. The FLASH based device permits field or boot upgradable, while the application is stored on FLASH memory. Custom settings can also be stored on FLASH memory or OTP for higher integrity. It supports Windows 10, Linux and macOS.
About Digi-Key Electronics
Digi-Key Electronics, headquartered in Thief River Falls, Minn., USA, is an authorized global, full-service distributor of electronic components, offering more than five million products, with over 1.3 million in stock and available for immediate shipment, from over 650 quality name-brand manufacturers. Digi-Key also offers a wide variety of online resources such as EDA and design tools, datasheets, reference designs, instructional articles and videos, multimedia libraries, and much more. Technical support is available 24/7 via email, phone and webchat. Additional information and access to Digi-Key’s broad product offering can be found by visiting www.digikey.com.
Bleuio Javascript library is available on npm(Node Package Manager).
Now you can easily access all the BleuIO functions from web browser.
Before starting to install our library, make sure you have Chrome 78 or later version installed on your system. You will also need to enable the #enable-experimental-web-platform-features flag in chrome://flags. To do that, Open chrome://flags/#enable-experimental-web-platform-features in Google Chrome browser and enable this feature.
You can use chrome.serial to create web apps that can access the BleuIO AT commands easily using this library.
Now Install the library by running
npm i bleuio
npm automatically downloads and installs the most recent library on your system in the correct directory. To check that the installation went well, follow the simple readme file from
Bleuio Python library is available on PyPI (the Python Package Index) to simplify the life of Python developers.
Before starting to install our library, make sure your you have the latest python installed on your system.
If you have never installed a library from PyPI, you must install the pip tool enabling you to download and install a PyPI package. There are several methods which are described on this page.
Now Install the library by running
pip install bleuio
Easy, right? pip automatically downloads and installs the most recent library on your system in the correct directory. To check that the installation went well, you can launch a Python interpreter and run the following lines:
from bleuio_lib.bleuio_funcs import BleuIo my_dongle = BleuIo() my_dongle.start_daemon() print(my_dongle.ati())
Good luck on creating amazing Bluetooth Low Energy application using BleuIO
In this project, we will demonstrate how two Bluetooth dongles can be paired together and share data between them. To pair two Bluetooth dongle, one of them needs to be configured as Central and other needs to be configured as Peripheral. We already wrote a Python script that sends data back and forth between dongles.
In short :
One dongle will take on the Central role and the other will take on the Peripheral role.
Then they will connect to each other.
The Central dongle will then start off sending a message; “Echo”.
The Peripheral dongle will then receive the message and send it back to the Central dongle which in turn will receive it and send it back and so forth until the script is stopped.
Step 1 : Install Python on both laptop and connect a USB Dongle on each of them.
Step 2 : For a quick setup, copy the following script and save it on your local directory as sps_example.py . You can also get the source code from our GITHUB PAGE.
Step 3: Change the COM-port in the script on both computers to match the ones your dongles is actually connected to. For the one that will be set up as the Central dongle you will also need to change the target_dongle_mac_address variable to the MAC address of your Peripheral dongle. You can get the MAC address by scanning for the other dongle while it’s advertising. To learn more about how to scan check out our scanning tutorial.
Step 4: Open up the command prompt, on both computers, in the directory where the script is located. Start the script by typing python sps_example.py and press Enter.
Step 5: You should now be prompted to enter 1 or 2 depending on what role the dongle should have. Set one as Peripheral and the other as Central. It is advisable to setup the Peripheral first as the Central will need someone to connect to.
You should now see in the terminal how the dongles send and recieve data to and from each other.
The script will run until you stop it.
And that is an example of how we can send data between two dongles. If you want to stop the script, you can simply press control C.