Omnishambles



CO2 Data Logging

Posted: 2020-09-26

Getting a ZGm053UKA CO2 monitor logging to a raspberry pi.

Introduction

With the all smoke from the California forest fires, I’ve been working from home with all the windows shut quite a lot recently. Mid afternoon I was finding myself feeling lethargic and a bit headachy, and not from having forgotten to drink my morning cup of coffee. Somebody suggested it might be high CO₂ levels. I got a metre and low and behold, it was.

Notes

Buy a CO₂ meter. I got a CO2Meter RAD-0301 Mini CO2 Monitor from Amazon, where it was in stock.

One of the nice things is that it has USB output. There’s pretty terrible Windows software, but a nice github project to allow it to be read from Python.

It required a bit of fiddling to get setup, so here’s what I did for my future reference, and anybody else who might find it handy:

Follow steps at https://github.com/vfilimonov/co2meter

sudo apt-get install python3-venv libatlas-base-dev

python3 -m venv venv

source venv/bin/activate

pip3 install hidapi co2meter

pip3 install -U flask pandas numpy matplotlib

Initially I could get status information out of the device

$ python3

>>> mon.info

{'vendor_id': 1241, 'product_id': 41042, 'manufacturer': 'Holtek', 'product_name': 'USB-zyTemp', 'serial_no': '2.00'}

But actually reading any values failed to work. It just timed out and gave zero values, IIRC.

The python library expected the output to be “encrypted”, and was failing on the decrypt. It turned out that the ZGm053UKA wasn’t actually sending the data encrypted. The author of co2meter has kindly provided an option to disable encryption:

import co2meter as co2

mon = co2.CO2monitor(bypass_decrypt=True)

mon.read_data()

That got things up and running, with a web server giving current status and history graph:

However, selecting “last hour” didn’t do anything, and the console was showed chart/co2/1H was giving a 500 error. This got something vaguely working, though I’ve not looked into if it’s really the best way to fix it:

@@ -137,6 +137,8 @@ def prepare_data(name=None, span='24H'):


     if span == '24H':

         data = data.resample('60s').mean()

+    elif span == '1H':

+        data = data.resample('10s').mean()

     elif span == '7D':

         data = data.resample('600s').mean()

     elif span == '30D':


Last updated: 2023-08-26

Tags: techsetup



© Andrew