Python client library for Flow 2 air quality monitors via Bluetooth Low Energy
Project description
Flow BT - Flow 2 BLE Client Library
A Python client library for interacting with Flow 2 air quality monitors via Bluetooth Low Energy (BLE).
Features
- Async/await API using
asyncioandbleak - Live data streaming - Real-time PM2.5 readings
- Historical data fetch - Retrieve stored sensor measurements
- Type hints - Full type annotations for better IDE support
- Well documented - Comprehensive docstrings and examples
Getting Started
Prerequisites
- Python >= 3.8
- A Flow 2 air quality monitor
- Bluetooth enabled on your computer
1. Find Your Device
First, wake up your Flow 2 device (press the button until the LED blinks blue), then run the discovery script:
python examples/discover_device.py
This will scan for nearby Flow devices and display their MAC addresses:
✅ Found 1 Flow device(s):
1. FLOW-00:43:A6
MAC Address: E4:3D:7F:05:7C:FA
Use the MAC address in your Flow2Client:
client = Flow2Client("E4:3D:7F:05:7C:FA")
Note: The MAC address format may differ by platform:
- Windows/Linux:
E4:3D:7F:05:7C:FA - macOS:
12345678-90AB-CDEF-1234-567890ABCDEF(UUID format)
2. Install the Package
pip install flow-bt
3. CLI Tool
Flow BT comes with a built-in CLI for quick interaction:
# Discover nearby devices
flow-bt discover
# Stream live data from a specific device
flow-bt read E4:3D:7F:05:7C:FA --duration 60
4. Use the Library in Your Code
Replace YOUR_MAC_ADDRESS with the address from step 1:
Basic Live Streaming
import asyncio
from flow_bt import Flow2Client
async def main():
client = Flow2Client("E4:3D:7F:05:7C:FA") # Your device MAC
def on_data(msg_type, payload):
if msg_type == "live":
print(f"PM2.5: {payload:.2f} µg/m³")
await client.connect()
await client.start_stream(on_data)
await asyncio.sleep(10) # Stream for 10 seconds
await client.disconnect()
asyncio.run(main())
See the Examples directory for more advanced usage like historical data retrieval.
Troubleshooting
Device Not Found
- Wake the device: Press the button until the LED blinks blue
- Check Bluetooth: Ensure Bluetooth is enabled on your computer
- Distance: Move closer to the device (within 10m)
- Interference: Move away from other Bluetooth devices
Connection Fails
- Authentication Error: The authentication key is hardcoded and should work for all Flow 2 devices
- Timeout: Try increasing the timeout in
BleakClientinitialization (currently 20 seconds) - Platform Issues:
- Linux: May require
bluezand proper permissions (sudo usermod -a -G bluetooth $USER) - macOS: May need to grant Bluetooth permissions in System Preferences
- Windows: Ensure Bluetooth is enabled in Settings
- Linux: May require
No Data Received
- Device in Sleep Mode: Press the button to wake it up
- Battery Low: Check battery level with
client.read_battery() - Keep-Alive: The client sends keep-alive commands every 5 seconds automatically
Examples
See the examples/ directory for complete working examples:
discover_device.py- Find your Flow 2 device's MAC addressbasic_stream.py- Live data streamingfetch_history.py- Historical data retrieval
Documentation
- PROTOCOL.md - Detailed BLE protocol specification
- DEVELOPMENT.md - Reverse engineering process and implementation walkthrough
Project Structure
flow_bt/
├── src/flow_bt/ # Main package source
│ ├── __main__.py # CLI Entry point
│ ├── client.py # Flow2Client class
│ ├── constants.py # Protocol constants
│ ├── exceptions.py # Custom exceptions
│ └── protocol.py # Data decoding utilities
├── examples/ # Usage examples
├── docs/ # Documentation (Source for GitHub Pages)
├── tests/ # Test suite
└── tools/ # Analysis/debugging scripts
Development
Running Examples
# Stream live data
python examples/basic_stream.py
# Fetch historical data
python examples/fetch_history.py
Code Formatting
# Format code with black
black src/ examples/
# Lint with ruff
ruff check src/ examples/
License
MIT License - See LICENSE file for details
Acknowledgments
This library was developed through reverse engineering of the Flow 2 BLE protocol. See DEVELOPMENT.md for the full story.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flow_bt-0.1.0.tar.gz.
File metadata
- Download URL: flow_bt-0.1.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92be3ca8abab4597060b4d5218077462e21e7689d40452c0c57225eca32f8d2f
|
|
| MD5 |
6a1332007f3b7b8eca7e0026bca074ad
|
|
| BLAKE2b-256 |
e1c8c7a8089bf322cc9c8d61a0461d4f3b7e90f10931564452e443bec2c7c345
|
Provenance
The following attestation bundles were made for flow_bt-0.1.0.tar.gz:
Publisher:
release.yaml on Moohan/flow_bt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flow_bt-0.1.0.tar.gz -
Subject digest:
92be3ca8abab4597060b4d5218077462e21e7689d40452c0c57225eca32f8d2f - Sigstore transparency entry: 910835735
- Sigstore integration time:
-
Permalink:
Moohan/flow_bt@5a647b5239f49ca5d915a9d100e6760bd4338ee3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Moohan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5a647b5239f49ca5d915a9d100e6760bd4338ee3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file flow_bt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flow_bt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f542bc9f1bd3ae01b153793c17605be55b45ce079bebb9c0f8b51c77f320efac
|
|
| MD5 |
19962a4e47897c9bc399b911887266f9
|
|
| BLAKE2b-256 |
7861eb7fc3cc87e30d2804a27aebd0bb10aea28eb4350c44bc83919c0cdab884
|
Provenance
The following attestation bundles were made for flow_bt-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on Moohan/flow_bt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flow_bt-0.1.0-py3-none-any.whl -
Subject digest:
f542bc9f1bd3ae01b153793c17605be55b45ce079bebb9c0f8b51c77f320efac - Sigstore transparency entry: 910835740
- Sigstore integration time:
-
Permalink:
Moohan/flow_bt@5a647b5239f49ca5d915a9d100e6760bd4338ee3 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Moohan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5a647b5239f49ca5d915a9d100e6760bd4338ee3 -
Trigger Event:
release
-
Statement type: