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.
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
- 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)
- Windows OS
- TFA Dostmann 31.5006 CO2 Monitor connected via USB
- Compiler with C++23 support
- Open
co2monitor.slnin Visual Studio - Build the solution (Ctrl+Shift+B)
- The executable will be in
x64\Debug\co2monitor.exeorx64\Release\co2monitor.exe
Simply run the executable:
co2monitor.exeThe program will:
- Search for the CO2 monitor device
- Initialize the device
- Read sensor data
- Display the results
For continuous monitoring with machine-readable output, use the --csv flag:
co2monitor.exe --csvThis 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
A web-based visualization tool is included in the visualization/ folder.
Quick Start:
run_visualization.batThis 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.
- Vendor ID: 0x04D9 (Holtek)
- Product ID: 0xA052
- Interface: USB HID
The device communicates using HID feature reports and input reports:
- Initialization: Send a 9-byte feature report with the magic bytes
- Reading: Use
ReadFileto read 9-byte input reports - 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
- 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 is calculated as: (byte1 + byte2 + byte3) % 256 == byte4
Based on the reverse engineering work documented at:
- https://blag.nullteilerfrei.de/2025/01/17/my-quest-for-a-reliable-co2-sensor-in-home-assistant
- https://hackaday.io/project/5301-reverse-engineering-a-low-cost-usb-co-monitor
- https://github.com/heinemml/CO2Meter
This is free and unencumbered software released into the public domain.