The use of the ESP8266 in the world of IoT

User avatar
By OLD MONK
#91174 Hi all.
I am new to IoT devices and its uses and is struggling to get a small fix for my device for the deployment purpose. I have a nodeMCU and I have setup initial codes such that it can send data to ThingsBoard node. Also, instead of hard coding ssid and password I used wifi-manager library so that i can establish a connection manually. My concern is my device should work like just my phone in terms of connectivity, although I will run it into deepsleep mode for maximum time. I am struggling to put following scenarios at once in my device:
1. If it powers on it should automatically connect to the available wifi.
2, If it is not able to connect, it should go in station mode and allow user to configure the credentials.
3. If someone changed ssid and password, it should be able to identify this and go into station mode for reconfiguration. Maybe I blink an LED at certain frequency to indicate it is not connected to wifi.
4. If let us say there is power outage of 4-5 hours, it will go in deepsleep mode(this I know how to make it work), but when it should wake up and power is back, points 1, 2 and 3 should be taken care.
5. If some extreme scenario appears at the end user can just go and do hard reset, such that everything starts from new.

Any help would be highly appreciated especially for point 3 and 4, as I am struggling a bit into it and is not able to find answer from a month. Please feel free to ask for any clarification, and pardon if this is silly question, but seems problematic for me.

I have searched other links but none seems to be a perfect solution.
Thanks in advance.
User avatar
By OLD MONK
#91333 I solved the problem myself.
It was just utilizing the wifimanager library properly.
wifiManager.setConfigPortalTimeout("time in seconds");
The above line solves the problem if utilized at right position in the code.

Anyone facing a similar problem or a newbie can just play with this line and problem will be solved.

You can use following sample code if you don't know how to start. I thought I would get a reply from people who had solved it, but the community is not that active it seems so.
Code: Select allWiFiManager wm;

  wm.setConfigPortalTimeout(60);

  Serial.println("Setup attempt to connect");
  wm.autoConnect("AutoConnectAP","password");
  if (!wm.autoConnect("AutoConnectAP","password")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    Serial.println("Starting Configure portal");
    Serial.println("manual ap mode to connect");
    wm.setConfigPortalTimeout(60);
    wm.startConfigPortal("AutoConnectAP","password"); 
    wm.stopConfigPortal();
    if(WiFi.status()!=WL_CONNECTED){
    Serial.println("failed to connect and hit timeout");
    Serial.println("Going to deepsleepmode for 10 seconds");
    ESP.deepSleep(10e6);
    delay(10);