Why WiFi-Manager directs to 192.168.244.1 instead of 192.168.4.1? (SOLVED)

This is the code I used.

#include <FS.h>                   //this needs to be first, or it all crashes and burns...

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <SimpleTimer.h>
#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
//#define BLYNK_DEBUG


//define your default values here, if there are different values in config.json, they are overwritten.
//char mqtt_server[40];
//char mqtt_port[6] = "8080";
char blynk_token[34] = "**********************";

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();

  //clean FS, for testing
  //SPIFFS.format();

  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          //strcpy(mqtt_server, json["mqtt_server"]);
          //strcpy(mqtt_port, json["mqtt_port"]);
          strcpy(blynk_token, json["blynk_token"]);

        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read



  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  //WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
  //WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
  WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 33);

  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //set static ip
  //wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  
  //add all your parameters here
  //wifiManager.addParameter(&custom_mqtt_server);
  //wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_blynk_token);

  //reset settings - for testing
  //wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();
  
  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  //wifiManager.setTimeout(120);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //here  "AutoConnectAP"
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("Wifi_Manager", "password")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  //strcpy(mqtt_server, custom_mqtt_server.getValue());
  //strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(blynk_token, custom_blynk_token.getValue());

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    //json["mqtt_server"] = mqtt_server;
    //json["mqtt_port"] = mqtt_port;
    json["blynk_token"] = blynk_token;

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.printTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
  }

  //Serial.println("local ip");
  //Serial.println(WiFi.localIP());

  Blynk.config(blynk_token);
  bool result = Blynk.connect();

if (result != true)
{
  Serial.println("BLYNK Connection Fail");
  Serial.println(blynk_token);
  wifiManager.resetSettings();
  ESP.reset();
  delay (5000);
}
else
{
  Serial.println("BLYNK Connected");
}

}

void loop() {
 
Blynk.run();

}

And with this code seems like I managed to reset those SSID and password.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
void setup()
{
  WiFi.disconnect();
//  WiFiManager.resetSettings();
//  ESP.eraseConfig();
//  ESP.reset();
//  ESP.restart();
}
void loop()
{
  yield();
}

So do I need to add some button to my Blynk-project like “Reset WiFi-settings”? But this I guess works only when I´m still connected to the old WiFi-network.

What does this : “ESP.reset();” mean in the code? is it basically the same as " WiFi.disconnect();"? So it resets the WiFi-settings, if it can´t find the old WiFi-network automatically anymore? And that way it takes me to config again.

Or what is the best way to do this? Or is this even connected properly now? Its bit weird have to say. How does this device act when i take it to some other place wheres new WiFi-network to connect if I havent reseted it first? Does it reset WiFi-settings automatically then to be able to go to the config again?

Correct.

You may want to review this page

Yes, when cannot connect to the configured router.

Okay, a few things here…

  1. I’ve compiled and uploaded this code to a device and it produces a captive portal at 102.168.4.1
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started

I suspect that your WiFiManager.h file contains a line that says something like:

IPAddress     _ap_static_ip (192,168,244,1);

That part of my WiFiManager.h file looks like this

IPAddress     _ap_static_ip;
IPAddress     _ap_static_gw;
IPAddress     _ap_static_sn;
IPAddress     _sta_static_ip;
IPAddress     _sta_static_gw;
IPAddress     _sta_static_sn;

If that’s not the case, then you may have several version of WiFiManager installed (you hinted at this before). You should turn on verbose compiler messages in the IDE to see the path of the library that’s used, like this:

Using library WiFiManager at version 0.14 in folder: C:\Users\Pete Knight\Documents\Arduino\libraries\WiFiManager 

Find the folder that’s being used and check the contents of the WiFiManager.h file.

  1. I think that there are a few lines missing from the start of your serial monitor output, and I suspect that the first two missing lines say:
mounting FS...
failed to mount FS

I say this because of the line in your output that says:

failed to open config file for writing

If this is the case then I suspect that you’ve compiled your code with a “(no SPIFFS)” option selected in the Flash Size menu of the IDE. You need a small amount of SPIFFS (1M is usually the smallest option for a NodeMCU, but only a small amount is actually needed)).
This prevents the Blynk Auth Code data from being saved to SPIFFS and retrieved later.
WiFi credentials aren’t stored in SPIFFS, so they will be saved and the NodeMCU will attempt to re-connect to the same network. If it can’t then it will launch the WiFiManager captive portal automatically when the device is booted (I think this probably answers one of your questions about the need for a way to clear existing WiFi credentials - it’s not really needed, but more on that later).

  1. You may also find that you need to format the SPIFFS storage area before it can be used, but in my experience this only seems to be necessary if you’ve changed the type and size of data being stored in SPIFFS and you need to clear it out.

To format SPIFFS you un-comment this line:

  //SPIFFS.format();

then upload the code and boot the device once, then comment-out that line and re-upload the code.
The IDE now has a neat way of doing that, using the “Erase Flash:…All Flash Contents” option.

image

  1. As I’ve said already, If you take your NodeMCU to a place where its out of range of any known network (or if you flash it with the “Erase Flash:…Sketch + WiFi settings” or “Erase Flash:…All Flash Contents” options) then it will launch the WiFiManager captive portal.

Once the portal is launched it will scan for available networks and allow you to choose one then input the password. You’ll also be able to add the Blynk auth code that will be used at that location.
The only time that you’ll need to have access to the portal again is if either the Wifi credentials change (in which case the portal will launch automatically) or if you need to amend the Blynk auth token/ This could be because you’ve inputted it incorrectly, or because you want to refresh it for some reason.

You can either:

  • Re-flash the device with the "“Erase Flash:…Sketch + WiFi settings” option (very messy!)
  • Take the device out of range of the known network and connect it to something else (maybe a hotspot) then return to the correct Wi-Fi network and re-input the credentials (also messy, but do-able)
  • Have a physical button or button widget in the app that erases the WiFi credentials using WiFi.disconnect()

Hope this adds some clarity.

Pete.

One other thing to note.
If anyone tries to compile this code and gets and gets a compiler error message something like “‘dynamicjsonbuffer’ was not declared in this scope” then you need to downgrade your ArduinoJson library from 6.x.x to 5.13.5

Pete.

Thanks a lot. That made many things clear. I checked my “WiFiManager.h” and it looks the same as yours. Nothing about 192.168.244.1.

And yes, I had “No SPIFFS” there. So i tried with “1M SPIFFS” and also “Erase Flash (Skecth and WiFi-settings” on. Still directs me to that weird 192.168.244.1, but serial monitor gives this now:

*WM: [1] Custom AP IP/GW/Subnet: 
*WM: [0] [ERROR] softAPConfig failed! 
*WM: [1] AP IP address: 192.168.244.1
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  192.168.244.1
*WM: [2] HTTP server started 
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] Config Portal Running, blocking, waiting for clients... 
*WM: [2] NUM CLIENTS: 0 
*WM: [2] WiFi Scan ASYNC completed in 2209 ms
*WM: [2] WiFi Scan ASYNC found: 8
*WM: [2] NUM CLIENTS: 1 
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> ncc.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] WiFi Scan ASYNC started 
*WM: [2] WiFi Scan ASYNC completed in 2207 ms
*WM: [2] WiFi Scan ASYNC found: 8
*WM: [3] -> ip-info.ff.avast.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 973 ms ago
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 3277 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 4144 ms ago
*WM: [2] <- HTTP Wifi 
*WM: [2] Scan is cached 4808 ms ago
*WM: [1] 8 networks found
*WM: [2] AP:  -65 **********************
*WM: [2] AP:  -66 ************
*WM: [2] AP:  -67 **********
*WM: [2] AP:  -70 *********
*WM: [2] AP:  -74 ********
*WM: [2] AP:  -79 *************
*WM: [2] AP:  -83 **************
*WM: [2] AP:  -85 *************
*WM: [3] _staShowStaticFields 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [3] Sent config page 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 7457 ms ago
*WM: [3] -> www.msftncsi.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP Root 
*WM: [3] -> 192.168.244.1 
*WM: [3] lastconxresult: WL_IDLE_STATUS
*WM: [2] Scan is cached 10915 ms ago
*WM: [3] -> detectportal.firefox.com 
*WM: [2] <- Request redirected to captive portal 
*WM: [2] <- HTTP WiFi save  
*WM: [3] Method: POST
*WM: [2] Parameters 
*WM: [2] -------------------- 
*WM: [2] blynk: *****************************
*WM: [2] -------------------- 
*WM: [3] static ip: (IP unset)
*WM: [3] static gateway: (IP unset)
*WM: [3] static netmask: (IP unset)
*WM: [3] static DNS: (IP unset)
*WM: [3] Sent wifi save page 
*WM: [2] process connect 
*WM: [2] Connecting as wifi client... 
*WM: [1] STA static IP: (IP unset)
*WM: [2] Custom static IP/GW/Subnet/DNS 
*WM: [2] Custom static DNS 
*WM: [1] STA IP set: (IP unset)
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to new AP: *******************
*WM: [3] Using Password: ****************
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] Connect to new AP [SUCCESS] 
*WM: [1] Got IP Address: 
*WM: [1] 192.168.10.64 
Should save config
*WM: [2] disconnect configportal 
*WM: [2] restoring usermode STA
*WM: [2] wifi status: WL_CONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting 
connected...yeey :)
saving config
{"blynk_token":"*******************************"}BLYNK Connected
*WM: [3] freeing allocated params! 
*WM: [3] unloading 

I have no idea yet why it directs me to that wrong config-site, but still…

my question is… is this NodeMCU properly connected anyway? So it works… but bit weird way?

I try to solve the mystery of 192.168.244.1 still.

Thanks a lot for your help… been a big help

You’re still missing some lines from the start of your serial output. You should keep the serial monitor open, clear the output then press the reset button on your NodeMCU.

What does vebose compiler messages say about the location of your WiFiManager library?

Pete.

Oh sorry bout this. Vebose compiler shows the right place for WiFiManager.h. And I checked it and it should be ok. So working or not? Heres all the serial monitor info:

mounting FS...
mounted file system
reading config file
opened config file
{"blynk_token":"****************************"}
parsed json
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
*WM: 
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: Custom AP IP/GW/Subnet
*WM: AP IP address: 
*WM: 192.168.244.1
*WM: HTTP server started
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Handle root
*WM: Scan done
*WM: **********
*WM: -63
*WM: ***********
*WM: -65
*WM: ********
*WM: -67
*WM: ************
*WM: -72
*WM: **********
*WM: -73
*WM: **********
*WM: -76
*WM: *****************
*WM: -80
*WM: **************
*WM: -84
*WM: ********
*WM: -89
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: WiFi save
*WM: Parameter
*WM: blynk
*WM: **************************
*WM: static ip
*WM: (IP unset)
*WM: static gateway
*WM: (IP unset)
*WM: static netmask
*WM: (IP unset)
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Connection result: 
*WM: 3
Should save config
connected...yeey :)
saving config
{"blynk_token":"*******************"}BLYNK Connected
*WM: freeing allocated params!

This what it says after restart:

mounting FS...
mounted file system
reading config file
opened config file
{"blynk_token":"********************"}
parsed json
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Custom STA IP/GW/Subnet
*WM: (IP unset)
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.10.64
connected...yeey :)
BLYNK Connected
*WM: freeing allocated params!

From here

Hi, I am experimenting the issue. The only fix I found is to modify startConfigPortal, by adding
WiFi.mode(WIFI_OFF);
delay(2000);
just before
WiFi.mode(WIFI_AP_STA);
A lower delay might work.
When I do that, I get 100% of the time 192.168.4.1
Otherwise, I get very often 192.168.244.1
Looks like it’s related to ESP8266 core

Best,

Jean

2 Likes

Also being discussed here:

It seems that it’s something to do with changes to the Arduino core to accommodate IPv6.

@Lobotomi what version of the Arduino core are you using?

Pete.

1 Like

Thanks for this info. But where do I find that “startConfigPortal”?

And sorry how do I check the Arduino core version?

But still… Is this working now anyway it´s weird? That I´d like to know… And of course how to fix this

In your .cpp .h files. Mine are stored here… C:\Users\eboli\Documents\Arduino\libraries\WiFiManager

Tools / board / board manager.
Scroll down to the bottom and you’ll find ESP8266.
Check which version is in use.

Pete.

1 Like

Modifying WiFiManager.cpp didn´t help me, but surprise…

I had Arduino core version 2.5.0 beta2 and I updated it to 2.5.0. It finally directs me to the right site 192.168.4.1. That´s absolutely great! Thanks a lot PeteKnight for this idea. So what I learned from this? update, update and update once more.

So serial monitor gives this now and I assume that everythings ok now… right?


mounting FS...
mounted file system
reading config file
opened config file
{"blynk_token":"****************************"}
parsed json
*WM: Adding parameter
*WM: blynk
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result: 
*WM: 0
*WM: 
*WM: Configuring access point... 
*WM: Wifi_Manager
*WM: password
*WM: AP IP address: 
*WM: 192.168.4.1
*WM: HTTP server started
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Scan done
*WM: ****************
*WM: -66
*WM: *************
*WM: -67
*WM: *************
*WM: -70
*WM: ****************
*WM: -76
*WM: ********
*WM: -77
*WM: *************
*WM: -80
*WM: *************
*WM: -83
*WM: **********
*WM: -88
*WM: **************
*WM: -88
*WM: ***********
*WM: -89
*WM: Sent config page
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: Handle root
*WM: Request redirected to captive portal
*WM: WiFi save
*WM: Parameter
*WM: blynk
*WM: *****************************
*WM: Sent wifi save page
*WM: Connecting to new AP
*WM: Connecting as wifi client...
*WM: Connection result: 
*WM: 3
Should save config
connected...yeey :)
saving config
{"blynk_token":"***********************"}BLYNK Connected
*WM: freeing allocated params!

Thanks a lot for everybody who helped me to solve this weird problem.

Yay! we got there in the end!
It looked like you were getting disheartened half way through, but well done for sticking with it and getting there in the end.

One slight improvement that you could make. If you changed the value of blynk_token from whatever your current Auth code is to “paste Blynk Auth code” then when the captive portal pops up it won’t give away your current auth code, and will act as a prompt for whoever sets this up to paste the Auth token into that field.

Pete.

1 Like