This is a simple program to read temperature and CO2 concentration from an Air Control USB device. The program was developed with the assistance of ChatGPT by making it analyze lnicola's rust code. The URL of the original rust project is https://github.com/lnicola/co2mon.
This program has been tested with the TFA-Dostmann AIRCO2NTROL MINI sensor (USB VID: 0x04d9, USB PID: 0xa052).
Here's an example of the JSON output format from the program:
{
"timestamp": "2023-08-11 16:51:18",
"temperature": 21.48,
"co2": 727
}
{
"timestamp": "2023-08-11 16:51:23",
"temperature": 21.48,
"co2": 726
}
Here's an example of the JSON output format when using the --all
command-line switch:
{
"timestamp": "2023-08-12 22:45:09",
"temperature_kelvin": 4727,
"temperature_celsius": 22.2875,
"co2": 551,
"co2_uncalibrated(unsure)": 480,
"relative_humidity": 0,
"value_C": 3159,
"value_O": 6901,
"value_R": 11808,
"value_V": 11834,
"value_W": 7870,
"value_m": 3969,
"value_n": 20274
}
- GCC (GNU Compiler Collection)
- HIDAPI Library
You can install the HIDAPI library and GCC on Debian / Ubuntu using the following commands:
sudo apt-get update
sudo apt-get install libhidapi-dev gcc
To install the HIDAPI library and GCC on Arch Linux, you can use the following command:
sudo pacman -S hidapi gcc
- Clone this repository:
git clone https://github.com/tpoechtrager/co2mon_c.git
cd co2mon_c
- Compile the program:
make
Run the compiled executable:
./co2mon
The program will read data from the Air Control USB device and display temperature and CO2 concentration in JSON format.
Press Ctrl+C to stop the program.
The available command-line switches are:
--help: Display help and usage information.
--key <key>: Set the encryption key (16 characters in hexadecimal format). Usually not needed.
--all: Print all available readings as JSON.
On Linux, you need to be able to access the USB HID device. For that, you can save the following udev rule to /etc/udev/rules.d/60-co2mon.rules:
ACTION=="add|change", SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", MODE:="0666"
Then reload the rules and trigger them:
udevadm control --reload
udevadm trigger
Note that the udev rule above makes the device accessible to every local user.
Run the program:
./co2mon
The USB HID protocol is not documented, but is a superset of this one and was reverse-engineered before.
The implementation was inspired by this one.
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.