So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Anton2k
#85262 Hi,

I am looking into using a NodeMCU for a project I am working on.

I want to be able to connect to the NodeMCU and setup the WiFi network details so each time it is powered off / on it will auto connect to the network that has been set. Looking at this guide https://randomnerdtutorials.com/wifimanager-with-esp8266-autoconnect-custom-parameter-and-manage-your-ssid-and-password/ it looks do-able using the library "WiFi Manager".

The only use case I don't think this guide covers, and that i'm hoping that you guys can help clear up for me is this...

NodeMCU is setup to connect the my home network, I buy another router that has a different SSID, I need to connect the NodeMCU to this new router / SSID. Does this WiFi Manager library or any other library have the functionality to achieve this? or would I need to power down the known router that the NodeMCU has saved and then connect it to the new SSID before power up the old router?

Hope this make sense - the project could potentially going into house holds, where such a use case might happen hence why I want to know.

As a side question, lets say the "project" gets moved and the know wifi router is not in range will it still keep the save credentials or wipe them before putting the NodeMCU back into AP mode?

Thanks,
Anton
User avatar
By btidey
#85276 wifiManager is normally used with autoConnect. This tries to connect with the last network used with the stored ssid and password. If that fails then it then activates wifiManagers Access point to allow you to select a new network and enter its password.

So if you want to switch networks then you have some choices.

First you can use startConfigPortal() instead of autoConnect. You would have to have some logic (e.g. reading a GPIO at start up) to allow that call to be made.

Second, and probably much simple,r you can erase the stored ssid and password and let wifiManager automatically start up its AP logic when restarted to choose which network to connect to. To erase the existing stored credentials use WiFi.disconnect(true); and restart the esp. You can trigger the erasure in a variety of ways including a webServer command if you have a webServer running.