Menu

Send BLE air quality data to Cloudflare D1 with Python
📰

Send BLE air quality data to Cloudflare D1 with Python

Adafruit Industries – Makers, hackers, artists, designers and engineers!·Anne Barela·20 days ago
#lES4f88P
#adafruit#port#python#cloudflare#worker
Reading 0:00
15s threshold

Send BLE air quality data to Cloudflare D1 with Python

sheikh shuhad has posted a tutorial on Hackster.io that moves Bluetooth Low Energy sensor readings into a serverless database. A HibouAir sensor advertises air quality data over BLE. A BleuIO dongle plugged into a computer’s USB port scans for that specific board ID and passes the advertising data to a Python script over the serial port.

The Python side decodes CO2, temperature, and humidity, prints the values to the terminal, and POSTs them as JSON to a Cloudflare Worker. The Worker checks an API key in the request header, then inserts the reading into a Cloudflare D1 database, which is SQLite running on Cloudflare’s edge. A second endpoint returns the most recent stored measurement.

Python only needs pyserial and requests. BleuIO is driven with AT commands, so the application never uses the operating system’s Bluetooth stack. Scan interval, serial port, board ID, Worker URL, and the API key all live in a config file kept out of version control.

See more at hackster.io and content on GitHub.