Page 1 of 1

Rules and GPIO16

Posted: 25 Oct 2022, 22:37
by mra2ko
Hi,
I would like use GPIO16 for reset any device.
I need enable this pin every 10minutes but for 2second.

Please, what will the program look like?

Thank

Re: Rules and GPIO16

Posted: 25 Oct 2022, 23:08
by ThomasB
Must use a Mega release dated after Oct-15-2022. Setup GPIO16 as an output in the web interface. Enter the following text into the rule page and save. Then reboot.

Code: Select all

on System#Boot do
   LongPulse,16,1,2,600,-1
endon
Important: GPIO16 is a reserved boot pin, must be allowed to float HIGH on reset/boot. I recommend using a different pin.

Code is untested, may require tweaks.

- Thomas

Re: Rules and GPIO16

Posted: 25 Oct 2022, 23:40
by TD-er
Ah, someone has been following development recently :)

Re: Rules and GPIO16

Posted: 25 Oct 2022, 23:53
by ThomasB
Yes, I noticed the new functionality. It's the ideal solution to the OP's application.

- Thomas

Re: Rules and GPIO16

Posted: 26 Oct 2022, 00:33
by TD-er
Yep, it is for sure the most clean solution.

Re: Rules and GPIO16

Posted: 26 Oct 2022, 08:20
by mra2ko
Hi all,
Yes, I know, is not ideal solution, but I have all of them GPIO used hi
The formula work just after reboot, miss any "loop"

I am not able find info about "longpulse" 16 is GPIO/ 1 is ? / 2 is ? / 600 is time / -1 is ?

Thank!

Re: Rules and GPIO16

Posted: 26 Oct 2022, 08:59
by TD-er
See the documentation: https://espeasy.readthedocs.io/en/lates ... e#commands
It has been added last week, so you need a build from GitHub Actions to make this work with the "-1" parameter. (continuous loop)

Otherwise you need a looptimer for every 10 minutes and send a longpulse for 2 seconds.
See looptimerset: https://espeasy.readthedocs.io/en/lates ... l-commands

Re: Rules and GPIO16

Posted: 26 Oct 2022, 13:45
by mra2ko
Hi,
I have latest FW ESP8266_4M1M Oct 15 2022 but formula still no working, also tested looptimer.
Dont see any exaples for my use, I am not a progammer, thats why I have such problems with it. Can you share exactly formula for this ?
Thank

Re: Rules and GPIO16

Posted: 26 Oct 2022, 19:35
by ThomasB
I have latest FW ESP8266_4M1M Oct 15 2022 but formula still no working ...
At this time the official release does NOT support the repeat feature on the longpulse command, which is required for the rule text I posted. You will need to download the latest binaries from the github "actions" folder. Here is the link to the actions folder: https://github.com/letscontrolit/ESPEasy/actions

For example, these binaries were released today, so maybe the "ESPEasy_normal_ESP8266_4M1M" in it will work for you: https://github.com/letscontrolit/ESPEas ... /412454571

- Thomas

Re: Rules and GPIO16

Posted: 28 Oct 2022, 12:10
by mra2ko
Hi,
I solve this problem....

Now question it is possible for ""on Clock#Time=All,21:30:xx" use "seconds" ?
I need send reboot MCU in exactly time, but need use second? Or any idea how to send reset in exactly time?

When I use for example:
on Clock#Time=All,21:30 do
Reboot
endon

MCU reboot sometime in one minutes...

Thank

Re: Rules and GPIO16

Posted: 28 Oct 2022, 12:32
by TD-er
What you can do, is trigger the event 1 minute (or maybe even 2??) early and then set a timer based on the %syssec% variable, or the %syssec_d% variable.
Maybe the latter is even more useful as it is the nr of seconds of the current day.
By using the %syssec_d% variable, you could set the timer at any moment of the day, as you simply compute the nr of seconds different from when you need to trigger the event.
Maybe it is a good idea to set this timer whenever you get the event the system time was updated.

N.B. keep in mind the ESP may sometimes need some extra time to complete its other jobs.
So this is not a guaranteed exact time.
See the timing stats page to check if there are things taking way more time to complete on your unit.
For example reconnecting to a WiFi network may sometimes block all other execution of code for more than a second.

Re: Rules and GPIO16

Posted: 28 Oct 2022, 18:59
by mra2ko
You mean:

on %syssec_d% >= time in second from 0:00 ?
Reboot
endon

Re: Rules and GPIO16

Posted: 29 Oct 2022, 00:32
by TD-er
Nope, more like this (untested)

Code: Select all

on Clock#Time=All,21:29 Do
  // 21:30 = 21*3600+30*60 sec = 77400 sec
  Let,1,77400-%syssec_d% // Compute nr of seconds left till 21:30 and store in [int#1]
  // A single timer with seconds resolution can be done using timerset
  // For sub-second timing, see timerset_ms:
  // https://espeasy.readthedocs.io/en/latest/Rules/Rules.html?highlight=looptimerset#timer
  // Start timer #1 with the remaining nr. of seconds we stored in [int#1]
  TimerSet,1,[int#1]  
Endon

On Rules#Timer=1 Do
  // This will be started exactly on 21:30:00 
Endon

Re: Rules and GPIO16

Posted: 29 Oct 2022, 20:06
by mra2ko
Oki, thank !
I test it...