• 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

    For Loop

    Scripting general Discussion
    3
    4
    2.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.
    • Udara PereraU
      Udara Perera
      last edited by

      Hi all,

      Is it possible to get a simple For loop working in scripting data source on MangoES ?
      I have the following code running :

      for ( var i = 0; LineCurrent1 > 271 ; i + 1) {

      value.set(i);

      }
      The aim of the code is to increment a value when a condition is met.

      Is this something I will be able to do using scripting data sources ?

      Thank You!

      1 Reply Last reply Reply Quote 0
      • danD
        dan
        last edited by

        Here's some code that I'm using in production on one of my systems, Joel helped with the syntax originally which was handy, it has javascript type syntax layout it would seem.

        // check if in auto mode at Driveway Tank AND tank level below Absolute Low Point AND pump not running
        if((p36.value == true) && (p23.value < p52.value) && (p11.value == false)) {
        // open southern solenoid
        p28.set(true);
        // close northern solenoid
        p24.set(false);
        // close western solenoid
        p22.set(false);
        // start pump
        p11.set(true);
        }
        

        Hope this helps, cheers Dan

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

          Hi Udara,

          The scripts use Java's implementation of JavaScript, so in Java 6 and 7 this is the Rhino engine and in Java 8 it is Nashorn. Both have all the loops and basic language features.

          Your for loop may have some issues as written. For instance, it will perform 271 sets very quickly. Using our NoSQL database, you can only have one value per point per millisecond. It may work with the H2 or MySQL databases, but I don't think it's what you want.

          It sounds like you want some kind of if condition leading to a...

          p.set(p.value + 1);
          

          The Scripting data source is run on a cron, so if it's on pattern 0/1 * * * * ? the point would reflect 'total seconds in state' and if you wanted to zero it when the condition is lost you can...

          p.set(0);
          
          Udara PereraU 1 Reply Last reply Reply Quote 0
          • Udara PereraU
            Udara Perera @phildunlap
            last edited by

            @phildunlap
            Thank You very much. That helped a lot.

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