No data is returned with read_data()
davidskeck opened this issue · 16 comments
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?
Hello guys, sorry for coming back late to you.
Unfortunately I don't have any device with Windows installed anymore, so I suspect that I could not be of a help any time soon here..
But in case you figure out the solution by yourself - could you please let me know about it, so I'll add it to the readme. Many thanks!
FWIW, this wasn't a Windows issue for me—I got the same problem on MacOS and Raspbian Linux.
I encountered the same issue with my ZGm053UKA which identified itself as:
>>> mon.info
{'vendor_id': 1241, 'product_id': 41042, 'manufacturer': 'Holtek', 'product_name': 'USB-zyTemp', 'serial_no': '2.00'}
I found this document describing the protocol, which matches what a raw hid read was giving me. i.e. it's not encrypted. The following solved the issue for me:
def hid_read(self):
""" Read 8-byte string from HID device """
- msg = self._h.read(8)
- return self._decrypt(msg)
+ return self._h.read(8)
@contextmanager
def co2hid(self, send_magic_table=True):
Hope that's helpful.
@a-r-w I can confirm that your fix also worked for me. OS X 10.14.6, Python3, Device: TFA-Dostmann AirControl Mini CO2.
Thanks!
Hello all. I've added an argument to __init__
: bypass_decrypt
. If set to True, read_data
will not call _decrypt
. Please let me know if it's ok and I'll push the new version to pypi.
@a-r-w Thanks a lot for the solution!
New co2meter.py is not working. The hack from a-r-w already works fine.
`Olivers-MacMini2018:co2meter Oliver$ ls
pycache co2meter.sh log_co2.csv usage.txt
co2meter.py co2meter_old.py readCO2meter.py
Olivers-MacMini2018:co2meter Oliver$ python3
Python 3.9.0 (default, Dec 4 2020, 12:07:11)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import co2meter as co2
mon = co2.CO2monitor()
mon.read_data()
co2 temp
2021-01-03 19:24:48 None None
Olivers-MacMini2018:co2meter Oliver$ python3
Python 3.9.0 (default, Dec 4 2020, 12:07:11)
[Clang 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import co2meter as co2
mon = co2.CO2monitor()
mon.read_data()
co2 temp
2021-01-03 19:25:51 1072 22.0375
`
import co2meter as co2
mon = co2.CO2monitor(bypass_decrypt=True)
mon.read_data()
should do the same as #16 (comment)
Works perfectly. Sorry for the inconvinience.
Hi @vfilimonov, glad it was useful. I can also confirm 5d4187d is working fine for me with bypass_decrypt=True. Thank you!
I tried a-r-w's hack and the new commit's bypass-decrypt approach but I am still getting the hang-up when calling read_data(). Has anyone had this issue with the newer Co2Meters? Is there maybe a new way that the data is encrypted or something? Mine's info is: {'vendor_id': 1241, 'product_id': 41042, 'manufacturer': 'Holtek', 'product_name': 'USB-zyTemp', 'serial_no': '2.00'}
Hi @Pinkers Thank you for your interest in co2meter and I’m sorry about your issues.
To be honest there’s little what I can do or suggest about other vendors. I did not find any proper documentation and just hacked myself out looking for boots and pieces in the Internet and other repos (see readme - resources).
Where exactly the code hangs?
It worth looking at what self._h.read() returns for different message lengths. Perhaps the message is not encrypted but shorter/longer.
If encrypted - worth trying different magic words - e.g. your vendor name.
That are the obvious things that come to my mind to start with.
@vfilimonov Thank you so much for the quick reply! After many days of debugging it is now working though I have no idea why. The only thing that has changed is that I ran it with the proprietary software found here. Maybe that configured the HID driver for the device or something, honestly I am stumped. But I really appreciate the help, and I am grateful it is now working
To update this, read_data() only returns when the ZG.exe (proprietary software mentioned earlier) is running first, then the CO2Meter is connected via USB, then read_data() is called. Any insights into why are welcome.
I can also confirm this issue, With the device TFA AIRCO2NTROL COACH ({'vendor_id': 1241, 'product_id': 41042, 'manufacturer': 'Holtek', 'product_name': 'USB-zyTemp', 'serial_no': '2.00'}), read_data() only shows values when the ZG.exe was started before.