• 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

    Import values from python script?

    User help
    2
    21
    8.3k
    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.
    • H
      Holzatelier
      last edited by

      Ok so I've changed the python script and it has created a CSV file with the labels value1 , value2 , value3 in the first row and the recieved values 12,13,14 in the second row. Now I want to create a Data source from a "Data file" and put the file path in the "Path to data file or folder" and "Check"-> File exists.
      Then I create a Data point and set " Identifier in import document" to say value1.
      Save everything and activate.
      Now I go to "Data point details" but I get no value.

      What am I missing?

      Thanks

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

        Hi Holzatelier,

        Sorry can't figure out how to include a screen shot.

        No worries, it can sometimes give trouble and not finish linking in the uploaded image.

        Is it somehow possible to get these values automatically at an intervall of say 5 minutes into Mango datapoints?

        In so very many ways, yes, it is possible. You could,

        1. Open a socket in your python script and take a connection from a TCP/IP data source, which could then query your python script with TCP/IP points.
        2. Create a virtual serial server socket and let your python script submit messages to a Serial data source, which then is in the context of a script that parses out values (but for your protocol, you could probably just use a serial data source's points to regex parse out the appropriate values.
        3. Go through some protocol wrapper on top of that, like HTTP, Modbus, BACnet, etc. A lot of options condensed into this one, including the Data File approach you have tried. It doesn't sound like you implemented your own CSV importer. Did you try to use one of the example importers for the CSV file?

        But probably the way I would choose is to,

        1. Create a user with set access to some virtual points set up to log all data that you've set up to receive these values. Create an authentication token on that user, and use that token in your script to POST API calls to the /rest/v2/point-values endpoint. You will submit the token in an HTTP header like, Authorization: Bearer <token> and the POST body would be
        [
          {
            "xid": "pointXidHere",
            "value": 123.456,
            "timestamp": 1535475910355,
            "dataType": "NUMERIC"
          },
          {
            "xid": "pointXidHere",
            "value": 789.123,
            "timestamp": 1535476010355,
            "dataType": "NUMERIC"
          },
          ....
        ]
        

        You can also do stuff like create points through the API. You can enable swagger in your env.properties, restart Mango, and then navigate to either /swagger/index.html (Mango 3.4.x and prior) or /swagger-ui.html (Mango 3.5 forward) to explore the API.

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

          It looks like I should probably have advised the PUT /rest/v1/point-values endpoint. Everything else would be the same, but the v1 endpoint is subject to logging type and will generate point events to inform websockets or meta scripts about the points' having updated.

          1 Reply Last reply Reply Quote 0
          • H
            Holzatelier
            last edited by

            Phil!

            Thanks so much! Lots of options! I hate to admit it but I don't understand half of it ... Somuch to learn, but so little time.
            Anyway after finding a CSV example file I was able to get the data import working. It's maybe a bit crude but it does the trick.

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

              The data file is a good way to go, too!

              I wonder which example you drew from though, as I know (and really should just fix) the SimpleCsvImporter and the MultiColumnCsvImporter have hh in their date format when they almost certainly meant HH.

              1 Reply Last reply Reply Quote 0
              • H
                Holzatelier
                last edited by

                Phil, I simply searched the installation folder for "CSV" and found this example of a csv-file:
                ../web/modules/dataFile/web/CompilingGrounds/CSV/multiColumnCsv.csv
                I then adjusted my python script to output the csv file in the appropriate format.

                Now I wonder if there is a way to have mango start my python script automatically since I have not been able to get crontab to start it periodically for me....

                1 Reply Last reply Reply Quote 0
                • H
                  Holzatelier
                  last edited by

                  Ok, after a few hours of poking around and following various suggestions I actually managed to fumble my way to a working solution and my python script actually runs through cron.
                  So now I wonder if there is a way to change the time format in Mango to 24 hrs.
                  Is there some setting to display 2:00:00 PM as 14:00:00 ?

                  Thanks

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

                    Now I wonder if there is a way to have mango start my python script automatically since I have not been able to get crontab to start it periodically for me....

                    Certainly. I suspect you'll find the Process Event Handler, perhaps on something like the System startup event, can do this for you.

                    So now I wonder if there is a way to change the time format in Mango to 24 hrs.
                    Is there some setting to display 2:00:00 PM as 14:00:00 ?

                    Yes, it's a simple change. Go to Mango/web/modules/dataFile/web/CompilingGrounds/CSV/ and edit MultiColumnCsvImporter.java . Change,

                    private DateTimeFormatter dtf = DateTimeFormat.forPattern("MM/dd/yyyy hh:mm:ss");
                    

                    to

                    private DateTimeFormatter dtf = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss");
                    

                    Then edit the data source edit page to recompile the importer class:

                    0_1535642816422_compileTemplates.png

                    And restart the data source.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Holzatelier
                      last edited by

                      Phil, I was thinking of changing the time format for all data points in Mango. So for example Modbus and Bacnet. Can I change the Time formatter for those modules as well?

                      Thanks

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

                        I'm not really sure what you mean. There isn't time formatting in Modbus, for instance. The timestamps for a poll on Modbus is the time that the poll occurred measured in elapsed milliseconds, this is then converted for display using the locale set on your user. If you change your user's locale, you should see the new UI use an appropriate time format. It is not currently possible to explicitly control the time format.

                        1 Reply Last reply Reply Quote 0
                        • H
                          Holzatelier
                          last edited by

                          I meant the Times given in the UI. For example in the "data point details" page the windows "point history values", "point statistics" and "chart" all give the Time in 12 hrs AM/PM format. I tought maybe there is a setting to change that format to 24 hrs (military time format).
                          But now I'm nit picking ...

                          Thank again for the help.

                          1 Reply Last reply Reply Quote 0
                          • H
                            Holzatelier
                            last edited by

                            Just set my locale and bingo I'm a happy camper! There's just so much to explore!
                            Cool !! Thanks!

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

                              Sweet! Glad to hear it!

                              I'm not sure this would be easy to change on the data point details page or other pages we provided, but if you find yourself using <ma-point-value></ma-point-value> components in your custom dashboards and wanting to provide a time format, the API docs (enable in Administration --> Edit menu) suggest,

                              display-type
                              (optional)
                              string	
                              Changes how the data point value is rendered on the page. Options are:
                              
                              rendered (Displays live value in point's text rendered format) *Default
                              converted (Displays live value in point's unit converted format)
                              dateTime (Displays the time the of the point's last update)
                              
                              date-time-format
                              (optional)
                              string	
                              If dateTime is used with display-type then you can pass in a momentJs string to format the timestamp. (Defaults to Mango default date format set in system settings)
                              

                              where the data point details page is displaying time in that element with the settings,

                              display-type="dateTime" flash-on-change="true" same-day-date-time-format="timeSeconds"
                              

                              where timeSeconds is one of the shorthands for normal formats one may find around Mango, defined: https://github.com/infiniteautomation/ma-dashboards/blob/bf9f8ba49754a1a93d59d1f3bd562b69b8523680/UI/web-src/ngMango/ngMangoServices.js#L151

                              1 Reply Last reply Reply Quote 0
                              • H
                                Holzatelier
                                last edited by

                                I haven't yet started with the custom dashboards, so I will keep this in mind for future reference.
                                Another thing I having difficulty with is the spline setting for the charts.
                                I've set my data points "point properties/Plot type" to "Spline" but the chart in the "Data Point Page" is never a smooth spline. The Bar and Step entries in the dropdown menu in the Chart window work nicely, the Line and Smooth entries don't seem to change anything, there are always steps.
                                I'm obviously missing something here again but what?

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

                                  I'm obviously missing something here again but what?

                                  The plot type setting applies to the old UI pages, such as /data_point_details.shtm

                                  On charts in the new UI, such as /ui/data-point-details/ , there is a selector in the top right portion of the chart to toggle between smooth, line, step, or bar styles.

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Holzatelier
                                    last edited by

                                    Phil, I' ll try to upload some screenshots. Whatever I choose in the selector in the top right portion of the chart the outcome seems the same to me. Except for "Bar", then the area below the graph is filled in solid:

                                    3_1535714143001_Mango_chart_bar.png 2_1535714143001_Mango_chart_line.png 1_1535714143001_Mango_Chart_smooth.png 0_1535714143001_Mango_chart_step.png

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

                                      Hmm. I was not able to replicate. Can you share the JSON for the point you're seeing that with? Are there any errors in the browser developer console?

                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Holzatelier
                                        last edited by Holzatelier

                                        Hi, I've got myself a litte confused with this one. I only just realized how to zoom into the chart and it turns out that the steps I'm seeing are actually a result of the data aquisition. Although I poll the devices every minute the data sources do not seem to update the data that fast. So I might get back constant values for several minutes and then record a change from one poll to the next.
                                        So then of course the spline is only 1 minute segment long and does not seem to be there at all when I'm looking at the whole chart.
                                        Sorry about that, don't know where my brain was...

                                        Nevertheless another question came up (of course). Please see next Post.

                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Holzatelier
                                          last edited by Holzatelier

                                          I've been playing around with the dashboard designer and I can't delete any pages.
                                          I'm admin and I think I've got all the permissions:
                                          0_1535812809428_admin settings.png
                                          Then I try to delete this page called "Testpage" by clicking on the trashcan symbol but nothing happens.

                                          0_1535812754166_dasdesignerpermission.png

                                          I try the same thing in "edit pages". The page is empty but I can't delete it.

                                          0_1535812918446_editpagesdelete.png

                                          But I noticed this error in the Browser console:

                                          0_1535813209364_BrowserConsole error.png

                                          So I checked Mango on my Windows installation and the exact same thing happens there.
                                          This is the java version I'm running:
                                          0_1535813691032_java version.png

                                          I hate to pepper you with questions, but I'm still hoping I just overlooked something really obvious.

                                          Thanks for your patience.

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

                                            Hi Holzatelier,

                                            You should see a confirm dialogue. What browser are you using? I was not able to reproduce in Chrome on the latest.

                                            I hate to pepper you with questions, but I'm still hoping I just overlooked something really obvious.

                                            No worries. But, this particular thread has strayed quite far from its topic. Don't hesitate to make more topics, it is ultimately a better question-answer or discussion style than threads twisting to new topics.

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