Rules and GPIO16

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Rules and GPIO16

#1 Post by mra2ko » 25 Oct 2022, 22:37

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

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Rules and GPIO16

#2 Post by ThomasB » 25 Oct 2022, 23:08

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

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules and GPIO16

#3 Post by TD-er » 25 Oct 2022, 23:40

Ah, someone has been following development recently :)

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Rules and GPIO16

#4 Post by ThomasB » 25 Oct 2022, 23:53

Yes, I noticed the new functionality. It's the ideal solution to the OP's application.

- Thomas

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules and GPIO16

#5 Post by TD-er » 26 Oct 2022, 00:33

Yep, it is for sure the most clean solution.

mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Re: Rules and GPIO16

#6 Post by mra2ko » 26 Oct 2022, 08:20

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!

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules and GPIO16

#7 Post by TD-er » 26 Oct 2022, 08:59

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

mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Re: Rules and GPIO16

#8 Post by mra2ko » 26 Oct 2022, 13:45

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

User avatar
ThomasB
Normal user
Posts: 1065
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Rules and GPIO16

#9 Post by ThomasB » 26 Oct 2022, 19:35

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

mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Re: Rules and GPIO16

#10 Post by mra2ko » 28 Oct 2022, 12:10

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

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules and GPIO16

#11 Post by TD-er » 28 Oct 2022, 12:32

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.

mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Re: Rules and GPIO16

#12 Post by mra2ko » 28 Oct 2022, 18:59

You mean:

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

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules and GPIO16

#13 Post by TD-er » 29 Oct 2022, 00:32

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

mra2ko
Normal user
Posts: 80
Joined: 06 Dec 2021, 08:32
Location: Czech Republic

Re: Rules and GPIO16

#14 Post by mra2ko » 29 Oct 2022, 20:06

Oki, thank !
I test it...

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests