IotWebConf icon indicating copy to clipboard operation
IotWebConf copied to clipboard

Easy way to check for active AP mode?

Open Ricky6633 opened this issue 4 years ago • 6 comments

Hello, is there a way to check easly for active AP Mode? I wanna show two different symbols on a display, one for active AP mode and one for Connected Wifi ConnectedWifi is no problem since i can use the WifiConnectedCallback to set a bool but im unsure how to switch back the bool variable if ap mode is active again ( if wifi connection failed for some reason )

Ricky6633 avatar Oct 01 '21 08:10 Ricky6633

You can define Handlers (callbacks) for both AP and Wifi. The only thing you need to take care is to call the actual handlers before or after your custom tasks are done. Another way to do this, is to frequently monitor the getState() and change you display accordingly.

prampec avatar Oct 01 '21 09:10 prampec

Thanks alot for the fast reply

void CheckWifiStatus() { if (iotWebConf.getState() == 2) { wlanConnected = false; } else if (iotWebConf.getState() == 4) { wlanConnected = true; } }

did the trick wlanConnected = false means AP is on, true means Wifi is connected :)

Ricky6633 avatar Oct 01 '21 09:10 Ricky6633

Instead of 2 / 4 you should use iotwebconf.ApMode / iotwebconf.OnLine enum constants.

prampec avatar Oct 01 '21 10:10 prampec

wlanConnected = false means AP is on, true means Wifi is connected

And what about the other four states? ;)

prampec avatar Oct 01 '21 10:10 prampec

Would you have a example of how to use the enum constant instead of the "raw values" ?

I actually just need to know if ap mode is on OR wlan is connected (for switching the coresponding symbol on display) or is there a benefit i dont see?

hmm maybe also checking if none is "active" to hide the symbol, but in normal operation this should never happen right?

Ricky6633 avatar Oct 01 '21 11:10 Ricky6633

Boot, NotConfigured, ApMode, Connecting, OnLine, OffLine

Ah well, i found the states, im wondering what time "NotConfigured" and "OffLine" is active

i updated my code as follows so far

if (iotWebConf.getState() == iotwebconf::ApMode) { lcd.write(3); //wlan_inverted } else if (iotWebConf.getState() == iotwebconf::OnLine == true && mqttClient.connected()) { lcd.write(4); //wlan_mqtt } else if (iotWebConf.getState() == iotwebconf::OnLine) { lcd.write(2); //wlan }

i found a example use in the mqtt example :)

Ricky6633 avatar Oct 01 '21 14:10 Ricky6633