• Recent
    • Tags
    • Popular
    • Register
    • Login
    1. Home
    2. arvand.owji
    3. Posts

    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
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 67
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by arvand.owji

    • DataPoints previous values

      Hi,
      Using JAvascript library, how can I return the previous values of a data point. I'm running the following code in my script and i get corect value when i alert the current value but im struggling to see how can i access the historical data, like the value 10 min ago in this script. Can you please guide me? I ahve already looked at the "About Mango Java Script" page but no breakthrough. Thanks.

      Util.getPointsValues({
                      done : function(){
                          chartData = [];						
                          alert(res['A1'][0].value);                    
                      },
                      scope : res,
                      from : dateRange.start,
                      to : dateRange.end,
                      points : graphPoints,
                      options : {
                          timePeriodType : 'DAYS',
                          timePeriods : 1,
                          rollup : 'AVERAGE'
                      }
                  });
      
      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @phildunlap said in Import javascript library:

      No there shouldn't be anything in the operating system getting in the way. I would advise

      1. Redirect stderr to your output file as well,
      */2 * * * * root /opt/mango/web/node-mango-client-master/CoolpropScript.sh >> /opt/mango/web/node-mango-client-master/CoolpropScript.log 2>&1
      
      1. Check dmesg output
        Edit:
      2. Add the user that's running it... how are you editing this cron?

      Thats better. It seems that Node path gets messed up when the script is executed through crontab and it was complaining about not being able to find node. I added the "/usr/local/bin/node /opt/mango/web/node-mango-client-master/RunCoolprop.js" to the script and now it executes it but further down the road complains about not finding more files, Seems all the paths are screwed up.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @phildunlap said in Import javascript library:

      DataPoint.setValue('DP_540483','2118.7704248055056')

      should be more like...

      DataPoint.setValue('DP_540483', {'value': 2118.7704248055056, 'time': new Date().getTime()});
      

      Thanks itsl working fine now on the script side. Now i have a script (named CoolpropScript.sh) that I want to schedule it to run every 2 minutes. This script runs the node js code.

      #! /bin/sh
      echo "running RunCoolprop.js"
      node /opt/mango/web/node-mango-client-master/RunCoolprop.js
      

      If I run the script manually it works fine and executes the RunCoolprop.js. But if I schedule the script to run using crontab i only see some (echo "running RunCoolprop.js") part of the script being executed and not the rest. Here is how i have it added to the crontab:

      */2 * * * * /opt/mango/web/node-mango-client-master/CoolpropScript.sh >> /opt/mango/web/node-mango-client-master/CoolpropScript.log

      Is there an auto timeout associated to the crontabs in the mango linux distribution? It seems the scripts timeout after few seconds...

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      this is what i am calling

      DataPoint.setValue('DP_540483','2118.7704248055056');

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @phildunlap said in Import javascript library:

      Mango is not running on port 8443?

      mmm, where can i check it?

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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?

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

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

      posted in Scripting general Discussion
      A
      arvand.owji
    • RE: Import javascript library

      @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.

      posted in Scripting general Discussion
      A
      arvand.owji