• 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
    72.6k
    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.
    • 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
                          • phildunlapP
                            phildunlap
                            last edited by

                            It's the web.port property in your Mango/overrides/properties/env.properties file or Mango/classes/env.properties files as "web.port". Judging from your earlier port of the HTTP Retriever data source, it's 85, but i have no way of knowing. It's 8080 by default.

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

                              @phildunlap said in Import javascript library:

                              It's the web.port property in your Mango/overrides/properties/env.properties file or Mango/classes/env.properties files as "web.port". Judging from your earlier port of the HTTP Retriever data source, it's 85, but i have no way of knowing. It's 8080 by default.

                              ok, web.port=8080 but i still get the same error as before.

                              $node example.js
                              (node:7075) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 192.168.1.125:8080

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

                                Mango is probably not running. Connection refused means the port isn't open.

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

                                  @phildunlap said in Import javascript library:

                                  Mango is probably not running. Connection refused means the port isn't open.

                                  I know it does as i can login into the web admin panel.

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

                                    Is https://192.168.1.125:8080 typed into your address bar?

                                    Edit: In the end HTTP localhost 80 prevailed

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

                                      @phildunlap said in Import javascript library:

                                      Is https://192.168.1.125:8080 typed into your address bar?

                                      Edit: In the end HTTP localhost 80 prevailed

                                      ok, i managed to get it working on port 80 and also changing https to http.
                                      Now i see only getValue function in datapoints.js. Is there any sort of setValue function available? Thanks.

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

                                        No you would have to add it, something like,

                                                static setValue(xid, valueTime) {
                                                    return client.restRequest({
                                                        method: 'PUT',
                                                        path: '/rest/v1/point-values/' + encodeURIComponent(xid),
                                                        data: {
                                                          "dataType": "NUMERIC",
                                                          "value": valueTime.value,
                                                          "timestamp": valueTime.time,
                                                          "annotation": "annotation" in valueTime ? valueTime.annotation : null
                                                        }
                                                    }).then(response => {
                                                        return response.data;
                                                    });
                                                }
                                        
                                                setValue(valueTime) {
                                                    return this.constructor.setValue(this.xid, valueTime);
                                                }
                                        

                                        Which should work for numeric points. You would have to do something more clever to make this fully general purpose as currently the DataPoint object doesn't know its data type.

                                        The node library is definitely not a finished product and anything you create is certainly encouraged to be shared.

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

                                          Also be sure to check out test/pointValue.spec.js

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

                                            @phildunlap said in Import javascript library:

                                            No you would have to add it, something like,

                                                    static setValue(xid, valueTime) {
                                                        return client.restRequest({
                                                            method: 'PUT',
                                                            path: '/rest/v1/point-values/' + encodeURIComponent(xid),
                                                            data: {
                                                              "dataType": "NUMERIC",
                                                              "value": valueTime.value,
                                                              "timestamp": valueTime.time,
                                                              "annotation": "annotation" in valueTime ? valueTime.annotation : null
                                                            }
                                                        }).then(response => {
                                                            return response.data;
                                                        });
                                                    }
                                            
                                                    setValue(valueTime) {
                                                        return this.constructor.setValue(this.xid, valueTime);
                                                    }
                                            

                                            Which should work for numeric points. You would have to do something more clever to make this fully general purpose as currently the DataPoint object doesn't know its data type.

                                            The node library is definitely not a finished product and anything you create is certainly encouraged to be shared.

                                            it complains about TypeError: Cannot use 'in' operator to search for 'annotation' in 2118.7704248055056

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