• 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

    How to setup and event on rate of change?

    Dashboard Designer & Custom AngularJS Pages
    3
    28
    14.2k
    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.
    • V
      v8dave
      last edited by

      OK. I found how to create a meta script. It's actually a data source. I'll give your code a try out. Thanks again.

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

        Data will be coming from it, won't it? :D

        A solution some people use for noisy data, to avoid what I was talking about, is to just use averages from time periods to compare instead of raw data, so,

        var period = 300000 //5*60*1000 Five minutes
        var now = new Date();
        var start = now.getTime() - period;
        var middle = now.getTime() - period/2;
        if( Math.abs( p.getStats(middle, now).average - p.getStats(start, middle).average ) > 5 ) //Threshhold
          return true;
        return false;
        

        Depending on your needs or thoughts on your data.

        1 Reply Last reply Reply Quote 0
        • V
          v8dave
          last edited by

          Just trying this now and when I input the script and then click save, I get this error at the bottom.

          invalid return
          at line -1
          

          I've selected a suitable data point and set its name to p for this test.

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

            Are you using the scripts as posted or as they arrived in an email notification?

            I am able to run all of these with a numeric point for p. That looks like a syntax error, which I think I would get regardless of the code path.

            1 Reply Last reply Reply Quote 0
            • V
              v8dave
              last edited by

              Hi Phil, I am using a numerical data point. Here is the screen capture. I modified the script as I only need to detect a falling trend.!!

              0_1469686311138_script.png

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

                it looks like you are using the scripting data source, instead of a meta data source and putting these scripting in a meta data point.

                Scripts are intended for a multiple-output control loop. Scripting data source scripts don't contain return statements, they set a point's value with p.set(value, time) or just p.set(value) for the current time.

                This kind of thing, where we're producing a single answer from perhaps multiple inputs, should be a meta point.

                1 Reply Last reply Reply Quote 0
                • V
                  v8dave
                  last edited by

                  Ah yes, so I was. Just trying it now but there is an error about a null value on line 4 which seems strange because it would not get to this line unless there was data.

                  var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
                  if( data.length <= 1 ) //we have the same edge conditions for our range
                     return false;
                  var firstValue = data[0];
                  var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than
                  for( var k = 1; k < data.length; k+=1 ) {
                    if( firstValue.value - data[k].value < changeThreshhold)
                      return true;
                  }
                  return false;
                  
                  1 Reply Last reply Reply Quote 0
                  • phildunlapP
                    phildunlap
                    last edited by

                    That is odd....
                    I would put print(data) at line 2 to investigate.

                    1 Reply Last reply Reply Quote 0
                    • V
                      v8dave
                      last edited by

                      I've added that but where do I see the output from this?

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

                        It would be below the script window, if it ran, where you saw the error. If it didn't, I wonder if you have a global script declared? The global scripts page is this icon: 0_1469746987325_script-globe.png

                        1 Reply Last reply Reply Quote 0
                        • V
                          v8dave
                          last edited by

                          I don't have that icon. Is this a module I need to install or a setting somewhere?

                          1 Reply Last reply Reply Quote 0
                          • V
                            v8dave
                            last edited by

                            I found the module and installed it and the icon is now present. My scripts still don't seem the be running as there is no output from the print(data) statement.

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

                              No, I was curious if that's where the error was occurring, not telling you that you needed to install it.

                              Do you get the same error from a very simple script, perhaps just...

                              return false;
                              

                              Are you sure your point is in the context as bbl1 (b - b - lower case L - numeral 1)?

                              1 Reply Last reply Reply Quote 0
                              • V
                                v8dave
                                last edited by

                                I am assuming that the variable is based on the area I circled?
                                0_1469800445894_Untitled.jpg

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

                                  Yeah, just checking. That script I posted surely runs for me, here's a version of yours with lots of print statements, maybe it will help find the issue?

                                  print("bbl1:");
                                  print(bbl1);
                                  var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
                                  print("data:");
                                  print(data);
                                  if( data.length <= 1 ) //we have the same edge conditions for our range
                                     return false;
                                  print("Passed the length condition...");
                                  var firstValue = data[0];
                                  var changeThreshhold = -20; //so, this would mean that if any point in the period it is more than
                                  for( var k = 1; k < data.length; k+=1 ) {
                                    if( firstValue.value - data[k].value < changeThreshhold)
                                      return true;
                                  }
                                  return false;
                                  

                                  If you see no output, I encourage you to 1) check for updates, 2) clear your browsers cache, 3) delete Mango/work/jsp and then try again.

                                  1 Reply Last reply Reply Quote 0
                                  • V
                                    v8dave
                                    last edited by

                                    Hi Phil, it doesn't seem to run. Nothing appears from the debug. I also deleted the jsp directory and still the same.

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

                                      Are you getting errors in the log, or just on the script's page? Is it still reporting null at line 4? Did you try a very simple script, just

                                      return false;
                                      

                                      And see if it reports success result=false?

                                      Well, would it be possible for you to email me the JSON for your Mango and I'll try to find the problem locally? I'd like your whole configuration.

                                      1 Reply Last reply Reply Quote 0
                                      • V
                                        v8dave
                                        last edited by

                                        Looking at the log file, it is still failing at this line.

                                        var firstValue = data[0];
                                        
                                        ERROR 2016-07-29 07:39:00,004 (com.serotonin.m2m2.meta.JavaScriptPointLocatorRT.executeImpl:54) - sun.org.mozilla.javascript.EvaluatorException: Java class "java.util.ArrayList" has no public instance field or method named "0". (<Unknown Source>#9) in <Unknown Source> at line number 9 in <Unknown Source> at line number 9
                                        

                                        I export and send you the file.

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

                                          It works fine for me, so, I wonder if it's a Java version issue.

                                          Judging from that error message, I would try using data.get(0) instead of data[0]

                                          Can you run "java -version" on the command line and report the result?

                                          1 Reply Last reply Reply Quote 0
                                          • V
                                            v8dave
                                            last edited by

                                            It's running on a Centos system and the "java -version" command gives me this error.

                                            Error occurred during initialization of VM
                                            Could not reserve enough space for object heap
                                            Error: Could not create the Java Virtual Machine.
                                            Error: A fatal exception has occurred. Program will exit.
                                            

                                            I have Mango running as a service on this machine. Java is install and running otherwise Mango won't run.

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