/co2mon_c

Air Control USB Device Reader

Primary LanguageCApache License 2.0Apache-2.0

Air Control USB Device Reader

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.

Compatibility

This program has been tested with the TFA-Dostmann AIRCO2NTROL MINI sensor (USB VID: 0x04d9, USB PID: 0xa052).

Example Output

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
}

Example Output with --all

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
}

Prerequisites

  • GCC (GNU Compiler Collection)
  • HIDAPI Library

Ubuntu and Debian

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

Arch Linux

To install the HIDAPI library and GCC on Arch Linux, you can use the following command:

sudo pacman -S hidapi gcc

Installation Instructions

  • Clone this repository:
git clone https://github.com/tpoechtrager/co2mon_c.git
cd co2mon_c
  • Compile the program:
make

Getting Started

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.

Available Command-Line Switches

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.

Setting Permissions

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.

Quick Start

Run the program:

./co2mon

Protocol Details

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.

License

This project is licensed under either of

at your option.