push button and http cmd value/state of button

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

push button and http cmd value/state of button

#1 Post by pw444 » 04 May 2019, 19:18

Hya,

i would like to know if and if yes, how to change teh value of a state using rules.

I have one push button define device switch input, push button active low, pullup pn, gpio0, named pb01.

With the followin code,

Code: Select all

// pb01   - gpio 0 - D5
// output - gpio 2 - D3

On System#Boot do
 let,1,0 // future enhancement by VAR
endon


on pb01#value do
  if [pb01#value]=1
    GPIO,2,1
  else 
    GPIO,2,0
  endif
endon

on pb01_on do
  GPIO,2,1
endon

on pb01_off do
  GPIO,2,0
endon
,

it works. pusing button, output is on (by devices, value 1), push again, it's off (by devices, value 0).

now, by off, by devices, value 0
using web:
http://192.168.1.5/control?cmd=event,pb01_on output in on, and by devices, value does not change, remains 0.
i push the button, nothing happens, i push it a second time, and output is off, and value by devices is ok.

Is there a way to change the value inside the rule, so either by physical button or by web - http cmd, the value reflects the action, so after using http, the state / value is correct and pushing the button it works, without having to push twice?

TIA
Last edited by pw444 on 04 May 2019, 19:56, edited 1 time in total.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#2 Post by grovkillen » 04 May 2019, 19:20

For each GPIO command you should add a let command.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#3 Post by pw444 » 04 May 2019, 19:21

Thx for answering.

Just let, alone?

example, please?

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#4 Post by grovkillen » 05 May 2019, 12:37

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#5 Post by pw444 » 05 May 2019, 13:38

Thx for the answer.

By the examples, old way, a toggle switch (on off) is used. I'm using a push button.

" For LET commands let me get back to you on that if you still want it?", sure!

BR

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#6 Post by grovkillen » 05 May 2019, 13:48

It's not a physical toggle switch. It's a virtual way of toggling.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#7 Post by pw444 » 05 May 2019, 14:04

Yes, sir, it's virtual toggle. The physical button (which exists), it's a push button.

All i want to is get rid of the need of pushing physically twice after it has been virtually toggled, when the state / value does not change.

If you can be so nice and educate me with the suggested "let" i'll really appretiate it.

By the old way, if there is also a way to have the state / value changed when virtually toggled, i'll also appretiate, as i could not find in the rules docs how to set the value of pb01 (pb01#value), like value=1 or value=0.

Thx in advance.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#8 Post by grovkillen » 05 May 2019, 16:54

Did you read the discussions I linked to?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#9 Post by pw444 » 05 May 2019, 17:02

grovkillen wrote: 05 May 2019, 16:54 Did you read the discussions I linked to?
yes, i did. and using the old way, i got it. i was asking the new way, with let, as you mentioned, and also asked.

viewtopic.php?f=4&t=6030&p=32910&hilit= ... tch#p32910
viewtopic.php?f=4&t=5771&p=31040&hilit= ... tch#p31040
viewtopic.php?f=6&t=2039&p=25350&hilit= ... tch#p25350

That's the old way. For LET commands let me get back to you on that if you still want it?

but maybe i'm not that smart, in neither post i've found how to set the pb01#value (value velue # of a device) variable to 1 or 0 using rules ;-)

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#10 Post by grovkillen » 05 May 2019, 17:05

Ok good. I will get back to you on that one. I'm watching a movie with the family :)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#11 Post by pw444 » 06 May 2019, 13:02

grovkillen wrote: 05 May 2019, 17:05 Ok good. I will get back to you on that one. I'm watching a movie with the family :)
ok, thank you. look forward for the reply ;-)

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#12 Post by pw444 » 07 May 2019, 14:24

???

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: push button and http cmd value/state of button

#13 Post by grovkillen » 07 May 2019, 15:06

Code: Select all

On System#Boot Do
 Let,1,0 //on boot make sure the LED is off
 GPIO,2,1 //the LED is set to off (inverted logic)
EndOn

On Button#State Do
  Event,toggleLED
EndOn

On toggleLED Do
  If [VAR#1] = 0
   Event,turnOnLED
  Else
   Event,turnOffLED
  EndIf
EndOn

On turnOnLED Do
  Let,1,1
  GPIO,2,0  //remember that this example uses onboard LED which is using inverted logic
EndOn

On turnOffLED Do
  Let,1,0
  GPIO,2,1  //remember that this example uses onboard LED which is using inverted logic
EndOn
Now you can use these three (event) commands:
toggleLED if LED is on it will be turned off, if LED is off it will be turned on
turnOnLED if LED is on it will not change, if LED is off it will be turned on
turnOffLED if LED is on it will be turned off, if LED is off it will not change
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: push button and http cmd value/state of button

#14 Post by pw444 » 07 May 2019, 16:07

Ok, thank you.

My doubt was regarding the use of let on states.

Last sunday, i had the follwoing code:

Code: Select all

// pb01   - gpio 0 - D5
// output - gpio 2 - D3
// boots off

On System#Boot do
 let,1,0
// GPIO,2,0
endon

on pb01#value do
   gpiotoggle,2
   if [VAR#1]=0
    let,1,1 // state on
    // publish light on
   else
    let,1,0 // state off
    // publish light off
   endif
endon

on pb01_on do
  GPIO,2,0
  let,1,1
  // publish light on
endon

on pb01_off do
  GPIO,2,1
  let,1,0
  // publish light off
endon

on pb01sw do
  gpiotoggle,2  
  if [VAR#1]=0
    let,1,1 // state on
    // publish light on
   else
    let,1,0 // state off
    // publish light off
   endif   
endon
i was not understanding the let use, but your example shows it.

Thx a lot.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests