WAIT command explained


#1

Does anyone know the largest number (threshold) where webCoRE can wait at a command without starting over at the top of the piston after the wait.

I have read that on short Waits, webCoRE will actually pause right there, and continue after the wait is over… And on longer waits, it will actually begin at the top after the wait, so certain blocks will no longer be true.

I would really love to know what is the maximum delay in milliseconds where webCoRE will not start at the top afterwards.

Can anyone clarify for me please?


Using Wait in a timer
Stuck again --not sure why will not do while loop
#2
 //if we don't have to wait, we're home free
    if (delay) {
    	//get remaining piston time
    	def timeLeft = 20000 + rtData.timestamp - now()
        //negative delays force us to reschedule, no sleeping on this one
        boolean reschedule = (delay < 0)
        delay = reschedule ? -delay : delay
    	//we're aiming at waking up with at least 10s left
    	if (reschedule || (timeLeft - delay < 10000) || (delay >= 5000) || async) {
	        //schedule a wake up
	        if (rtData.logging > 1) trace "Requesting a wake up for ${formatLocalTime(now() + delay)} (in ${cast(rtData, delay / 1000, 'decimal')}s)", rtData
            tracePoint(rtData, "t:${task.$}", now() - t, -delay)
            requestWakeUp(rtData, statement, task, delay, task.c)
	        return false
	    } else {
	        if (rtData.logging > 1) trace "Waiting for ${delay}ms", rtData
	        pause(delay)
	    }
	}
	tracePoint(rtData, "t:${task.$}", now() - t, delay)
    return true

It depends on a few factors in this line.

if (reschedule || (timeLeft - delay < 10000) || (delay >= 5000) || async)

  1. Waits greater than or equal to 5 seconds cause a wakeup(delay >= 5000)
  2. Async Statements (async) will always request a wakeup

timeleft - delay < 10000

  1. If I’m remembering the above correctly, the piston has 20 seconds to do whatever it needs to do. It will reschedule a wakeup if the delay requested will prevent it from having 10 seconds left to do whatever it needs to do after.

So if the piston had been executing for 7 seconds up to this point. It would have 13 left to do the rest of the items (20 - 7 = 13 = timeleft). If you request a wait time for 3 seconds it would put your right at the 10 second mark which pause without requesting a wakeup (13 - 3 = 10 >= 10 ). Waiting for 4 seconds however would put the time left after the pause at 9 seconds which is passed the threshold causing a wakeup.

reschedule
  1. Not too sure about this one. It’s if the delay is negative and it will take the absolute value instead but I haven’t debugged to see where the delay can be negative.

I’m more surprised though that it’s re-evaluating conditions for you. From what I’ve seen in the code it’s supposed to fast forward to the block you came from and not check the conditions again but that’s only for code it’s already run though. Are the conditions you noticed changing after the wait command? Would it be possible to save the states you want to check in variables before the wait?


#3

Wow, thank you for the informative response!! I was afraid there was not going to be an easy answer, LOL

In general, I tend to put in a few short delays (500-800 ms) scattered thru my code when I am trying to control many devices simultaneously. This helps my network traffic to not get so congested, and my devices are more reliable. I have wondered for quite some time what is the largest Wait I could safely use for general usage.

This is most commonly seen when I want to trigger something when a door contact opens, but when a wait occurs, the door is no longer opening. (it is already open)

At the moment, I am trying to help out @leicam4 in this post, but the 1500 ms wait is causing us grief. Maybe I just need a new set of eyes on that one… Otherwise, I may have to break up that piston into two separate pistons, and use global variables… (I hate to do this unless it is absolutely necessary)

I think it is the “semaphore” delays that are frustrating me there… and I am assuming the required wait is the root of the problem.


#4

I have pistons that have ‘randomly waits’ in them up to 120 minutes and these work OK.
I must admit it’s not something I have thought about as for me, they always work.
If you look at the logs it says it is setting up a schedule for between 50 and 120 minutes in the future when it reaches the ‘randomly wait’ command. I assume this means it must know where it paused, so it knows where to restart from when the schedule matures.
Here is what I’m talking about. Admittedly this is in a ‘while’ statement but I wouldn’t have thought it matters.

image