Using BleuIO with Thingsboard to Monitor Air Quality
March 2, 2024Project Details
In this project, we’ll create a system to monitor air quality in real-time using BleuIO (A Bluetooth Low Energy USB dongle). We’ll scan for an air quality monitoring device called HibouAir and decode the advertised data. The decoded air quality data will then be sent to the ThingsBoard cloud platform for visualization and monitoring.
Introduction to BleuIO
For this project, we’ll utilize a BLE USB dongle called BleuIO. BleuIO is a versatile Bluetooth low energy USB dongle that simplifies the development of BLE applications. It offers a range of AT commands, making it easy to interact with the dongle and create applications. BleuIO supports multiple platforms and programming languages. In our case, we’ll be using Python with the BleuIO Python library, available on PyPI.
About HibouAir
HibouAir is an advanced air quality monitoring device, HibouAir offers real-time data on various critical parameters including CO2 levels, particulate matter (PM 1.0, PM 2.5, PM 10), pressure, temperature, humidity, volatile organic compounds (VOCs), and noise levels. With its plug-and-play setup helps users to take immediate control of their indoor air quality.
About ThingsBoard
ThingsBoard is an open-source IoT platform that enables users to collect, store, visualize, and analyze data from connected devices in real-time. It provides a comprehensive set of features for building scalable and customizable IoT applications, including device management, data processing, rule engine, and customizable dashboards. With ThingsBoard, users can easily connect their devices, monitor their performance, and take actions based on real-time data insights. Its user-friendly interface and flexible architecture make it suitable for a wide range of IoT use cases, from industrial automation and smart cities to agriculture and healthcare. Additionally, ThingsBoard offers seamless integration with various third-party platforms and services, allowing users to leverage existing technologies and expand the capabilities of their IoT solutions.
Hardware Requirements
- BLE USB dongle: BleuIO
- Air quality monitoring device: HibouAir
- Thingsboard account: Create a free or paid Thingsboard account to set up your dashboard.
Project Setup
- Install the BleuIO Python library:
First, we need to install the BleuIO Python library, which allows us to interact with the BleuIO USB dongle. You can install it using pip:pip install bleuio
- Scan for nearby BLE devices:
from bleuio_lib.bleuio_funcs
import BleuIO
import time
my_dongle = BleuIO()
my_dongle.at_central()
my_dongle.at_findscandata('220069') # Replace '220069' with the device ID time.sleep(3)
my_dongle.stop_scan()
- Decode the advertised data
last_element = my_dongle.scan_data[-1]
data_part = json.loads(last_element[0])['data']
last_part = data_part.split(',')[-1].strip('"}')
decoded_env_data = adv_data_decode(last_part)
- Send data to ThingsBoard
import requests api_endpoint = 'https://thingsboard.cloud/api/v1/YOUR_API_KEY/telemetry'
response = requests.post(api_endpoint, json=decoded_env_data)
if response.status_code == 200:
print("Data sent successfully to ThingsBoard.")
else:
print("Failed to send data to ThingsBoard. Status code:", response.status_code)
Decoding Advertised Data
The advertised data contains encoded air quality data. We’ve implemented a function called adv_data_decode
to decode this data based on the HibouAir datasheet. The decoded data includes parameters such as temperature, humidity, CO2 levels, etc.
Integration with ThingsBoard
We use the ThingsBoard cloud platform to visualize and monitor the air quality data. We send the decoded data to ThingsBoard via a POST request to the Telemetry API endpoint. If the request is successful, we receive a confirmation message.
ThingsBoard setup
We have created a device called HibouAir and added pressure , temperature , co2, humidity widget attribute on my dashboard and this is how my dashboard looks. we can see latest data ( data updated 1 mins ago)
Code
Complete code is available on the following repository
https://github.com/smart-sensor-devices-ab/thingsboard-ble-integration
Output
The dashboard can be visited using the following link
https://thingsboard.cloud/dashboard/d54a76c0-d150-11ee-a550-01ba59c8406a?publicId=efae7c90-d151-11ee-a922-37ae9eb95d8c
With BleuIO and ThingsBoard integration, we’ve built a robust system for monitoring air quality in real-time. This project demonstrates the BleuIO can be used in ThingsBoard integrationto create IoT solutions for environmental monitoring.