-
• #2
I'd suggest to place the code for "wifi.on('disconnected',..." into the "wifi.on('connected'," function. I didn't try this, but as the disconnect function gets registered after every connect it should work.
-
• #3
Mon 2020.01.20
@Gordon just posted the very solution needed here within a separate thread post just this morning.
@Homoludens a full explanation is there also. I'd read the entire thread. . . .
Hello everybody.
Faced the problem of reconnecting to the WiFi network through the wifi.on (‘connected’) event.
Program code:
When you first start wifi.on (‘connected’), it works:
{
"ip": "192.168.0.10",
"netmask": "255.255.255.0",
"gw": "192.168.0.1",
"mac": "a4:cf:12:75:38:ec"
}
I turn off the router with my hands:
Obviously wifi.on (‘disconnected’) - it worked.
I turn on the router, I get a message from wifi.on (‘connected’):
{
"ip": "192.168.0.10",
"netmask": "255.255.255.0",
"gw": "192.168.0.1",
"mac": "a4:cf:12:75:38:ec"
}
And that’s it. If I turn off the router again, then no events occur.
Moreover, if you give the wifi.getIP () command when the router is off, then we get.
{
ip: "192.168.0.10",
netmask: "255.255.255.0",
gw: "192.168.0.1",
mac: "a4:cf:12:75:38:ec"
}
(the router has been turned off for more than two minutes)
That is, the board does not understand that wifi / network is no more.
Question:
PS So far, the only working option I have found is the gateway ping once every 30 seconds, and if (rateTime> 1000) {e.Reboot ()};
But I think this is not the best option :)
PPS Sorry for the presentation - English is not my native language.
I will be glad to any advice. Thanks.