PeterTh/co2monitor

A command-line application for Windows that reads temperature and CO2 values from the TFA Dostmann 31.5006 CO2 monitor device. Also includes a web-based visualization tool for real-time monitoring.

★ 0Forks 0HTMLGitHub ↗Compare

README

CO2 Monitor Reader for Windows

A command-line application for Windows that reads temperature and CO2 values from the TFA Dostmann 31.5006 CO2 monitor device. Also includes a web-based visualization tool for real-time monitoring.

Project Structure

co2monitor/
├── main.cpp               - Main application entry point and UI logic
├── co2_sensor.h           - CO2 sensor device interface and declarations
├── co2_sensor.cpp         - Device discovery and sensor reading implementation
├── run_visualization.bat  - Launcher script for visualization
├── visualization/
│   ├── index.html         - Web-based chart UI (Plotly.js)
│   └── server.py          - Simple Python HTTP server
└── README.md              - This file

Features

  • Automatic device detection (searches for Holtek USB HID device)
  • Reads CO2 levels (in ppm)
  • Reads temperature (in °C)
  • Reads humidity (in %, if supported by device)

Requirements

  • Windows OS
  • TFA Dostmann 31.5006 CO2 Monitor connected via USB
  • Compiler with C++23 support

Building

  1. Open co2monitor.sln in Visual Studio
  2. Build the solution (Ctrl+Shift+B)
  3. The executable will be in x64\Debug\co2monitor.exe or x64\Release\co2monitor.exe

Usage

Simply run the executable:

co2monitor.exe

The program will:

  1. Search for the CO2 monitor device
  2. Initialize the device
  3. Read sensor data
  4. Display the results

CSV Mode

For continuous monitoring with machine-readable output, use the --csv flag:

co2monitor.exe --csv

This will:

  • Suppress normal output (except errors)
  • Output a CSV header: timestamp,co2_ppm,temperature_celsius
  • Continuously output readings every 5 seconds
  • Each line starts with an ISO 8601 timestamp

Example CSV output:

timestamp,co2_ppm,temperature_celsius
2025-11-26T15:48:42.588,1560,21.23
2025-11-26T15:48:47.692,1562,21.25
2025-11-26T15:48:52.795,1563,21.24

Visualization

A web-based visualization tool is included in the visualization/ folder.

Quick Start:

run_visualization.bat

This starts co2monitor.exe --csv, launches a local Python server on port 8002, and opens the chart in your browser. The chart auto-refreshes every 15 seconds and supports CO2 threshold alerts via browser notifications.

Manual usage: Run python visualization/server.py [port] from the project root and open http://localhost:8002/visualization/index.html.

Technical Details

Device Information

  • Vendor ID: 0x04D9 (Holtek)
  • Product ID: 0xA052
  • Interface: USB HID

Protocol

The device communicates using HID feature reports and input reports:

  1. Initialization: Send a 9-byte feature report with the magic bytes
  2. Reading: Use ReadFile to read 9-byte input reports
  3. Data Format: Each report contains:
    • Byte 0: Report ID (always 0x00)
    • Byte 1: Message type (0x50=CO2, 0x42=Temperature, 0x41=Humidity)
    • Byte 2-3: Value (big-endian)
    • Byte 4: Checksum
    • Bytes 5-8: Padding

Value Conversions

  • CO2: Raw value in ppm (no conversion needed)
  • Temperature: (raw_value / 16.0) - 273.15 (converts from Kelvin to Celsius)
  • Humidity: raw_value / 100.0 (converts to percentage)

Checksum

Checksum is calculated as: (byte1 + byte2 + byte3) % 256 == byte4

Acknowledgments

Based on the reverse engineering work documented at:

License

This is free and unencumbered software released into the public domain.

Contributors

PeterTh

Issues