Rule with p2p networking dosn't work

Moderators: grovkillen, TD-er, Stuntteam

Post Reply
Message
Author
Lansselot
Normal user
Posts: 5
Joined: 21 Oct 2019, 16:55

Rule with p2p networking dosn't work

#1 Post by Lansselot » 27 Mar 2020, 12:09

Rule with p2p network dosn’t work
Good day everyone. I’m working on a little quiz button system with 10 buttons and a relay. Wat I want to get at:

- Rest state
- Someone smash a button
- Relay switches for one second to let hear a buzzer
- Light on the button turns on
- No input is possible
- Button 1 resets
- Rest state

This are my devices

See attachment.

The dumy “info#Snellste” while tell the rest witch one shut turn on his light.
I have the following rule working on the relay which acts as a master. This rule checks for button updates, changes the “info#Snellste” number and turns on the relay for one second. Button one brings the “info#Snellste” back to zero.

Code: Select all

On quizmister_2_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,2
  gpio,0,0
  timerSet,1,1
 endif
endon
On quizmister_3_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,3
  TaskValueSet 11,2,3
  gpio,0,0
  timerSet,1,1
 endif
endon
On quizmister_4_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,4
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_5_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,5
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_6_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,6
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_7_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,7
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_8_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,8
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_9_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,9
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_10_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,10
  gpio,0,0
  timerSet,1,1
 endif
endon


On the button site I have almost the same rule bud shorter. This did work, bud not anymore.

Code: Select all

On quizmister_10_button#State=1 do
 if[info#Snellste]=10
  gpio,0,0
 else
  gpio,0,1
 endif
endon
First question: are the variables case sensitive. Does it matter if you type

Code: Select all

if [Info#Snellste]=10
or

Code: Select all

if [info#snellste]=10
Can someone help me? I try a lot of things bud can’t get it to work.
thank you in advance,
Sander
Attachments
2020-03-27 11_36_39-Let's Control It - Plaats een nieuw onderwerp.png
2020-03-27 11_36_39-Let's Control It - Plaats een nieuw onderwerp.png (62.08 KiB) Viewed 1211 times

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

Re: Rule with p2p networking dosn't work

#2 Post by grovkillen » 27 Mar 2020, 12:46

What interval do you have for the dummy?
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:

Lansselot
Normal user
Posts: 5
Joined: 21 Oct 2019, 16:55

Re: Rule with p2p networking dosn't work

#3 Post by Lansselot » 27 Mar 2020, 15:06

1 second
It looks to me like the if statement is always false while that shouldn't be the case.

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

Re: Rule with p2p networking dosn't work

#4 Post by ThomasB » 27 Mar 2020, 16:52

It looks to me like the if statement is always false while that shouldn't be the case.

Code: Select all

On quizmister_10_button#State=1 do
 if[info#Snellste]=10
  gpio,0,0
 else
  gpio,0,1
 endif
endon
The if statement seen above has a typo. There must be a space between if and the [ bracket. Like this:

Code: Select all

 if [info#Snellste]=10
Perhaps a space was not required on older firmware (just thinking out loud, I don't know if this is true). But I just tested a similar rule on a recent release; Leaving out this space caused incorrect behavior.

- Thomas

Lansselot
Normal user
Posts: 5
Joined: 21 Oct 2019, 16:55

Re: Rule with p2p networking dosn't work

#5 Post by Lansselot » 27 Mar 2020, 18:30

Yes, I also discovered that. Bud this was a typo from me in my post. In the rule on the esp there is a space.

Something else what I tried is trying:

Code: Select all

On quizmister_10_button do
 if [quizmister_10_button#State]=1
  gpio,0,0
 else
  gpio,0,1
 endif
endon
And this works with no problem. So I would conclude that the problem would be somewhere with reading the "info#Snellste" variable. Whel I see it changing in the devices tap.

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

Re: Rule with p2p networking dosn't work

#6 Post by ThomasB » 27 Mar 2020, 19:41

So I would conclude that the problem would be somewhere with reading the "info#Snellste" variable. Whel I see it changing in the devices tap.
My best guess: I suspect that the info#Snellste value changes *after* the quizmister_10_button#State rule is triggered. For the existing logic to work the info#Snellste value would need to be updated before the rule is triggered. This race condition seems to be a "what comes first, chicken or the egg?"

FYI, I noticed that your rule examples are missing the on timer rule that clears the info#Snellste dummy value. If this value is not cleared to zero before each new game then the button event rules will not update it with a new switch value.

BTW, I believe that the rules are executed in a top down fashion, starting on rule page 1. So the winner in a tie condition will be the player with the lowest button number, which is an unfair advantage.

- Thomas

Lansselot
Normal user
Posts: 5
Joined: 21 Oct 2019, 16:55

Re: Rule with p2p networking dosn't work

#7 Post by Lansselot » 27 Mar 2020, 21:06

My best guess: I suspect that the info#Snellste value changes *after* the quizmister_10_button#State rule is triggered. For the existing logic to work the info#Snellste value would need to be updated before the rule is triggered. This race condition seems to be a "what comes first, chicken or the egg?"
This is true. bud if I press the button again it should still turn on.
FYI, I noticed that your rule examples are missing the on timer rule that clears the info#Snellste dummy value. If this value is not cleared to zero before each new game then the button event rules will not update it with a new switch value.
I do the reset by pressing button 1 with the following rule.

Code: Select all

On quizmister_1_button#State=1 do
 TaskValueSet 11,1,0
endon
And also have the following rule to turn of the relay where the buzzer is connected to.

Code: Select all

on Rules#timer=1 do
 gpio,0,1
endon
BTW, I believe that the rules are executed in a top down fashion, starting on rule page 1. So the winner in a tie condition will be the player with the lowest button number, which is an unfair advantage.
I think you are right about that. I’m thinking about using MQTT and making a python application and a nice GUI so you get the real quiz fibes. Bud I want to make it stand-alone first.


I just did a little test,
on button 10 I made the following rule:

Code: Select all

On quizmister_4_button#State=1 do
 gpio,0,0
endon

On quizmister_4_button#State=0 do
 gpio,0,1
endon
This works. so when I press button 4 the light on 10 turns on.

Bud the following should do exact the same thing. Bud doesn’t work.

Code: Select all

On quizmister_4_button#State do
if [quizmister_4_button#State]=1
 gpio,0,0
else
 gpio,0,0
endif
endon
What am I doing wrong?
Now I know that the above named rule works I have a workaround. Bud I’m still confused why the if statement doesn’t work.

One little site note:

Code: Select all

On quizmister_2_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,2
  gpio,0,0
  timerSet,1,1
 endif
endon
On quizmister_3_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,3
  TaskValueSet 11,2,3
  gpio,0,0
  timerSet,1,1
 endif
endon
On quizmister_4_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,4
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_5_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,5
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_6_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,6
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_7_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,7
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_8_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,8
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_9_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,9
  gpio,0,0
  timerSet,1,1
 endif
endon

On quizmister_10_button#State=1 do
 if [info#Snellste]=0
  TaskValueSet 11,1,10
  gpio,0,0
  timerSet,1,1
 endif
endon
This is running build "mega-20190928" and the other buttons are running the newer build "mega-20200310".

Thank you for all you’re time and thinking with me

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

Re: Rule with p2p networking dosn't work

#8 Post by ThomasB » 27 Mar 2020, 21:54

Maybe the plugin de-bounce setting used in each players' switch is too short and multiple on-off P2P messages are sent on each press. I recommend 100mS and increase if necessary.

Other than that, I don't have any other ideas/suggestions. So if you're not satisfied with your workaround then be patient for more ideas from other users.

- Thomas

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests