Can't get On WIFI#Connected to work

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Can't get On WIFI#Connected to work

#1 Post by dynamicdave » 03 Apr 2019, 10:41

I'm using mega-20190315 and can't get...

On WIFI#Connected do

in a rule-set to work.

Does anyone know if this command works?

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

Re: Can't get On WIFI#Connected to work

#2 Post by grovkillen » 03 Apr 2019, 11:45

Please show me the rule you're using.
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
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Re: Can't get On WIFI#Connected to work

#3 Post by dynamicdave » 03 Apr 2019, 15:05

Iv'e made it as simple as I can to test it out.

On WIFI#Connected do
publish node80/report,hello
endon

User avatar
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Re: Can't get On WIFI#Connected to work

#4 Post by dynamicdave » 03 Apr 2019, 15:09

What I'm trying to do is detect which WiFi network a Wemos D1 Mini connects to.
Then set a Gateway IP address accordingly.

One of my students has a gateway at his home of 192.168.1.254, while at our IoT Club it's 192.168.1.1

This means each week he has to manually alter the 'settings' in the 'Config' tab (then memember to change it back before he goes home).

I suspose we could detect... on System#Boot do
then trigger a timer for 'x' seconds (which should give the Wemos enough time to connect to a WiFi network) then check the %ssid% name.

User avatar
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Re: Can't get On WIFI#Connected to work

#5 Post by dynamicdave » 03 Apr 2019, 16:34

I've created this rule, but for some reason the first IF test always evaluates to true.
What is the correct syntax for comparing a system variable to a text string ??

on System#Boot do
timerSet,1,5
endon

on Rules#Timer=1 do
If %ssid% = "iotclub" <<<<<<<<<<<<
Gateway,192.168.1.1
Publish node80/report,{"GW=":192.168.1.1}
else
Gateway,192.168.1.254
Publish node80/report,{"GW=":192.168.1.254}
endif
Publish node80/report,{"SSID=":%ssid%}
endon

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

Re: Can't get On WIFI#Connected to work

#6 Post by grovkillen » 03 Apr 2019, 17:02

Haven't read all your posts (on my phone), but wifi connect means just that - the wifi is connected. It doesn't mean your MQTT broker is connected. Use a LED and control it with the GPIO command and you'll see.
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
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Re: Can't get On WIFI#Connected to work

#7 Post by dynamicdave » 03 Apr 2019, 18:12

Thanks for you feedback.
When your have a chance - please can you look over the Rule I posted and see why the string comparison doesn't work ??

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

Re: Can't get On WIFI#Connected to work

#8 Post by grovkillen » 03 Apr 2019, 18:34

You cannot test strings (%) mathematically within the rules engine.
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
dynamicdave
Normal user
Posts: 130
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK
Contact:

Re: Can't get On WIFI#Connected to work

#9 Post by dynamicdave » 04 Apr 2019, 15:43

If anyone is interested, I've managed to get a Rule-Set working to detect which WiFi network one of my student's WeMos D1 Mini is connected to.

At home his router has a GW and DNS of 192.168.1.254, while at our IoT Club the GW and DNS is 192.168.1.1

I've flashed one of my Wemos D1s with the version of ESP Easy that includes a 'ping' device.

When the D1 boots-up it sets the GW and DNS for his home (which is the default) and starts pinging that IP address.

If I get a 'good' ping, then the ping counter is incremented otherwise it stays at ZERO.

After 60-seconds the timer times-out and the value of the ping counter is checked.

If it still ZERO then the GW and DNS settings are switched over to the school's network.

Phew - that was fun.

Hope someone finds this useful.

Code: Select all

// Routine to check which WiFi network the WeMos D1 Mini is connected to
// Default is a PlusNet network at the student's home

on System#Boot do
   Gateway,192.168.1.254   // Set GW  for student's home network
   DNS,192.168.1.254       // Set DNS for student's home network
   Let,1,0  //zero the ping counter
   timerSet,1,60
endon

on Rules#Timer=1 do
   If [VAR#1]=0            // Check for ZERO pings (looks like the student is connected to the IoT Club's router)
      Gateway,192.168.1.1  // Set GW for IoT Club's router
      DNS,192.168.1.1      // Set DNS for IoT Club's router
   endif
endon


on ping#value do
   if [ping#value]>0  //Check if 'good' ping received
      if [VAR#1] < 5
         Let,1,%v1%+1    //Increment the ping counter
      endif
   endif
endon

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

Re: Can't get On WIFI#Connected to work

#10 Post by grovkillen » 04 Apr 2019, 16:01

Just as a note. The settings will not be written to memory of no save command is made. It'll work just fine in Dave's case since the rules right away set the gateway and DNS.
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:

Post Reply

Who is online

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