• 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

    ASCII file data source, reading linux log file events

    User help
    2
    8
    2.8k
    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 want to read a GPIO pin on a Raspberry Pi, but I didn't have any luck trying to read the device file (as per this this thread) so I thought I would try it another way.

      I wrote a small script in python that reads the GPIO pin and then writes any events to a log file.
      The format of my log file is like this:

      2015-05-24 19:31:03,705 INFO CLOSED
      2015-05-24 19:29:48,691 INFO OPEN
      2015-05-24 19:29:52,053 INFO CLOSED
      2015-05-24 19:29:53,094 INFO OPEN
      

      Is there any way to get the ASCII file data source to read the 'CLOSED' and 'OPEN' events plus the timestamp?
      I have tried, I think, dozens of combinations of regex expressions!

      Cheers
      Jeremy

      1 Reply Last reply Reply Quote 0
      • JoelHaggarJ
        JoelHaggar
        last edited by

        I'm really not good with Regex but maybe one of our developers can answer next week. Here is an example file and data source that we use on the MangoES which should help. systemInfo.txt

        ASCII Data Source example JSON: System Info Data Source.json

        Let me know if that helps. Awhile ago Terry was telling me it would be fairly easy to make a data source to talk to the Raspberry Pi GPIO as there is an existing java library we could use. We might have to do that one of these days.

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

          Hey Joel

          Those links 404 for me. I'll have a look in one our our MangoES units though.

          Regex does my head in.

          @JoelHaggar said:

          Let me know if that helps. Awhile ago Terry was telling me it would be fairly easy to make a data source to talk to the Raspberry Pi GPIO as there is an existing java library we could use. We might have to do that one of these days.

          That would be really cool. I have a rPi at home that I am playing around with for various automation tasks.

          FWIW you can also access the GPIO as a linux device/file. Not sure about setting outputs or reading ADC (haven't looked into it) but to read an input (pin 25) you just initialise it like this:

          pi@rpi $ echo 25 > /sys/class/gpio/export
          

          Then when you access this file:

          /sys/class/gpio/gpio25/value
          

          That file contains a single bit, either 0 or 1.

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

            I had a look at the MangoES regex examples. Using regexr.com to test, I copied the regex expression format and ran it against my logfile:

            Screen Shot 2015-05-25 at 12.40.50 pm.png

            Capture group 1 appears to contain 'INFO' and capture group 2 appears to contain the value ('OPEN').
            I set up my point as follows:

            Screen Shot 2015-05-25 at 12.41.22 pm.png

            This regex does capture the timestamp along with the point identifier and point value:

            Screen Shot 2015-05-25 at 12.54.17 pm.png

            But even with my point setup as follows, I still get 'active source point has no value:

            Screen Shot 2015-05-25 at 12.54.36 pm.png

            At this point I believe I'm doing everything correctly, so I'm a bit stuck.
            If anyone else is able to take a crack at this I'd really appreciate the help!

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

              OK, I appear to have gotten Mango reading the file and timestamp correctly.. It seems I just needed to select 'alphanumeric' not 'multistate'. However there is now an issue with repeated entries.

              I'm not sure whether this is the expected behaviour of the module or not. If not I may be able to modify my script/log to suit.. At the moment it appends a new line at the bottom of the log every time the GPIO pin has a rising or falling edge.

              When I create two lines in my log file like this:

              Screen Shot 2015-05-25 at 4.22.48 pm.png

              Mango captures it like this:

              Screen Shot 2015-05-25 at 4.22.35 pm.png

              'Justnow' and 'verysoon' are dummy values I made up. The timestamps are in the past and future respectively.

              What I want is for Mango to just add history point for every line in the log file. Then Mango can read the file every minute and if my sensor was tripped 4 times, I'll get those 4 timestamped events. In other words, the Mango point history should have the same number of rows as my logfile, with the same timestamped values.

              Is this possible or am I way off from what the module is designed to do?

              1 Reply Last reply Reply Quote 0
              • JoelHaggarJ
                JoelHaggar
                last edited by

                This data source will not bring in history and will only look for a current value. If you could get your data into a csv format you could use the dataFile data source to import historical data.

                If you do not have the NoSQL database then it's possible to have duplicate time stamps which is what you are seeing here.

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

                  @JoelHaggar said:

                  This data source will not bring in history and will only look for a current value. If you could get your data into a csv format you could use the dataFile data source to import historical data.

                  If you do not have the NoSQL database then it's possible to have duplicate time stamps which is what you are seeing here.

                  Hey Joel,

                  If I modify my python script so that the logfile is just overwriting the same single line (rather than amending a new line to the log), with the current timestamped state, would that give me the results that I expect? Or would I still get duplicate entries?

                  Cheers
                  Jeremy

                  1 Reply Last reply Reply Quote 0
                  • JoelHaggarJ
                    JoelHaggar
                    last edited by

                    I'm not sure as I've never used it this way but it probably depends on how you have the point set to log. If you have it set to log on change I would expect you would not get duplicates. You might see duplicates in the cache but only the change should be logged to the database.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post