Page 1 of 1

rules: delay

Posted: 08 Sep 2018, 05:17
by kenkoknz
Hi, I cant seems to get delay to work. On boot, I want the onboard blue led on a nodemcu to be on for 3 sec before doing anything, so just a simple delay or pause for 3 sec.


on System#Boot do
GPIO,0,1 // set gpio0 high
GPIO,2,0 // turn on blue led
Delay 3000
GPIO,2,1 //turn off blue led
endon

The led only flash for about half sec, not 3sec. Tested with just command gpio,2,0 and gpio,2,1 and the blue led works as expected.

Whats wrong with the code? (I am assuming that the Delay function is similar to arduino c delay function)

Re: rules: delay

Posted: 08 Sep 2018, 13:25
by papperone
I can guess the Delay suring system boot process is not working as it should...
Have you tried with a timer?

Re: rules: delay

Posted: 08 Sep 2018, 14:13
by grovkillen
Yes that is probably the case (also, what version are you using?).

Re: rules: delay

Posted: 09 Sep 2018, 21:25
by TD-er
And don't use delay in rules.
At this moment it is not doing what you think it does.
You should start another timer and on that timer make the pin go low again.

Re: rules: delay

Posted: 10 Sep 2018, 00:57
by kenkoknz
Hi, thanks for advice, after much investigation and head scratching:
1. Delay function does not work for me in rules as TD-er said (I was using mega-20180903), however I followed with interest @Grovkillen garage door project https://testoftimes.com/2017/09/29/horm ... h-esp8266/ which uses the Delay in rules so delay obviously worked before (not sure what version he used)

on System#Boot do
Publish %sysname%/status,Booted
Publish %sysname%/IP,%ip%
pcfgpio,69,0
pcfgpio,70,0
pcfgpio,71,0
pcfgpio,72,0
Delay,5000
endon


2. Re using timer
Finally got it to work with timer:

on System#Boot do
gpio,2,0
timerSet,1,10
endon

On Rules#Timer=1 do
gpio,2,1
endon

At first the code do not work, what confused me was, I has some code further down the rules that uses gpio2, I assume it started excuting the code with gpio2 while timer 1 is still set, only way it works was when i removed the code with gpio2 downstream.

Is there like a "pause" command, ie do nothing for x seconds?

Thanks,
Ken

Re: rules: delay

Posted: 10 Sep 2018, 07:46
by grovkillen
I used Dev10 back when I made that blog post. Thanks for the feedback :D

You don't need that delay command in latest releases. It was used to make the timer work but that bug was later fixed.