Introduction: Plotting Real-time Graph From Bluetooth 5.0 Device to Google Chrome
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 showing real-time air quality data; temperate, humidity, pressure, particle matters etc. The data could be later stored on a cloud service of choice.
Things we need :
- Google chrome version 78 or later (windows)
- BleuIO — Bluetooth Low Energy Adapter
- Hibou Air Quality Monitor sensor device
Before we start
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.
Step 1: Creating Files
Create a file called index.html and paste the codes from this github url.
This gives you basic layout of the page with connect, scan, and get data buttons.
Create a file called script.js and paste the following codes from this github url
This js has all the codes and uses Chrome Serial to
- · Connect to your BleuIO Bluetooth dongle,
- · Scan nearby devices using the AT-commands
- · Receive and store the data
- · Generate real time charts from the data.
All the functions used in the script are well commented for understanding.
Now create a style.css on the root folder and paste the codes from this github url.
They will give your site a clean look.
You can download the complete script from here. https://github.com/smart-sensor-devices-ab/Web-Hi...
Step 2: Connect to the Dongle
Once you have everything ready, open the index.html file.
Now connect your BleuIO device to your computer and click connect. Wait for your device to show up on the port screen.
Select your device and press connect.
Once the device is connected, you can scan for nearby devices. For this project I have added a filter so that it will only look for Hibou BLE devices. You will see a list of devices on the dropdown menu. We have a small console on the page that shows scan status and number of devices found. Now you can select a device from the dropdown and start getting data from the device.
Step 3: Generate Graph
Once you click on get data after selecting a device, it will start to generate graphs using chartjs using real-time data from Hibou Air Quality Monitor.
In my script I am showing Pressure, Temperature, ALS, VOC, Humidity, PM2.5 You can customize your own chart by updating values. All the codes for charts are available on script.js
Follow this video if you find any difficulties.