vfilimonov / co2meter Goto Github PK
View Code? Open in Web Editor NEWA Python library for USB CO2 meter
License: MIT License
A Python library for USB CO2 meter
License: MIT License
You mentioned difficulty interpreting the data from the mini usb. The manufacturer provided me with the following link to interpret the data: http://co2meters.com/Documentation/Other/AN_RAD_0301_USB_Communications_Revised8.pdf
I am getting warning messages from the monitoring since the code is using the frame.append method, which is deprecated.
/home/pi/.local/lib/python3.9/site-packages/co2meter/co2meter.py:310: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
Thank you for creating such a great library.
I have set up this library and successfully got data for CO2 and temperature as follows:
pi@raspberrypi:~ $ python
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import co2meter as co2
>>> mon = co2.CO2monitor(bypass_decrypt=True)
>>> mon.info
{'vendor_id': 1241, 'product_id': 41042, 'path': b'1-1:1.0', 'manufacturer': 'Holtek', 'product_name': 'USB-zyTemp', 'serial_no': '2.00'}
>>> mon.read_data()
(datetime.datetime(2022, 1, 2, 0, 7, 54), 873, 20.100000000000023)
Now I am trying to run the web-server and facing error.
pi@raspberrypi:~ $ co2meter_server
-bash: co2meter_server: command not found
I believe that I have installed the necessary dependecies as shown below. Could you please tell me how to solve this?
pi@raspberrypi:~ $ pip3 list
Package Version
--------------- ------------
certifi 2020.6.20
chardet 4.0.0
click 8.0.3
CO2meter 0.2.6
colorzero 1.1
distro 1.5.0
Flask 2.0.2
future 0.18.2
gpiozero 1.6.2
hidapi 0.11.0.post2
idna 2.10
itsdangerous 2.0.1
Jinja2 3.0.3
MarkupSafe 2.0.1
numpy 1.22.0
pandas 1.3.5
pip 20.3.4
python-apt 2.2.1
python-dateutil 2.8.2
pytz 2021.3
requests 2.25.1
RPi.GPIO 0.7.0
setuptools 52.0.0
six 1.16.0
spidev 3.5
ssh-import-id 5.10
urllib3 1.26.5
Werkzeug 2.0.2
wheel 0.34.2
Module does not work under default user pi
in raspberry py, only under root
.
Despite setting permissions in /etc/udev/rules.d98-co2mon.rules
:
KERNEL=="hidraw*", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", GROUP="plugdev", MODE="0666"
and the fact that device is visible in hid.enumerate()
:
(system3) pi@raspberrypi:~ $ python -c "import hid; print(hid.enumerate())"
[{'product_id': 41042, 'usage_page': 0, 'interface_number': 0, 'product_string': '', 'serial_number': '', 'vendor_id': 1241, 'manufacturer_string': '', 'path': b'0001:0005:00', 'usage': 0, 'release_number': 256}]
it does not work when trying to open it:
(system3) pi@raspberrypi:~ $ python -c "import hid; h = hid.device(); h.open(0x04d9, 0xa052)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "hid.pyx", line 66, in hid.device.open
OSError: open failed
Most likely, some permissions are not set.
Issue on the hidapi
repo: trezor/cython-hidapi#47
Thank you for the work on this project. It is running successfully on my Raspberry Pi on Debian Jessie (Linux).
However, to get it to work, I had to install an additional dependency not mentioned in your documentation. The pip install of hidapi failed due to not being able to link to the udev library.
I corrected that by installing Linux package libudev-dev:
apt-get install libudev-dev
Not sure if you would like to add that information to your README.md, but it may help others.
Kind regards.
I just found this fantastic project. Great work. I would love to use it with my Raspberry Pi at home.
However, from the README I am unclear as to what meters are compatible. Is this repository tailored to devices from the brand CO2meter.com or something?
Maybe you can loose a word or two in the README. Thanks!
Hello,
First of all thank you for such nice software!
I've been using co2meter (0.2.5 from pip) with flask server option on my two PCs running Ubuntu 20.04
It seems that every request for co2 and temperature is followed by kernel message:
Dec 18 11:34:29 homie1 co2meter_server[30179]: INFO:root:[2021-12-18 11:34:29] 510 ppm, 23.8 deg C
Dec 18 11:34:29 homie1 kernel: hid-generic 0003:04D9:A052.00FA: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
Dec 18 11:35:01 homie1 co2meter_server[30179]: INFO:root:[2021-12-18 11:35:01] 507 ppm, 23.9 deg C
Dec 18 11:35:01 homie1 kernel: hid-generic 0003:04D9:A052.00FB: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
Dec 18 11:35:34 homie1 co2meter_server[30179]: INFO:root:[2021-12-18 11:35:34] 506 ppm, 23.9 deg C
Dec 18 11:35:34 homie1 kernel: hid-generic 0003:04D9:A052.00FC: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
so dmesg log looks like this:
[Sat Dec 18 11:35:01 2021] hid-generic 0003:04D9:A052.00FB: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
[Sat Dec 18 11:35:34 2021] hid-generic 0003:04D9:A052.00FC: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
[Sat Dec 18 11:36:06 2021] hid-generic 0003:04D9:A052.00FD: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
[Sat Dec 18 11:36:39 2021] hid-generic 0003:04D9:A052.00FE: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
[Sat Dec 18 11:37:11 2021] hid-generic 0003:04D9:A052.00FF: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
[Sat Dec 18 11:37:44 2021] hid-generic 0003:04D9:A052.0100: hiddev0,hidraw0: USB HID v1.10 Device [Holtek USB-zyTemp] on usb-0000:00:1a.0-1.5/input0
Is it possible to suppress these messages?
pi@raspberrypi:~ $ co2meter_server -H 0.0.0.0 -P 1201
Can you create module with PyUSB and without dependencies of libusb-1.0-0-dev?
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/site-packages/co2meter/server.py", line 316, in init_homekit_target
start_homekit(mon, host=host, port=port, monitoring=False, handle_sigint=False)
File "/usr/local/lib/python3.7/site-packages/co2meter/homekit.py", line 145, in start_homekit
driver.start()
File "/usr/local/lib/python3.7/site-packages/pyhap/accessory_driver.py", line 472, in start
self.advertiser.register_service(self.mdns_service_info)
File "/usr/local/lib/python3.7/site-packages/zeroconf/__init__.py", line 2385, in register_service
self._broadcast_service(info)
File "/usr/local/lib/python3.7/site-packages/zeroconf/__init__.py", line 2419, in _broadcast_service
info.server,
File "/usr/local/lib/python3.7/site-packages/zeroconf/__init__.py", line 652, in __init__
DNSRecord.__init__(self, name, type_, class_, ttl)
File "/usr/local/lib/python3.7/site-packages/zeroconf/__init__.py", line 457, in __init__
self._expiration_time = self.get_expiration_time(100)
File "/usr/local/lib/python3.7/site-packages/zeroconf/__init__.py", line 484, in get_expiration_time
return self.created + (percent * self.ttl * 10)
TypeError: unsupported operand type(s) for +: 'float' and 'str'
Reverting zeroconf to 0.23 remediated this. The issue was on both mac and ubuntu(rasp pi)
Just a simple correction for README.md:
The readme file says the command for starting server and homekit integration is start_server_homekit
but at least in the current version it is called co2meter_server_homekit
.
For TFA Dostmann AIRCO2NTROL Coach version of co2meter I had to comment out the _decrypt(msg)
in co2meter.py, i.e. this works:
def hid_read(self):
""" Read 8-byte string from HID device """
return self._h.read(8)
Otherwise (None, None) is returned.
Here is the >>> mon.info
{'product_name': u'USB-zyTemp', 'vendor_id': 1241, 'serial_no': u'2.00', 'product_id': 41042, 'manufacturer': u'Holtek'}
where to buy it : USB CO2 meter?
The homekit compatibility is missing a dependency on asyncio:
co2meter_server_homekit -H 192.168.200.100 -P 8000 -N co2
Traceback (most recent call last):
File "/usr/local/bin/co2meter_server_homekit", line 11, in <module>
sys.exit(start_server_homekit())
File "/usr/local/lib/python2.7/dist-packages/co2meter/co2meter.py", line 433, in start_server_homekit
start()
File "/usr/local/lib/python2.7/dist-packages/co2meter/server.py", line 342, in start_server_homekit
from homekit import PORT
File "/usr/local/lib/python2.7/dist-packages/co2meter/homekit.py", line 9, in <module>
from pyhap.accessory_driver import AccessoryDriver
File "/home/pi/.local/lib/python2.7/site-packages/pyhap/accessory_driver.py", line 24, in <module>
import asyncio
ImportError: No module named asyncio
However, manually installing asyncio (sudo pip install asyncio
) on a RPI3B+ also does not work:
co2meter_server_homekit -H 192.168.200.100 -P 8000 -N co2
Traceback (most recent call last):
File "/usr/local/bin/co2meter_server_homekit", line 11, in <module>
sys.exit(start_server_homekit())
File "/usr/local/lib/python2.7/dist-packages/co2meter/co2meter.py", line 433, in start_server_homekit
start()
File "/usr/local/lib/python2.7/dist-packages/co2meter/server.py", line 342, in start_server_homekit
from homekit import PORT
File "/usr/local/lib/python2.7/dist-packages/co2meter/homekit.py", line 9, in <module>
from pyhap.accessory_driver import AccessoryDriver
File "/home/pi/.local/lib/python2.7/site-packages/pyhap/accessory_driver.py", line 24, in <module>
import asyncio
File "/usr/local/lib/python2.7/dist-packages/asyncio/__init__.py", line 9, in <module>
from . import selectors
File "/usr/local/lib/python2.7/dist-packages/asyncio/selectors.py", line 39
"{!r}".format(fileobj)) from None
^
SyntaxError: invalid syntax
There is probably no fix to this bug as the asyncio port on 2.7 is not maintained anymore: trollius project on github
Also, the trollius port is not a complete replacement and asyncio is Python 3.4+ only. So co2meter_homekit requires python3 to run.
Note that hidapi is a cython package and cython is not installed by default on Raspbian Stretch Lite.
I'd suggest adding a note to README.md:
Note that hidapi requires cython (
sudo apt-get install cython
) to be installed, otherwisepip install hidapi
will result in anerror code 1
in gcc.
Such a short note would have saved me at least an hour of wondering why it worked on a macbook but not a Raspberry Pi 3 B+ and might help others as well.
Hello,
First of all thank you for such nice software!
I use a carbon dioxide monitor from a gadget. everything works fine with the local web server, but it is not possible to add it to the apple home kit. I'm doing everything according to your instructions, but I can't find the sensor in the "home" application in any way
After following the instructions to install required packages and changing the dev rules, the CO2monitor() functions throws an IOError as open failed. The command and error log can be seen as follows:
python -c "import co2meter as c; m=c.CO2monitor(); print(m.info)"
The error log is:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/co2meter/co2meter.py", line 95, in __init__
with self.co2hid():
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/co2meter/co2meter.py", line 144, in co2hid
self.hid_open(send_magic_table=send_magic_table)
File "/usr/local/lib/python2.7/dist-packages/co2meter/co2meter.py", line 114, in hid_open
self._h.open(self._info['vendor_id'], self._info['product_id'])
File "hid.pyx", line 66, in hid.device.open
IOError: open failed
I've tried using the package on El Capitan 10.11.4, and it fails during import:
>>> import co2meter as co2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/co2meter/__init__.py", line 3, in <module>
from co2meter import *
File "/usr/local/lib/python2.7/site-packages/co2meter/co2meter.py", line 6, in <module>
import hid
File "/usr/local/lib/python2.7/site-packages/hid/__init__.py", line 24, in <module>
hidapi = ctypes.windll.LoadLibrary('hidapi.dll')
AttributeError: 'module' object has no attribute 'windll'
Line 264 in 8a2e12d
It may be useful to be able to set bypass_decrypt
like below.
mon = co2.CO2monitor(bypass_decrypt=True)
Thank you for creating such a wonderful library.
It is very helpful.
Hello,
I have followed the setup instructions for Windows, but when I try to follow the example, I get no data from the read_data() call.
import co2meter as co2
mon = co2.CO2monitor()
mon.info # data is returned here
mon.read_data() # this call waits forever and has no printout
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.