Device: Wemos D1 Mini (ESP8266-based board)
Usage: 3 buttons, rest is up to you
First, install WiFiManager to Arduino IDE, back up .cpp and .h files in library folder, and replace them with ones from my zip file.
Description: When a device powers up, it makes access point with name entered in INO file. On connecting to that AP with Android device it will open Android-built-in browser. Opened page gives four options:
- Configure WiFi - lists all SSID’s, select one, enter password and Cayenne token
- Configure WiFi (No Scan) - enter your WiFi SSID, password and Cayenne token
- Info - all relevant info about board
- Reset - name says it all
With saving all credentilas, board resets, enters STA mode (WiFi station, like any other WiFi client), disabling AP in the process. After this setup process, if board is powered down, on reboot will automatically connect to set up WiFi and, after a few seconds, to Cayenne.
If you need to re-enter WiFi credentials, connect D5 pin with ground (or put momentary button for that) and board resets to AP mode. At this moment, in both Configure Wifi and Configure WiFI (No Scan) modes, previously entered Cayenne token will be pre-entered in field Cayenne, so there is no need to enter it again (you can if you want).
Full reset, with wiping all data can be made by connecting pin D6 and D5 to ground, after that shorting RST to ground. Board will be fully erased, and after it boots (it takes a second, literally), power it down, disconnect pins D5 and D6, and power it up. It will behave like new board, without any setting.
For any new fields, you need to add definition at the start (like I did char token[40]), in setup part, right before
WiFiManagerParameter custom_cayenne_token(“token”, “Cayenne token”, token, 40);
add your parameter, but remeber: it HAS TO BE named custom_, first parameter in brackets is field name, second is written on that field, third is name of variable previously set, and fourth is size of it - it is good to be same as variable).
Few lines after, right after WiFiManager wifiManager; declaration, you have to add your custom parameter, preferably after wifiManager.addParameter(&custom_cayenne_token);
Now you need to repeat process all over again in loop part, for adding same parameters to OnDemand AP (the one that is brought up with shorting D5 to ground). Find WiFiManagerParameter, and start there, like in previous step.
To retireve stored parameters, you need to use custom_XXXXXXXXX.getValue().
You can also change SSID of AP’s, and secure them with passwords. On my original line 92 you can see
if (!wifiManager.autoConnect(“AutoConnectAP”)) {
Change autoConnect(“AutoConnectAP”) to autoConnect(“YOUR_SSID”, “YOUR_PASSWORD”), and your INITIAL AP will be secured.
For securing OnDemand AP go to line 160 where you can find
if (!wifiManager.startConfigPortal(“OnDemandAP”)) {
Change startConfigPortal(“OnDemandAP”) to startConfigPortal(“YOUR_SSID”, “YOUR_PASSWORD”), and it will be secured.
More about WiFIManager is available on GitHub - tzapu/WiFiManager: ESP8266 WiFi Connection manager with web captive portal, official page.
At the bottom I’ve made my Cayenne send data script, which is used few lines above it. Change it as you like or need, as this is just plain data send…
Compile and upload, run and enjoy!
UPDATE: Link to files on Dropbox is fixed, sorry for mistake.