• 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 javascript library

    Scripting general Discussion
    scipting javascript
    3
    98
    93.9k
    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.
    • phildunlapP
      phildunlap
      last edited by phildunlap

      The detail that is missing is the regex you are trying to use to get values from this. You didn't put any data points in your export.

      I must say, I'm confused. Why would you have a data source regex'ing a script for constant content? The JavaScript and HTML (or whatever content) are not interpreted beyond the data points you create to parse it.

      A 0ms poll isn't that surprising, as it's loading a file locally. Here were my poll times reading the regex Set(.*) for group 1 (which gives me value, Point Value</title>)from that content saved as you describe,

      2017/09/28 20:53:15.311 16ms
      2017/09/28 20:53:20.311 8ms
      2017/09/28 20:53:25.311 0ms
      2017/09/28 20:53:30.311 0ms
      2017/09/28 20:53:35.311 0ms
      2017/09/28 20:53:40.311 0ms
      2017/09/28 20:53:45.311 0ms
      2017/09/28 20:53:50.311 8ms
      2017/09/28 20:53:55.311 4ms
      2017/09/28 20:54:00.311 0ms

      Because it's doing the same thing every time. It will definitely be 0ms if you don't have any data points.

      A 1 Reply Last reply Reply Quote 0
      • A
        arvand.owji @phildunlap
        last edited by

        @phildunlap I agree. What im trying to do is a bit confusing but here is my attempt for a s simple explanation...
        I have a javascript library named coolprop.js that is about 7mb in size and too big to use inside a mango script. So what i ended up to do was to create an html page that:
        Step 1: retrieves bunch of data points value by XID then
        Step 2: passes those data points value to a function provided by coolprop to do some calculation, then
        Step 3: use mango api to assign values calculated in above step to some other Data points.

        I then use the url pointed to this html file into httpretriever to simply run this html file every 2 minutes. Once html is ran, it should set the values as detailed out in the above steps. I know the html works because if i run it through my browser, it perfectly does what it suppose to but when i run it through httpretreiver, nothing happens (as if the whole URL is not even being called every 2 minutes). This script used to work before but suddenly stopped working. and unfortunately i cant really debug it. When running in the browser, i can see the output and errors written in the chrome devtool but i have no visibility to errors when using http retriever.

        1 Reply Last reply Reply Quote 0
        • A
          arvand.owji
          last edited by

          @phildunlap i hope that my explanation above made sense. Thanks.

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

            The HTTP Retriever doesn't execute or interpret the content it retrieves. You would end up in the same boat as before, where coolprop runs Java out of memory in your instance. That's what this is an effort to circumvent, right?

            I think what you're looking for is to have a node js running on a machine with sufficient memory that executes these calculations and sets the values back to Mango through the API.

            It is certainly possible, though, that you can leave this page open on the other computer in a browser (something which is executing it). You can create an automatic login for the user and just leave that page open somewhere. It's not the most robust solution, but it should work.

            A 1 Reply Last reply Reply Quote 0
            • A
              arvand.owji @phildunlap
              last edited by

              @phildunlap I understand but are you 100% certain that this wont work? Im pretty sure it was updating the values before.

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

                Are you saying when you had the page open in a browser?

                I am certain the HTTP retriever is basically treating it as text content for regex parsing, yes. It doesn't treat it as a webpage and execute its content.

                A 1 Reply Last reply Reply Quote 0
                • A
                  arvand.owji @phildunlap
                  last edited by arvand.owji

                  @phildunlap said in Import javascript library:

                  Are you saying when you had the page open in a browser?

                  I am certain the HTTP retriever is basically treating it as text content for regex parsing, yes. It doesn't treat it as a webpage and execute its content.

                  running the script through another browser is not an option. Any other ways you can think of? Thanks.

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    arvand.owji @arvand.owji
                    last edited by

                    @phildunlap how about running the url through something like phantomjs from command prompt?

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

                      I don't have experience with phantomjs but it looks like it might work. It will at least execute the JavaScript. It should be the same idea as using node, right?

                      A 2 Replies Last reply Reply Quote 0
                      • A
                        arvand.owji @phildunlap
                        last edited by arvand.owji

                        @phildunlap said in Import javascript library:

                        I don't have experience with phantomjs but it looks like it might work. It will at least execute the JavaScript. It should be the same idea as using node, right?

                        Well,i just tried phantom and it wont work as it does not have arm distribution. I will tried node.js see what happens.

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          arvand.owji @arvand.owji
                          last edited by

                          @phildunlap now with Node.js i need to convert my html file that references java script inside to full javascript!

                          1 Reply Last reply Reply Quote 0
                          • A
                            arvand.owji @phildunlap
                            last edited by

                            @phildunlap do we have any sample javascripts that cna be used in node.js that use mangoapi? like retrieving values by XID and setting values? Thanks.

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

                              Yeah you might be able to get what you're looking for from the tests we've implemented in node: https://github.com/infiniteautomation/node-mango-client

                              A 1 Reply Last reply Reply Quote 0
                              • A
                                arvand.owji @phildunlap
                                last edited by

                                @phildunlap Thanks. I get this error when i try to run the example:

                                $node example.js
                                (node:24509) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:8443

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

                                  You would have to point it at your running Mango instance and port. It's from this section of example.js:

                                  const client = new MangoClient({
                                      protocol: 'https',
                                      host: 'localhost',
                                      port: 8443,
                                      rejectUnauthorized: false
                                  });
                                  
                                  A 1 Reply Last reply Reply Quote 0
                                  • A
                                    arvand.owji @phildunlap
                                    last edited by

                                    @phildunlap said in Import javascript library:

                                    You would have to point it at your running Mango instance and port. It's from this section of example.js:

                                    const client = new MangoClient({
                                        protocol: 'https',
                                        host: 'localhost',
                                        port: 8443,
                                        rejectUnauthorized: false
                                    });
                                    

                                    Its running locally on the same box. shouldnt localhost be enough? Thanks

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

                                      No. It is using the HTTP API which is over TCP/IP and all TCP/IP connections require an address and a port. Edit: yes localhost is the host if its the same machine (usually, localhost means 127.0.0.1 usually)

                                      A 1 Reply Last reply Reply Quote 0
                                      • A
                                        arvand.owji @phildunlap
                                        last edited by

                                        @phildunlap said in Import javascript library:

                                        No. It is using the HTTP API which is over TCP/IP and all TCP/IP connections require an address and a port. Edit: yes localhost is the host if its the same machine (usually, localhost means 127.0.0.1 usually)

                                        ok, so im on the same machine and tried the local ip of the machine and still the samething.
                                        Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 192.168.1.125:8443

                                        ami i missing something?

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

                                          Mango is not running on port 8443?

                                          A 1 Reply Last reply Reply Quote 0
                                          • A
                                            arvand.owji @phildunlap
                                            last edited by

                                            @phildunlap said in Import javascript library:

                                            Mango is not running on port 8443?

                                            mmm, where can i check it?

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