I have downloaded an Arduino project from GitHub intended to create an electricity meter monitoring system via the HAN port and using an ESP8266 based module to send the data via WiFi to an MQTT broker.
I have successfully configured it for an AdaFruit Huzzah board which uses an ESP-12, which I had available.
So this project uses WiFiManager to on first start switch to the AccessPoint operation mode and enabling a config webpage where I can select the WiFi network to connect to and the password for it. In addition it also has MQTT connection entries like these:
MQTT Server address
MQTT port
MQTT username
MQTT login password
MQTT topic name
So on first start I connected with my phone to its WiFi AP and selected my normal WiFi network and typed in the password, as well as entering my debug MQTT server address etc.
Now I have this problem:
After verifying that the system works I want to reconfigure the MQTT data but I have not found a way to re-enable the WiFiManager config page when the ESP has successfully connected to my WiFi. I know its IP address since it is sent to the debug monitor serial port on startup, but visiting that address in a browser just displays a "could not connect error".
So how can I modify the code such that the config page is available at all times even when the device is properly connected to the selected WiFi?
It seems like it hides this page when it is connected...
Or maybe it is there but on a non-standard TCP port? If so which?
All of this seems to be hidden inside the WiFiManager library...
One thing you can do is add code that you can trigger (with a button?) to execute WiFi.disconnect() and then reset the board. That is supposed to put the board back into "What is my network?" mode.
Another thing you can do is turn off the WiFi router (take down the whole SSID) or change the WiFi Password and then reset the board. If WiFiManager can't join the network with the SSID and Password it has it should then go back to "What is my network?" mode.
But how can one modify the other settings ever?
It seems like there should be a way to get other config items to be modified after it has connected to wifi the first time...
Thanks, I looked at the project on GitHub and read through all of the code.
But I could not find how the WiFiManager menu is started on demand...
How is it actually done?
Is there a button to press or something else?
Or is it running constantly so it is available if one connects to the IP address of the ESP?
If so how is this accomplished?
In my test project it only appears if the WiFi is running as an AP and then the remaining functionality is not there, like communicating with the MQTT broker.
My use case is to be able to reach a config page on the device when it is operating normally and connected to my WiFi network. This should happen even if I don't have access to it physically, like reprogramming it when it sits at a remote location with LAN only access.
40 WiFiManager wm;
83 wm.setMenu(wmMenuItems);
84 wm.setCustomHeadElement(htmlStyles);
85 wm.addParameter(&wmParamAlarmLEDs);
86 wm.addParameter(&wmParamAlarmDisplay);
87 wm.addParameter(&wmParamAlarmDuration);
88 wm.addParameter(&wmParamSunriseDuration);
89 wm.addParameter(&wmParamSleepLEDs);
90 wm.addParameter(&wmParamSleepDuration);
91 wm.setSaveParamsCallback(saveParamsCallback);
92 wm.setTimeout(120);
98 wm.autoConnect("NTPClock");
And inside loop():
262 if (button.released() && buttonPressedMillis) { // released before long push time
263 buttonPressedMillis = 0;
264 menuTimeoutMillis = 0;
265 switch (state) {
...
...
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;
328 }
It looks to me like there is a button or similar that causes state to be set to MENU_CONF_AP and then lines starting at 321 get executed.
Does this cause the device to respond to http requests to its address like it does when it acts as an AP before having been configured?
And how does state get set to this value?