Giter Site home page Giter Site logo

grefeos / co2meter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heinemml/co2meter

0.0 0.0 0.0 22 KB

Python Module to use co2meter code derived from https://hackaday.io/project/5301-reverse-engineering-a-low-cost-usb-co-monitor

License: MIT License

Python 100.00%

co2meter's Introduction

CO2Meter

Python Module to use co2meters like the 'AirCO2ntrol Mini' from TFA Dostmann with USB ID 04d9:a052. There are also other modules using the same interface.

This module supports Python 2.7 and 3.x.

Attribution

Reverse Engineering of the protocol and initial code done by Henryk Plötz.

Read all about it at hackaday

Code derived from this article

Install

With pip:

pip install git+https://github.com/heinemml/CO2Meter

Without pip:

python setup.py install

Remark: you don't need to install, you can also just copy the CO2Meter.py into your project.

If you don't want to run your script as root make sure you have sufficient rights to access the device file.

This udev rule can be used to set permissions.

ACTION=="remove", GOTO="co2mini_end"

SUBSYSTEMS=="usb", KERNEL=="hidraw*", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="plugdev", MODE="0660", SYMLINK+="co2mini%n", GOTO="co2mini_end"

LABEL="co2mini_end"

save it as /etc/udev/rules.d/90-co2mini.rules and add the script user to the group plugdev.

This rules make the device also available as co2mini0 (increase trailing number for each additional device).

Usage

from CO2Meter import *
import time
sensor = CO2Meter("/dev/hidraw0")
while True:
    time.sleep(2)
    sensor.get_data()

The device writes out one value at a time. So we need to parse some data until we have co2 and temperature. Thus the get_data() method will initially return none or only one value (whichever comes first). When you just need one measurement you should wait some seconds or iterate until you get a full reading. If you just need co2 a call to get_co2 might speed things up.

Callback

You can pass a callback to the constructor. It will be called when any of the values is updated. The parameters passed are sensor and value. sensor contains one of these constants:

CO2METER_CO2 = 0x50
CO2METER_TEMP = 0x42
CO2METER_HUM = 0x41

Error handling

In Case the device can't be read anymore (e.g. it was unplugged) the worker thread will end in the background. Afterwards calls to any of the get_* functions will throw an IOError. You will need to handle any resetup, making sure that the device is there etc yourself.

co2meter's People

Contributors

heinemml avatar jannau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.