• 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.1k
    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

      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
                                • V
                                  v8dave
                                  last edited by

                                  With .get(0) I get this error.

                                  ERROR 2016-07-29 08:13:13,576 (com.serotonin.m2m2.meta.JavaScriptPointLocatorRT.executeImpl:54) - sun.org.mozilla.javascript.EcmaError: TypeError: Cannot find function get in object {minimumValue: 99.05402923333332, minimumTime: 1469804893540, maximumValue: 99.568, maximumTime: 1469805193538, average: 99.15065249671122, sum: 397.38296884523055, count: 4, delta: 0.5139707666666737, integral: 29745.195749013365, firstValue: 99.05402923333332, firstTime: 1469805036550, lastValue: 99.568, lastTime: 1469805193538, periodStartTime: 1469804893540, periodEndTime: 1469805193540}. (<Unknown Source>#9) in <Unknown Source> at line number 9 in <Unknown Source> at line number 9 
                                  javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: TypeError: Cannot find function get in object {minimumValue: 99.05402923333332, minimumTime: 1469804893540, maximumValue: 99.568, maximumTime: 1469805193538, average: 99.15065249671122, sum: 397.38296884523055, count: 4, delta: 0.5139707666666737, integral: 29745.195749013365, firstValue: 99.05402923333332, firstTime: 1469805036550, lastValue: 99.568, lastTime: 1469805193538, periodStartTime: 1469804893540, periodEndTime: 1469805193540}. (<Unknown Source>#9) in <Unknown Source> at line number 9 in <Unknown Source> at line number 9
                                  
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • terrypackerT
                                    terrypacker
                                    last edited by

                                    Dave,

                                    That last post shows that you are using the statistics method to get the data. I'll just ignore that and focus on the first problems you were having. You are expecting the method:

                                    bbl1.pointValuesSince()
                                    

                                    to return an Array, but it actually returns a Java style ArrayList. The difference is that ArrayLists have a method called size() instead of the member length and accessing the values is done via get(index).

                                    So here is an updated version of your script to run using an array list instead of an array:

                                    var data = bbl1.pointValuesSince(new Date().getTime() - 5*60*1000); //Five minutes in milliseconds
                                    if( data.size() <= 1 ) //we have the same edge conditions for our range
                                       return false;
                                    var firstValue = data.get(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.size(); k+=1 ) {
                                      if( firstValue.value - data.get(k).value < changeThreshhold)
                                        return true;
                                    }
                                    return false;
                                    

                                    Hope this helps.

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

                                      Thanks Terry!

                                      Terry's code will work on Java 7 and 8. I guess I've mostly been interacting with Java 8... mine only works on Java 8's JavaScript engine. So, you can convert .length to .size() as per Terry's suggestion and use get() instead of square brackets []. I will try to be more conscious of this in the future when contributing example code snippets.

                                      Sorry for the confusion!

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

                                        No worries Phil, without this interaction you would not have known this so in the end we both benefit from the exchange of data.

                                        I am slowly learning Mango and it's pretty impressive what you can do with it. Your only downside of the whole system is the lack of really good documentation on things like the scripting etc. Other than this, with the support on the forum it makes up for this until such time as you have the documentation done.

                                        Thanks Terry, That seems to work this time. There are no errors appearing in the log file now. I just need to wait for the sensor to change and then hopefully I can detect the change.

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

                                          Very true. The community definitely makes me take a closer look at many things, which I enjoy.

                                          Virtual points can be useful to check if your meta point is behaving as you expect.

                                          The blue help icon (?) in sections with scripts has a 'related item' called 'Mango JavaScript' that documents the functions a data point has. Examples are definitely spread around the forum as well. There's a whole section called 'Scripting general discussion'

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