Raspberry Pi (or clone) GPIO into Mango
-
Hi,
I am interested in a small project where I will attempt to get data from a DHT22 temperature/humidity sensor connected to a Raspberry Pi (or clone/compatible board, like Orange Pi) into Mango, running on the same board.
There are a number of python libraries for DHT22 sensors so I suppose I could read the temperature, write that to a local file, and then read that back into Mango. But I wondered if there was a more 'elegant' way.
Thanks!
-
Hi Jeremy!
It sounds there's a script, let's call it
readSensor.py
that if you invoke you get an output like1234
. If I am mistaken, and it's a daemon that keeps running, it could be done as you describe or one could write a server socket into the python program and query the python application using the TCP/IP data source pointed at localhost.But, if I am correct, you could use the SSH data source for this purpose. You'd have to generate an SSH key and then place the private key somewhere Mango can access it. Then you can use the SSH data source to invoke
python readSensor.py
and it'll try parse the output into the data type. So, if your output is "%stuff% Sensor value: 1234 %stuff%" you may wish to use as the ssh "Query command,"python readSensor.py | grep -o "Sensor value: [0-9]+" | grep -o "[0-9]+"
for a numeric (or configure 'readSensor.py' to only output123.4
) -
Hey Phil,
Thanks for the reply!
Those are all excellent suggestions. The SSH data source is probably the most aligned with what I want - which is to eliminate the need to daemonize and monitor a separate script outside of Mango.
One quick question - with the SSH data source, can I parse out multiple datapoints in a single SSH request? Eg if the output is:
Temp1: 21 RH1: 86 Temp2: 31 RH2: 75
, can I break that out into four datapoints?Thanks!
-
There is not an entirely direct method in the SSH data source for that that I know of. You cannot do
output=$(command); export output;
then doecho $output;
in another data point. I think this is because every point runs it its own channel (not session, but channel).So, you have two options:
- Make the first point on the data sources query the script and write the value to a file (it could also parse a value if need be). So,
python readSensor.py > ~/DHT22-live-data; cat ~/DHT22-live-data | grep -o "Temp1: [0-9]+" | grep -o "[0-9]+"
and then every data point below can read the data from that file. It would be nice if we had a way to explicitly order the points in the SSH session. There are probably still potential improvements to be made to the SSH data source. Or... - Use point links or meta points to parse out the individual values from the SSH point, which is then just an alphanumeric doing
python readSensor.py
and you can do regex in the point link or meta point to extract the value, i.e.return /.*Temp1 (\d+) .*/.exec(source.value)[1]
- Make the first point on the data sources query the script and write the value to a file (it could also parse a value if need be). So,