WiFiManager For Cayenne

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.

INO and custom WiFiManager

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.

5 Likes

Definitely going to check this out!

Hello @vedran.musica,

This is really interesting, and I would like to try it out. However the code doesn’t exits in the folder you mentioned.

Can you please send me the code, would like to try this out.

Thanks
S

Hello @soubir,

Thank you for interest in this, and I hope I can help.

Can you tell me which code is missing?

If you refer to WiFiManager, I’ve adapt my about a 10 days ago, version 0.12.0. You can find it in Arduino Library Manager (author is tzapu).

After installing it through Arduino, close Arduino IDE, and find where are your libraries located. In that folder you should see WiFiManager folder. Within that folder are WiFiManager.cpp and WiFiManager.h files located. Make backup of them, and replace with files from my ZIP file.

That should work, it is the same way I did on my second laptop and home desktop.

Please, note here has it work out for you. Thank you :slight_smile:

Best regards,
Vedran

Oh, I see now that Dropbox link is wrong.

Here is new one: INO and custom WiFiManager

1 Like

Thanks. I will try it and let you know

Hello there,
i have tried using WiFiManager for cayenne but i can’t figure how to save the settings in the config file.
I’m using an esp8266 12S and i have uploaded your code successfully. My serial comm returns those messages:

mounting FS…
mounted file system
reading config file
opened config file
{}failed to load json config
*WM: Adding parameter
*WM: token
*WM:
*WM: AutoConnect
*WM: Connecting as wifi client…
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 3
*WM: IP Address:
*WM: 192.168.1.7
connected…yeey :slight_smile:

About to start Cayenne…
Cayenne started.
Cayenne run, uploaded value.
Cayenne run, uploaded value.
Cayenne run, uploaded value.
Cayenne run, uploaded value.
Cayenne run, uploaded value.
//and goes on… Cayenne run, uploaded value

If i ground the trigger pin ESP enters the AP mode. I have entered successfully the SSID/PASS/TOKEN and after that the ESP8266 does reset and then connects in my dashboard successfully. But if i reset the module the Token is gone. And as it seems it fails to load the json config file. I don’t know if this is the normal operation of this code but i would appreciate some more information.

Finally some questions:
Where is the json file stored ? (EEPROM? RAM? ROM?)
Is it possible to read the Token-Ssid-Password and sent them to a serial after reading the json config ?

Best Regards, Kostas.

Strangely, I have same problem now with two of my ESP’s. Data is stored initially, but on restart it can’t read it out. I’ll try to find some solution for it, I guess it is some problem with my implementation of WiFi Manager for Cayenne.

I’ll try to see is there new version of WiFiManager, and re-implement this workaround for Cayenne. But, please, don’t expect it in next two week, as I’m currently away…

i use wifimanager on other project , but with Cayenne i must use Cayenne.begin(username, password, clientID, ssid, wifiPassword); with the <CayenneMQTTESP8266.h> library

i found on Wifimanager this : GitHub - tzapu/WiFiManager: ESP8266 WiFi Connection manager with web captive portal
“You can use WiFiManager to collect more parameters than just SSID and password. This could be helpful for configuring stuff like MQTT host and port, blynk or emoncms tokens, just to name a few”
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);

How to use this library to “replace” :

Cayenne.begin(username, password, clientID, ssid, wifiPassword);

?

I found why your ESP loose the token. One line is missing when you save to SPIFF :

json.printTo(configFile);

Add it just before configFile.close(); and it will work fine.

2 Likes

You can also do: Cayenne.begin(username, password, clientID);
No need to include SSID and wifiPassword)
In principle the wifimanager already made wifi access.
Best of all it just works!

I have tweaked my Solderless SonOff OTA MQTT with no WIFI and MQTT information inside the sketch

2 Likes

thank’s, i’ll test :yum:

For your convenience just published my latest concoction in a SonOff project, it works for me solderless (seal still on it). Think it will be also suitable for other ESP8266 devices with the need for OTA and WiFi / MQTT credentials in EEPROM suitable for Cayenne.

1 Like