VAR use - let - VAR# - ??

Moderators: grovkillen, Stuntteam, TD-er

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

VAR use - let - VAR# - ??

#1 Post by pw444 » 24 Dec 2020, 20:54

Hya,

i'm working o the following rules, but VAR is not being read (i guess)

Code: Select all


On System#Boot do
 Monitor GPIO,4  // D2
 let,1,0
endon

on MQTT#Connected do
 event,publishstatus
endon

// loop

// B58 - gpio 14 - statusoff P3 D5
On B58 do
  pulse,14,1,500
  pulse,2,0,500
  let,1,1
endon

// B24 - gpio 12 status24 P2 D6
On B24 do
  pulse,12,1,500
  pulse,2,0,500
  let,1,1
endon 

// BOFF - gpio 13 statusoff P1 D7
On BOFF do 
  pulse,13,1,500
  pulse,2,0,500
endon

on GPIO#4=1 do
   if %v1%=1
     // Publish,%sysname%/status,Working!!
   endif
endon

on GPIO#4=0 do
   if %v1%=1  
       let,1,0
   endif 
endon
by log, the event GPIO#4=0 the var %1% is not considered...

Code: Select all

112032: WD : Uptime 19 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
1117336: HTTP: event,B58
1117388: EVENT: b58
1117400: ACT : pulse,14,1,500
1117401: Command: pulse
1117903: SW : GPIO 14 Pulsed for 500 mS
1117922: ACT : pulse,2,0,500
1117924: Command: pulse
1118426: SW : GPIO 2 Pulsed for 500 mS
1118428: ACT : let,1,1
1118429: Command: let
1118451: SW : GPIO=4 State=1 Output value=1
1118488: EVENT: VACC#status=1.00
1121477: EVENT: Clock#Time=Thu,16:47
1125876: HTTP: event,Boff
1125949: EVENT: boff
1125968: ACT : pulse,13,1,500
1125969: Command: pulse
1126471: SW : GPIO 13 Pulsed for 500 mS
1126473: ACT : pulse,2,0,500
1126474: Command: pulse
1126976: SW : GPIO 2 Pulsed for 500 mS
1126988: SW : GPIO=4 State=0 Output value=0
1126994: EVENT: VACC#status=0.00
1142032: WD : Uptime 19 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
What i want: by B24 and B58, var 1 gets 1, and by GPIO#4=0 and var 1 = 1, it gets 0.

Not find out what is wrong...

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

Re: VAR use - let - VAR# - ??

#2 Post by TD-er » 24 Dec 2020, 21:38

Just keep one entry per event.

Code: Select all

on GPIO#4 do
  if %eventvalue%=1
    if %v1%=1
     // Publish,%sysname%/status,Working!!
    endif
  else
    if %v1%=1  
       let,1,0
    endif 
  endif
endon
Also how are the events B24 and B58 being generated?
If those never are sent, the variable will not be set to 1

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

Re: VAR use - let - VAR# - ??

#3 Post by pw444 » 24 Dec 2020, 21:44

TD-er wrote: 24 Dec 2020, 21:38
[/code]

Also how are the events B24 and B58 being generated?
If those never are sent, the variable will not be set to 1
http://192.168.80.152/control?cmd=event,Boff

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

Re: VAR use - let - VAR# - ??

#4 Post by TD-er » 24 Dec 2020, 21:48

Event Boff is only setting a pulse command in your rules.
It doesn't look like it will fire the other events which will call the "let" command to set the variable.

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

Re: VAR use - let - VAR# - ??

#5 Post by pw444 » 24 Dec 2020, 21:48

TD-er wrote: 24 Dec 2020, 21:38 Just keep one entry per event.

Code: Select all

on GPIO#4 do
  if %eventvalue%=1
    if %v1%=1
     // Publish,%sysname%/status,Working!!
    endif
  else
    if %v1%=1  
       let,1,0
    endif 
  endif
endon
Also how are the events B24 and B58 being generated?
If those never are sent, the variable will not be set to 1

Code: Select all

4622032: WD : Uptime 77 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
4622539: HTTP: event,Boff
4622578: EVENT: boff
4622595: ACT : pulse,13,1,500
4622596: Command: pulse
4623098: SW : GPIO 13 Pulsed for 500 mS
4623119: ACT : pulse,2,0,500
4623122: Command: pulse
4623624: SW : GPIO 2 Pulsed for 500 mS
4634918: HTTP: event,B58
4634935: EVENT: b58 -------------------------------------------------------------- B58
4634951: ACT : pulse,14,1,500
4634952: Command: pulse
4635455: SW : GPIO 14 Pulsed for 500 mS
4635458: ACT : pulse,2,0,500
4635459: Command: pulse
4635961: SW : GPIO 2 Pulsed for 500 mS
4635979: ACT : let,1,1 ------------------------------------------------------------- LET,1,1
4635981: Command: let
4635996: SW : GPIO=4 State=1 Output value=1
4636030: EVENT: VACC#status=1.00
4645351: HTTP: event,Boff
4645395: EVENT: boff ------------------------------------------------------------- BOFF   not let,1,0
4645412: ACT : pulse,13,1,500
4645413: Command: pulse
4645915: SW : GPIO 13 Pulsed for 500 mS
4645934: ACT : pulse,2,0,500
4645936: Command: pulse
4646437: SW : GPIO 2 Pulsed for 500 mS
4646450: SW : GPIO=4 State=0 Output value=0
4646455: EVENT: VACC#status=0.00
4652032: WD : Uptime 78 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
4661477: EVENT: Clock#Time=Thu,17:46

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

Re: VAR use - let - VAR# - ??

#6 Post by pw444 » 24 Dec 2020, 21:51

TD-er wrote: 24 Dec 2020, 21:48 Event Boff is only setting a pulse command in your rules.
It doesn't look like it will fire the other events which will call the "let" command to set the variable.
if, BOFF only sends a pulse. with this pulse, relay is disarmed, and GPIO4 becomes LOW, GPIO#4=0

for events B58 and B24, GPIO4 becomes high (+3v3), so GPIO#4=1

Code: Select all

EVENT: b58 -------------------------------------------------------------- B58
4634951: ACT : pulse,14,1,500
4634952: Command: pulse
4635455: SW : GPIO 14 Pulsed for 500 mS
4635458: ACT : pulse,2,0,500
4635459: Command: pulse
4635961: SW : GPIO 2 Pulsed for 500 mS
4635979: ACT : let,1,1 ------------------------------------------------------------- LET,1,1
4635981: Command: let
4635996: SW : GPIO=4 State=1 Output value=1
4636030: EVENT: VACC#status=1.00

Code: Select all

EVENT: boff ------------------------------------------------------------- BOFF   not let,1,0
4645412: ACT : pulse,13,1,500
4645413: Command: pulse
4645915: SW : GPIO 13 Pulsed for 500 mS
4645934: ACT : pulse,2,0,500
4645936: Command: pulse
4646437: SW : GPIO 2 Pulsed for 500 mS
4646450: SW : GPIO=4 State=0 Output value=0
version in use:

Code: Select all

Binary Filename:⋄	ESP_Easy_mega_20200829_normal_ESP8266_4M1M_VCC
Build Platform:⋄	Linux-4.19.104-microsoft-standard-x86_64-with-glibc2.29
Git HEAD:⋄	mega_c625d91
Last edited by pw444 on 24 Dec 2020, 21:57, edited 1 time in total.

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

Re: VAR use - let - VAR# - ??

#7 Post by TD-er » 24 Dec 2020, 21:55

OK, so those events are called.
Still I think you should try to only have one on...do block matching the "GPIO#4" event.

And maybe also add a logentry command to make sure it is being executed.
I am not entirely sure the rules parser is handling it well to match similar events which only differ in the eventvalues.

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

Re: VAR use - let - VAR# - ??

#8 Post by pw444 » 24 Dec 2020, 22:02

TD-er wrote: 24 Dec 2020, 21:55 add a logentry command
how to add this log command, please?

thx. if you take a look at the log, all the events are being excuted as they should, no problem.

VAR is not being verified by the last blocks.

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

Re: VAR use - let - VAR# - ??

#9 Post by TD-er » 24 Dec 2020, 22:14

See: https://espeasy.readthedocs.io/en/lates ... nds-listed

So it is something as simple as calling

Code: Select all

logentry,"Yep, we made it"
Don't forget to use quotes on the parameter if you're using a space or a comma in it.

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

Re: VAR use - let - VAR# - ??

#10 Post by TD-er » 24 Dec 2020, 22:24

I'm looking at the rules and you're sending a pulse (not a longpulse) which is blocking.
So if the result of this pulse should result in a new event, using blocking calls may make this less reliable.

Also maybe you want to set the variable before calling the pulse command.
Although preferably use the longpulse command, as it is non blocking.
The drawback is that the call to longpulse will return immediately so it will not allow for sequential actions if you call it twice in the same event handler.
If you need to have the pulse (longpulse) commands sequential, you should set a timer to trigger the next event.

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

Re: VAR use - let - VAR# - ??

#11 Post by pw444 » 24 Dec 2020, 22:27

Code: Select all

on GPIO#4 do
  logentry,"Yep, we made it"
  if %eventvalue%=1
    if %v1%=1
     // Publish,%sysname%/status,Working!!
       logentry,"Yep, we made it 2"
    endif
  else
    if %v1%=1  
       let,1,0
    endif 
  endif
endon
it does not excutes what's inside the on GPIO#4 do block, but the log shows that the condition "SW : GPIO=4 State=1 Output value=1".

Code: Select all

4622032: WD : Uptime 77 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
4622539: HTTP: event,Boff
4622578: EVENT: boff
4622595: ACT : pulse,13,1,500
4622596: Command: pulse
4623098: SW : GPIO 13 Pulsed for 500 mS
4623119: ACT : pulse,2,0,500
4623122: Command: pulse
4623624: SW : GPIO 2 Pulsed for 500 mS
4634918: HTTP: event,B58
4634935: EVENT: b58 -------------------------------------------------------------- B58
4634951: ACT : pulse,14,1,500
4634952: Command: pulse
4635455: SW : GPIO 14 Pulsed for 500 mS
4635458: ACT : pulse,2,0,500
4635459: Command: pulse
4635961: SW : GPIO 2 Pulsed for 500 mSVACC#status
4635979: ACT : let,1,1 ------------------------------------------------------------- LET,1,1
4635981: Command: let
4635996: SW : GPIO=4 State=1 Output value=1
4636030: EVENT: VACC#status=1.00
4645351: HTTP: event,Boff
4645395: EVENT: boff ------------------------------------------------------------- BOFF   not let,1,0
4645412: ACT : pulse,13,1,500
4645413: Command: pulse
4645915: SW : GPIO 13 Pulsed for 500 mS
4645934: ACT : pulse,2,0,500
4645936: Command: pulse
4646437: SW : GPIO 2 Pulsed for 500 mS
4646450: SW : GPIO=4 State=0 Output value=0
4646455: EVENT: VACC#status=0.00
4652032: WD : Uptime 78 ConnectFailures 0 FreeMem 23936 WiFiStatus WL_CONNECTED
4661477: EVENT: Clock#Time=Thu,17:46
I'm really not finding out what i'm doing wrong :-(

User avatar
Ath
Normal user
Posts: 3515
Joined: 10 Jun 2018, 12:06
Location: NL

Re: VAR use - let - VAR# - ??

#12 Post by Ath » 24 Dec 2020, 22:34

Have you updated the Boff event to have let,1,0 ? It's not there in you original post...
/Ton (PayPal.me)

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

Re: VAR use - let - VAR# - ??

#13 Post by pw444 » 24 Dec 2020, 22:48

Have you updated the Boff event to have let,1,0 ? It's not there in you original post...
No, because it shall only be done when finished, otherwise it will start publishing the finish message.

My logic:
- device boots - idle - VACC is low.
- B58 or B24, starts working - VACC becomes high
- BOFF cancel the working, VACC becomes low, but was cancelled, did not finnish the job.
By work finnish, VACC becomes low, and notification shall be sent, only when work finnished normally.

That's why BOFF does not reset the var#1

I really don't understand why on GPIO#4=0 do didn't work

Code: Select all


On System#Boot do
 Monitor GPIO,4  // D2
 let,1,0
endon

on MQTT#Connected do
 event,publishstatus
endon

// loop

// B58 - gpio 14 - statusoff P3 D5
On B58 do
  pulse,14,1,500
  pulse,2,0,500
  let,1,1
endon

// B24 - gpio 12 status24 P2 D6
On B24 do
  pulse,12,1,500
  pulse,2,0,500
  let,1,1
endon 

// BOFF - gpio 13 statusoff P1 D7
On BOFF do 
  pulse,13,1,500
  pulse,2,0,500
endon


on VACC#status do
  if %eventvalue%=1  // status = 1
    if %v1%=1             // status = 1 var1 = 1
       logentry,"Working"
    endif
  else                       // status = 0
    if %v1%=1             // status = 0 var1 =1
       let,1,0
       logentry,"Finished"
    endif 
  endif
endon
After changing GPIO#4 by VACC#status it finnaly worked.

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

Re: VAR use - let - VAR# - ??

#14 Post by pw444 » 26 Dec 2020, 14:39

TD-er wrote: 24 Dec 2020, 21:55 OK, so those events are called.
Still I think you should try to only have one on...do block matching the "GPIO#4" event.

And maybe also add a logentry command to make sure it is being executed.
I am not entirely sure the rules parser is handling it well to match similar events which only differ in the eventvalues.
May i ask why on GPIO#4=0 did not work, as it was being monitored by Monitor GPIO,4 on boot?

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

Re: VAR use - let - VAR# - ??

#15 Post by TD-er » 26 Dec 2020, 23:28

pw444 wrote: 26 Dec 2020, 14:39
TD-er wrote: 24 Dec 2020, 21:55 OK, so those events are called.
Still I think you should try to only have one on...do block matching the "GPIO#4" event.

And maybe also add a logentry command to make sure it is being executed.
I am not entirely sure the rules parser is handling it well to match similar events which only differ in the eventvalues.
May i ask why on GPIO#4=0 did not work, as it was being monitored by Monitor GPIO,4 on boot?
I honestly have no idea as it should work.
Only thing I mentioned was to try not to use the "=0" part in the event trigger and just check the value inside the event handler block.
But it seems like your "on GPIO#4" is also not working and I have no idea why it doesn't.

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

Re: VAR use - let - VAR# - ??

#16 Post by pw444 » 27 Dec 2020, 15:49

May i ask why on GPIO#4=0 did not work, as it was being monitored by Monitor GPIO,4 on boot?
[/quote]
I honestly have no idea as it should work.
Only thing I mentioned was to try not to use the "=0" part in the event trigger and just check the value inside the event handler block.
But it seems like your "on GPIO#4" is also not working and I have no idea why it doesn't.
[/quote]


ok, but i used it from examples and docs, as found in https://espeasy.readthedocs.io/en/lates ... %5BGPIO%23 where can be found:

GPIO#N If the command ‘Monitor’ is used to monitor a given pin you will receive an event for that GPIO as soon as it’s state changes. As seen in the example you can always use the square brackets together with the task/value name of Plugin#GPIO#Pinstate#N to get the state, but to trigger events you need to add the monitor command (preferably at boot).

Code: Select all

on System#Boot do
 Monitor GPIO,15
endon

 on GPIO#15=0 do
  if [Plugin#GPIO#Pinstate#13]=0
   // do something
  endif
 endon

 on GPIO#15=1 do
  if [Plugin#GPIO#Pinstate#13]=1
   // do something
  endif
 endon

Post Reply

Who is online

Users browsing this forum: No registered users and 62 guests