I need to add a custom configuration webpage to a sketch for the ESP8266 which I have downloaded from GitHub.
In order not to overwrite the WiFiManager storage of the ssid and password with my own config data and to be able to manage all of the items in one place I need to know where WiFiManager stores the two strings in EEPROM.
Because I assume that EEPROM is where they get stored when one visits the WiFiManager page on startup when there is no configured WiFi connections available.
So when the user visits my own config page when the device is properly connected to WiFi he will see the two entries for SSID and Password and he can change them accordingly. But these changes only currently will go into my own config struct. Therefore I would like to know how to set these into the WiFiManager storage area for later use if the user changes these items.
So to avoid the problems I want to be able to set the WiFiManager ssid and password from my own code such that it will be used when the device restarts. Or else send it to WiFiManager on system startup after I have read them from my own config area.
And I want to make sure I am not using an area of EEPROM which WiFiManager also uses for storage of its data.
So can someone here advice where to find this information or outright just put it into your reply?
That is good to know so I can safely use the EEPROM altogether for my own configs!
So can they be read by the application such that I can show them in my own config webpage and also allow modification?
I.e. how can I read and write these from my applicatioon.
(I have scanned the WiFiManager cpp and h files to find anything useful but failed...)
But I am not very good at c++ programming...
Yes, 4kBytes as far as I know. I use 256 bytes for my custom config system (including ssid/password) and I want to store the values WiFiManager uses there so they are the same.
And if the user changes ssid in my config it has to reflect over to WiFiManager's data.
And what I am really doing is trying to apply my own config solution (which is used in many of my other projects) to the sketch I have downloaded (link in first post) for managing my electricity meter, which was switched recently to one that has a HAN connector for reading consumption data.
The author of that sketch has expanded WiFiManager's data to also include MQTT items, which really need to be accessible also after first start.
But they are not now since WiFiManager does not run if it connects to the programmed WiFi and there seems to be no way to bring it up except by walking out of WiFi range with the device and powering it up with a separate power connection (it gets its power from the meter normally).
A REAL PITA!
Do you refer to this code section regarding bringing up the config portal?
320 case MENU_CONF_AP: {
321 memcpy(displayData, SEG_CNAP, 4);
322 display.setSegments(displayData);
323 wm.setConfigPortalTimeout(120);
324 wm.startConfigPortal("NTPClock"); // returns after Exit in browser or timeout
325 state = CLOCK;
326 saveConfig();
327 break;
If so I could not figure out how the trigger for MENU_CONF_AP is entering the sketch.
It looks like there is some mechanical item (encoder) that is attached to the "clock"...
Anyway if this can be done inside loop() I need to figure out a way to signal to the sketch that it is time to start the configportal.
Or can I just start it once in the end of setup() or as a one-timer at the start of loop() and leave it running for a minute or so from power-up?
If noone connects to it it will go away after the timeout (120 s in the example), or not?
In such a case I can connect to it after I reset the device, I assume here that it will not start the AP mode too, because that will kill my use for it (remotely 100 km away).
But this comment is really disturbing in that case:
wm.startConfigPortal("NTPClock"); // returns after Exit in browser or timeout
Looks like "startConfigPortal" is blocking, so that means a delay when starting up the system, which is not acceptable.
OK thanks,
then I will not spend more time on the WiFiManager but implement my own config in normal EEPROM instead like I have done in my own sketches.
And I will move the MQTT parameters out of WiFiManager and put them where they belong in an accessible config page.
I am also using a struct (packed) to contain my config data and I am saving/reading them in one command like you showed above EEPROM.put() and EEPROM.get()
And I have a checksum item in the struct to verify its content is OK.
What do you mean by actually check?
I have built numerous ESP8266 based devices (usually based on ESP-07, ESP-07S and ESP-12 modules) and I always store config data in EEPROM so it is protected also when I flash new firmware into it.
These Expressif modules which use the ESP8266 chip do contain an on-board EEPROM for use as config store etc (for the developer to decide)...
The reason for this thread is that I want to use the GitHub sketch since it does what I need towards my new electricity meter.
However I found out that it uses a one-time only configuration system because it has bunched together the WiFiManager handling of WiFi connection data with the MQTT data comm settings. That means that MQTT cannot be modified once the device has been configured with a working WiFi connection since WiFiManager will not launch the config portal if it can connect WiFi...!