In building a Photon powered device, I’ve realized it would be desirable to be able to easily switch the device between WiFi ON and WiFi OFF modes with a physical switch. Has anyone tried this and can recommend a best path forward? I was thinking something like this.
Any suggestions would be appreciated. Maybe there is a way to do this without the switch?
Well a switch gives a a nice visual indicator of the setting, you could also use an illuminated push button. Other methods would depend on what your device is doing and why you want to turn off WiFi but any sensor input, timer or even a command sent over serial could be put to use.
Thanks! The reason is because from time to time, we like to use these devices in areas where WiFi is not an option…most of them are strewn across Delhi and acceptable WiFi can be hard to come by.
I’ve tried attaching the switch to an interrupt, but it’s hard to tell whether or not it is working. It doesn’t look like WiFi.off() is working (LED still shows it’s connected).
Previously, I was trying to use both a RISE and FALL interrupt so I could determine the position of the switch (ON v OFF), but that seemed to have problems. I was able to successfully catch the FALL, but not the RISE to turn the WiFi bakc on!
By toggling the state using an interrupt, the position of your physical switch is meaningless to the user.
The switch probably doesn’t switch from on HIGH to LOW cleanly, so its is quite possible that interrupt gets multiple changes very close together.
The use of an interrupt is neither suitable nor necessary, by definition your code is running if that switch does anything so you can pick up on the switch state like any other button/input.