New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot Connect to MH_Z19B Sensor - code fix attached #1315
Comments
This issue has been mentioned on Radical DIY Forum. There might be relevant details there: https://forum.radicaldiy.com/t/mh-z19b-not-work-with-mycodo-python-but-works-with/1563/3 |
I don't think getty is necessary. How are you wiring your sensor? |
Yes that was me seeking help and I have cross posted this issue on that forum comment.
…________________________________
From: Kyle Gabriel ***@***.***>
Sent: Friday, June 16, 2023 12:34:45 PM
To: kizniche/Mycodo ***@***.***>
Cc: Tony Edwards ***@***.***>; Author ***@***.***>
Subject: Re: [kizniche/Mycodo] Cannot Connect to MH_Z19B Sensor - code fix attached (Issue #1315)
[EXTERNAL EMAIL: DO NOT CLICK links or attachments unless you recognize the sender and are expecting the email]
This issue has been mentioned on Radical DIY Forum. There might be relevant details there:
https://forum.radicaldiy.com/t/mh-z19b-not-work-with-mycodo-python-but-works-with/1563/3
—
Reply to this email directly, view it on GitHub<#1315 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADXPIK3ZTKCOFN2GSRKGU7TXLSKLLANCNFSM6AAAAAAZJRIOFQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
------------------------------------------------------------------------------------ The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material, the disclosure of which is governed by applicable law. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error please contact the sender and destroy the materials contained in this message.
|
I agree. I am not sure if Getty now comes with the OS or not. But I basically built my system following your growing guide online including parts, wiring and OS on the Pi. I will post pic of wiring when I am not mobile.
…________________________________
From: Kyle Gabriel ***@***.***>
Sent: Sunday, June 18, 2023 1:55:32 PM
To: kizniche/Mycodo ***@***.***>
Cc: Tony Edwards ***@***.***>; Author ***@***.***>
Subject: Re: [kizniche/Mycodo] Cannot Connect to MH_Z19B Sensor - code fix attached (Issue #1315)
[EXTERNAL EMAIL: DO NOT CLICK links or attachments unless you recognize the sender and are expecting the email]
I don't think getty is necessary. How are you wiring your sensor?
—
Reply to this email directly, view it on GitHub<#1315 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADXPIK7TC4MEF6ROCQPSCFLXL5FKJANCNFSM6AAAAAAZJRIOFQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
------------------------------------------------------------------------------------ The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material, the disclosure of which is governed by applicable law. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error please contact the sender and destroy the materials contained in this message.
|
Connection is like this: Sensor is correctly read with https://github.com/UedaTakeyuki/mh-z19 so it should be wired up correctly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is related to https://forum.radicaldiy.com/t/mh-z19b-not-work-with-mycodo-python-but-works-with/1563 which was posted on the forum.
Mycodo Version: 8.15.9
OS: Linux raspberrypi 6.1.21+ #1642 armv6l GNU/Linux
Platform: Pi Zero W
Issue:
Unable to get data from the sensor.
Reproduce Issue:
These items are mentioned in the above forum post and was part of the troubleshooting. I have not tried to not do these changes after I found a code fix.
Reviewed https://forum.radicaldiy.com/t/mh-z19b-wiring-sanity-check/677 to properly wire up the sensor
Disable Bluetooth and uninstal Py libraries
/boot/config.txt:
Disable Bluetooth
dtoverlay=disable-bt
[all]
enable_uart=1
Create an Input for MH_Z19B
Testing was done with the following configured serial ports:
Although it is worth noting the following linked serial ports at the OS level:
ls -la /dev/ser*
lrwxrwxrwx 1 root tty 7 Jun 9 10:22 /dev/serial0 → ttyAMA0
lrwxrwxrwx 1 root root 5 Jun 9 10:22 /dev/serial1 → ttyS0
After testing, the proper port to use at least on this platform is /dev/serial0.
Once the proper port is configured and the system runs, the following error is generated:
2023-06-16 12:05:05,067 - ERROR - mycodo.inputs.mh_z19b_6a3d18a1 - UART Location: "/dev/serial0".
2023-06-16 12:05:05,177 - DEBUG - mycodo.controllers.controller_input_6a3d18a1 - get_measurement() found
2023-06-16 12:05:05,179 - DEBUG - mycodo - Input controller with ID 6a3d18a1-c77a-421b-8a71-8be78a91bf88 activated.
2023-06-16 12:05:05,185 - DEBUG - mycodo.controllers.controller_input_6a3d18a1 - listener() not found
2023-06-16 12:05:05,209 - INFO - mycodo.controllers.controller_input_6a3d18a1 - Activated in 5605.7 ms
2023-06-16 12:05:06,238 - DEBUG - mycodo.inputs.mh_z19b_6a3d18a1 - No response
2023-06-16 12:05:06,425 - DEBUG - mycodo.controllers.controller_input_6a3d18a1 - Adding measurements to InfluxDB with ID 6a3d18a1-c77a-421b-8a71-8be78a91bf88: {}
2023-06-16 12:05:07,993 - INFO - mycodo.controllers.controller_input_69d8bf11 - Activated in 1929.7 ms
2023-06-16 12:05:07,994 - DEBUG - mycodo - Input controller with ID 69d8bf11-ef3d-405e-b7be-5696fae74a07 activated.
No response error is coming from this section of the code from inputs/mh_z19b.py:
Expected behavior
The system shall be able to read values from the sensor.
Potential Code Fix
After some comparison to https://github.com/UedaTakeyuki/mh-z19 (please note this library is mentioned several times in the Mycodo mh_z19b code), I discovered one key difference and it was the stop and start of a getter service. Whenever a connection was made to the serial port for this sensor, the third party library had a control feature to start/stop the service. The service was related to below:
$ systemctl --type=service --state=running | grep getty
getty@tty1.service loaded active running Getty on tty1
serial-getty@serial0.service loaded active running Serial Getty on serial0
serial-getty@ttyAMA0.service loaded active running Serial Getty on ttyAMA0
I added these two methods to mh_z19b.py:
Then I added a call to these methods before and after the connection to the serial port in def initialize(self).
For the get_measurement(self) method, I had to do a little more work.
First it was necessary to add a new connection to the device. This method was reusing the old connection and it did not seem to work.
Second, I added a retry around the write command. This was used in the third party code.
And finally, the stop/start Getty commands.
Based on these code changes, I am actively receiving CO2 values using the input/output/functions defined at https://kylegabriel.com/projects/2021/09/mushroom-cultivation-automation.html
Complete file used during testing:
mh_z19b.py.txt
The text was updated successfully, but these errors were encountered: