• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Raspberry Pi (or clone) GPIO into Mango

    How-To
    2
    4
    2.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jeremyhJ
      jeremyh
      last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by phildunlap

        Hi Jeremy!

        It sounds there's a script, let's call it readSensor.py that if you invoke you get an output like 1234. 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 output 123.4)

        1 Reply Last reply Reply Quote 0
        • jeremyhJ
          jeremyh
          last edited by

          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!

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            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 do echo $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:

            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, 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...
            2. 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]
            1 Reply Last reply Reply Quote 0
            • First post
              Last post