syntax question

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

syntax question

#1 Post by Sasch600xt » 06 Jun 2020, 15:39

Hello all :)

i have an 3 way switch and try to do something like this, but it wont work :(
sure the problem is me :)

if the switch is in position "up" i want to switch MCPGPIO,1,1 (works already)

if the switch is in middle position i want MCPGPIO,1,0 (does not work)

if the switch is in position "down" i want MCGPIO,1,StateOfmcp#29 (does not work)

Code: Select all

on mcp#18=1 do    // Switch position "up"
MCPGPIO,1,1
endon

on mcp#18=0 do    // Switch position "middle"
  if mcp#17=0	  // to make sure Switch is not in position "down"
    MCPGPIO,1,0
  endif
endon

on mcp#17=1 do    // Switch is in Position "down"
  if mcp#29=1 do
    MCPGPIO,1,1
    else
    MCPGPIO,1,0
  endif
would be great to get some help here :)
Thank you very much !!

Have a great day
"the flat earth society has members all around the globe"

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

Re: syntax question

#2 Post by grovkillen » 06 Jun 2020, 15:53

Do you have monitor activated for them?
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:

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#3 Post by Sasch600xt » 06 Jun 2020, 16:06

yes, monitor is activated for all MCP inputs.
"the flat earth society has members all around the globe"

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

Re: syntax question

#4 Post by TD-er » 06 Jun 2020, 17:06

Just a simple question.
Are you sure this is ever entered?

Code: Select all

on mcp#18=0 do    // Switch position "middle"
Maybe add a logentry statement in that block, to make sure it is detected as being 'low'.

Also I'm missing a "do" here:

Code: Select all

  if mcp#17=0	  // to make sure Switch is not in position "down"
and an "endon" for this block:

Code: Select all

on mcp#17=1 do    // Switch is in Position "down"

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#5 Post by Sasch600xt » 06 Jun 2020, 17:41

thank you :)

i changed it to:

Code: Select all

on mcp#18=1 do
MCPGPIO,1,1
endon



on mcp#18=0 do
  if mcp#17=0 do
    MCPGPIO,1,0
  endif
endon



on mcp#17=1 do
  if mcp#29=1 do
    MCPGPIO,1,1
    else
    MCPGPIO,1,0
  endif
endon
"Maybe add a logentry statement in that block, to make sure it is detected as being 'low'."
Could you show me exactley what it means ? How could it look like ?
And you are right, at the moment it looks like it does not detect "low"

This one here:

Code: Select all

on mcp#17=1 do
  if mcp#29=1 do
    MCPGPIO,1,1
    else
    MCPGPIO,1,0
  endif
endon
is not working, mcp#17 is high and mcp#29 is high, but MCPGPIO,1 is low.

will the trigger work only in the first run, or will this be triggered as long i have mcp#17 high in every loop ?

Thank you for your help
"the flat earth society has members all around the globe"

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

Re: syntax question

#6 Post by Ath » 06 Jun 2020, 19:30

You need to add [ and ] around the variable(s) in the 'if' lines, (but not in the 'on' lines).

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#7 Post by Sasch600xt » 06 Jun 2020, 20:18

ok, thank you

i have it now like this:

Code: Select all

on mcp#18=1 do
MCPGPIO,1,1
endon



on mcp#18=0 do
  if [mcp#17]=0 do
    MCPGPIO,1,0
  endif
endon



on mcp#17=1 do
  if [mcp#29]=1 do
    MCPGPIO,1,1
    else
    MCPGPIO,1,0
  endif
endon
but still only the first block is working.

second block does not switch MCPGPIO "low"

and third block does MCPGPIO,1 "low" even when mcp#29 is "high"

still my question would be:

for example in the third block, let´s say MCP#17=1 but mcp#29 is low.
will the rules check on every loop for mcp#29 for "high" or "low" or just once when mcp#17 is "high" the first time and then never again untill mcp#17 is "low" and "high" after.

Thank you all so much for help :)
"the flat earth society has members all around the globe"

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

Re: syntax question

#8 Post by Ath » 06 Jun 2020, 20:25

Hm, the if doesn't have a do, it's just the if and a condition/test, you might want to read the documentation on that again: https://espeasy.readthedocs.io/en/lates ... Rules.html

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

Re: syntax question

#9 Post by TD-er » 06 Jun 2020, 20:28

Maybe something like this:

Code: Select all

on mcp#18 do
  LogEntry,"MCP 18: [mcp#18], MCP 17: [mcp#17]"
  if [mcp#18]=0 
    if [mcp#17]=0 
      MCPGPIO,1,0
    endif
  else
    MCPGPIO,1,1
  endif
endon

on mcp#17=1 do
  if [mcp#29]=1   // Is this correct, to compare with mcp#29 ????
    MCPGPIO,1,1
  else
    MCPGPIO,1,0
  endif
endon
Edit:
As mentioned the if doesn't have "do".
I was mistaken by the fact there was one line in the given example that had an if ... do.
And usually some omission is more likely than something extra.
And I always ask GrovKillen for rules, as those are also not my cup of tea :)

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#10 Post by Sasch600xt » 06 Jun 2020, 20:53

thank you for helping :)

i did try TDer´s code but this was also no luck.

Maybe i try to explain what i want to do with the code:

the ESP is in my Car.
I try to control my extended rear lights.

i have a switch with 3 Positions:

Pos "up" = mcp#18 HIGH
Pos "middle" = mcp#18 AND mcp#17 LOW
Pos "down" = mcp#17 HIGH

Relay for Rearlight is MCPGPIO#1

Input for reverse gear is mcp#29 (HIGH = reverse gear selected)

So the 3 Positions of the switch should provide this features:

Position "up" = rearlights ON
Position "middle" = rearlights OFF
Position "down" = rearlights only ON if reverse gear is selected, else OFF (automode, here the rules should check always about i have reverse gear IN or not)

Thank you so much :)
Last edited by Sasch600xt on 06 Jun 2020, 23:39, edited 1 time in total.
"the flat earth society has members all around the globe"

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

Re: syntax question

#11 Post by TD-er » 06 Jun 2020, 22:18

Maybe you should leave that last part out first.
So only trigger on the mcp#18 and not the 17.

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#12 Post by Sasch600xt » 06 Jun 2020, 23:34

ok, this i did for now:

Code: Select all

on mcp#18 do
  LogEntry,"MCP 18: [mcp#18], MCP 17: [mcp#17]"
  if [mcp#18]=0
    if [mcp#17]=0
      MCPGPIO,2,0
    endif
  else
    MCPGPIO,2,1
  endif
endon
i can switch it ON, but not OFF
"the flat earth society has members all around the globe"

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

Re: syntax question

#13 Post by TD-er » 06 Jun 2020, 23:52

Well maybe Grovkillen or ThomasB can have some new insight in the rules here.
I'm a bit too tired right now to think clearly.

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#14 Post by Sasch600xt » 06 Jun 2020, 23:58

same here :) i try again tomorrow.

But thanks alot for all your help already !

good night :)
"the flat earth society has members all around the globe"

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

Re: syntax question

#15 Post by TD-er » 07 Jun 2020, 00:47

Good night to you to :)

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#16 Post by Sasch600xt » 07 Jun 2020, 11:26

Good morning all :)

So maybe today we get it to work :)
I am so sorry that it turns out more complicated then i thought :(

Happy Sunday :)
"the flat earth society has members all around the globe"

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

Re: syntax question

#17 Post by TD-er » 07 Jun 2020, 12:32

I summoned the Rules Jedi master.

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

Re: syntax question

#18 Post by grovkillen » 07 Jun 2020, 12:57

The thing is that you probably have both 18 and 17 change at the same time, thus I'm not sure what state your rule is triggering. I would test this:

Code: Select all

on mcp#18 do
  Event,triggering=[MCP#18],[MCP#17],[MCP#29]
endon

on mcp#17 do
  Event,triggering=[MCP#18],[MCP#17],[MCP#29]
endon

on triggering do
  if %eventvalue1%=1
    MCPGPIO,1,1
  endif
  if %eventvalue1%=0 AND %eventvalue2%=0
    MCPGPIO,1,0
  endif
  if %eventvalue2%=1 AND %eventvalue3%=1
    MCPGPIO,1,0
  endif
  if %eventvalue2%=1 AND %eventvalue3%=0
    MCPGPIO,1,1
  endif
endon
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:

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#19 Post by Sasch600xt » 07 Jun 2020, 13:14

Thank you for your help.

with the new code nothing is working, not ON, not OFF and not depending on state of mcp#29.

monitoring is avtivated for all mcp channels.

but the code looks wonderful and exactley what i need :)
"the flat earth society has members all around the globe"

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

Re: syntax question

#20 Post by grovkillen » 07 Jun 2020, 13:29

Could you look into the log when you have this rule triggered? And add the event values to log entry just to see if they are correct.
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:

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#21 Post by Sasch600xt » 07 Jun 2020, 13:37

i hope i know how to do so :)

i found a little mistake in the code and changed it already :

Code: Select all

on mcp#18 do
  Event,triggering=[MCP#18],[MCP#17],[MCP#29]
endon

on mcp#17 do
  Event,triggering=[MCP#18],[MCP#17],[MCP#29]
endon

on triggering do
  if %eventvalue1%=1
    MCPGPIO,1,1
  endif
  if %eventvalue1%=0 AND %eventvalue2%=0
    MCPGPIO,1,0
  endif
  if %eventvalue2%=1 AND %eventvalue3%=1
    MCPGPIO,1,1 // In this case i need the relay ON
  endif
  if %eventvalue2%=1 AND %eventvalue3%=0
    MCPGPIO,1,0 // in this case i need it OFF
  endif
endon
how do i have to change the code to provide more information in the log ?
Thank you so much for your help ! :)
"the flat earth society has members all around the globe"

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#22 Post by Sasch600xt » 07 Jun 2020, 13:41

this is the log:

39423: EVENT: Clock#Time=Sun,13:39
63979: WD : Uptime 1 ConnectFailures 0 FreeMem 20552 WiFiStatus 3
74572: EVENT: MCP#18=1
74593: ACT : Event,triggering=,,
74594: Command: Event
74594: EVENT: triggering=,,
77172: EVENT: MCP#18=0
77193: ACT : Event,triggering=,,
77194: Command: Event
77194: EVENT: triggering=,,
78972: EVENT: MCP#17=1
78995: ACT : Event,triggering=,,
78996: Command: Event
78997: EVENT: triggering=,,
83974: EVENT: MCP#29=1
88174: EVENT: MCP#29=0
91972: EVENT: MCP#17=0
91995: ACT : Event,triggering=,,
91996: Command: Event
91996: EVENT: triggering=,,
93979: WD : Uptime 2 ConnectFailures 0 FreeMem 18728 WiFiStatus 3
99423: EVENT: Clock#Time=Sun,13:40
123979: WD : Uptime 2 ConnectFailures 0 FreeMem 19928 WiFiStatus 3
"the flat earth society has members all around the globe"

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

Re: syntax question

#23 Post by Ath » 07 Jun 2020, 14:04

To me it is at least 'strange' that the event is fired without any values, only the commas, do you have a screenshot of your Devices page, showing the MCP settings?

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#24 Post by Sasch600xt » 07 Jun 2020, 14:09

to be honest i do NOT have the MCPs in devicepage.

because there are 16 outputs and 16 inputs.
How can i handle that in devicepage for 12 devices ?
"the flat earth society has members all around the globe"

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#25 Post by Sasch600xt » 07 Jun 2020, 14:11

this is how my rules look like at the sysboot:

Code: Select all

on System#Boot do
monitor,mcp,1
monitor,mcp,2
monitor,mcp,3
monitor,mcp,4
monitor,mcp,5
monitor,mcp,6
monitor,mcp,7
monitor,mcp,8
monitor,mcp,9
monitor,mcp,10
monitor,mcp,11
monitor,mcp,12
monitor,mcp,13
monitor,mcp,14
monitor,mcp,15
monitor,mcp,16
monitor,mcp,17
monitor,mcp,18
monitor,mcp,19
monitor,mcp,20
monitor,mcp,21
monitor,mcp,22
monitor,mcp,23
monitor,mcp,24
monitor,mcp,25
monitor,mcp,26
monitor,mcp,27
monitor,mcp,28
monitor,mcp,29
monitor,mcp,30
monitor,mcp,31
monitor,mcp,32
endon
"the flat earth society has members all around the globe"

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

Re: syntax question

#26 Post by Ath » 07 Jun 2020, 14:28

Not sure if then the [MCP#n] variables can be used? AFAICS that's not possible, as [var#name] is referring to Device names and variables.

We could use the 16 custom variables for that, something like this:

Code: Select all

on mcp#18 do
  let 1,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%
endon

on mcp#17 do
  let 2,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%
endon

on mcp#29 do
  let 3,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%  // trigger needed on mcp 29 too?
endon

on triggering do
  if %eventvalue1%=1
    MCPGPIO,1,1
  endif
  if %eventvalue1%=0 AND %eventvalue2%=0
    MCPGPIO,1,0
  endif
  if %eventvalue2%=1 AND %eventvalue3%=1
    MCPGPIO,1,1 // In this case i need the relay ON
  endif
  if %eventvalue2%=1 AND %eventvalue3%=0
    MCPGPIO,1,0 // in this case i need it OFF
  endif
endon
When in need of more than 12 Devices, grab an ESP32, that can have up to 32 Devices ;)

Edit: You may need to initialize the variables at boot.

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

Re: syntax question

#27 Post by grovkillen » 07 Jun 2020, 14:32

Yep, since you're not using device/task those square brackets are referring to something that isn't existing. Ath's approach is the one to go.
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:

User avatar
Sasch600xt
Normal user
Posts: 134
Joined: 10 Sep 2018, 16:37

Re: syntax question

#28 Post by Sasch600xt » 07 Jun 2020, 14:52

YAY !!!

It works PERFECT with the internal sys variables !

@grovkillen:
Thank you so much for your patience and great code

@Ath:
also thanks for your patience and help.
you where right, mcp#29 had also to be reconized. (this is when i put the reverse gear in)
I LOVE the ESP32 :) But i made a lot of PCBs for the ESP8266 :(
So if i have time (hahahahahaha) i have to redesign my PCBs for the ESP32 and order some in china.

So for all, who run into the same problem, here is the finally working code:

Code: Select all

on System#Boot do
monitor,mcp,17
monitor,mcp,18
monitor,mcp,29
endon


on mcp#18 do
  let 1,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%
endon

on mcp#17 do
  let 2,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%
endon

on mcp#29 do
  let 3,%eventvalue%
  Event,triggering=%v1%,%v2%,%v3%
endon

on triggering do
  if %eventvalue1%=1
    MCPGPIO,1,1
  endif
  if %eventvalue1%=0 AND %eventvalue2%=0
    MCPGPIO,1,0
  endif
  if %eventvalue2%=1 AND %eventvalue3%=1
    MCPGPIO,1,1
  endif
  if %eventvalue2%=1 AND %eventvalue3%=0
    MCPGPIO,1,0
  endif
endon
Thank you all for your help and i wish you a great Sunday :)
"the flat earth society has members all around the globe"

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests