Skip to main content

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 asyncio and bleak
  • 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 BleakClient initialization (currently 20 seconds)
  • Platform Issues:
    • Linux: May require bluez and 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

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flow_bt-0.1.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flow_bt-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

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

Hashes for flow_bt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 92be3ca8abab4597060b4d5218077462e21e7689d40452c0c57225eca32f8d2f
MD5 6a1332007f3b7b8eca7e0026bca074ad
BLAKE2b-256 e1c8c7a8089bf322cc9c8d61a0461d4f3b7e90f10931564452e443bec2c7c345

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_bt-0.1.0.tar.gz:

Publisher: release.yaml on Moohan/flow_bt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for flow_bt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f542bc9f1bd3ae01b153793c17605be55b45ce079bebb9c0f8b51c77f320efac
MD5 19962a4e47897c9bc399b911887266f9
BLAKE2b-256 7861eb7fc3cc87e30d2804a27aebd0bb10aea28eb4350c44bc83919c0cdab884

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_bt-0.1.0-py3-none-any.whl:

Publisher: release.yaml on Moohan/flow_bt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page