how does wifimanager remember last connected network....i wanna do same

Hello amazing people!
cann some one tell me how does my nodemcu recall the net connection it was connected to,last time....even if some other ssid and pass was written in code.....no what i want is : I want to use this property in other ways,like i have saved an API key in my code so that data would be sent to thingspeak.....I wan to control that externally....and just did that .....now when i turn the power off,..i have to feed my nodemcu new api ....but i want it to remember which api key it had last time and go for it even if code states some other api...
Aint that cool.........lets go for it..
i'll keep tryin and lets see where we reach
thanks already.....

It's a function of the ESP8266 itself.

You can reprogram it and it will still attempt to connect to the last network that you gave it information for, even if that connection was not successful.

This connection is attempted as soon as power is applied, before any of your code gets a chance to do much.

Don

Thanks floresta
so can I find a way to get my mentioned results

If you state your proposal in coherent sentences then maybe someone could offer an opinion.

Don

sabishaw:
Thanks floresta
so can I find a way to get my mentioned results

comment out WiFi.begin()

https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#setautoconnect

Note: static config is not remembered

hey …i just did it…
using flash memory…
eeprom library
but what i m able to do at the moment is that i can save numbers in flash memory not strings or characters…

sabishaw:
hey ...i just did it....
using flash memory...
eeprom library
but what i m able to do at the moment is that i can save numbers in flash memory not strings or characters....

what do you want to save?

thanks Juraj for replying
i want to save a string

sabishaw:
thanks Juraj for replying
i want to save a string

how is it related to thread's title?

wifi manager takes data in string i.e. ssid and pass code and stores em in flash.....now i can i do so?.....i want to save strings other than ssid and pass

sabishaw:
wifi manager takes data in string i.e. ssid and pass code and stores em in flash.....now i can i do so?.....i want to save strings other than ssid and pass

it does not as you could read in comment #1

https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#setautoconnect

setAutoConnect

Configure module to automatically connect on power on to the last used access point.

WiFi.setAutoConnect(autoConnect)

The autoConnect is an optional parameter. If set to false then auto connection functionality up will be disabled. If omitted or set to true, then auto connection will be enabled.

so you need only WiFi.waitForConnectResult();

it does not as you could read in comment #1

when you feed it ssid and pass a couple of times via autoconnect…it then tries to connect to last connected…if thats not avaliable,it again avails auto connect thing,…i have done it a thousand times so far

sabishaw:
when you feed it ssid and pass a couple of times via autoconnect....it then tries to connect to last connected...if thats not avaliable,it again avails auto connect thing,....i have done it a thousand times so far

you asked how WiFiManager does it. WiFiManager doesn't store anything

but it happens only after you include wifi manager…even serial monitor shows message to wait so that it will connect to last connection…and that is definitely written in wifi manager library,because i didnt write that in my code…i believe there iis certain command in wifi manager which saves this string into board and after seeing the library itself in .cpp was ununderstandable and thats my question…how wifimanager did that

but it happens only after you include wifi manager

Not true. If you program a simple blinky sketch, or even a blank sketch, into your ESP8266 you will find that your device still connects to your router the next time you power it up.

This happens because, at some time in the past, with or without WiFi Manager, you provided your SSID and Password to the ESP8266 and it has preserved that information in it's flash memory.

PS - The best you can hope for is that it didn't 'call home' to a server in China with that information.

Don

sabishaw:
but it happens only after you include wifi manager.....even serial monitor shows message to wait so that it will connect to last connection...........and that is definitely written in wifi manager library,because i didnt write that in my code.......i believe there iis certain command in wifi manager which saves this string into board and after seeing the library itself in .cpp was ununderstandable and thats my question....how wifimanager did that

this is from WiFiManager (main line is WiFi.begin() without parameters)

if (WiFi.status() == WL_CONNECTED) {
    DEBUG_WM(F("Already connected. Bailing out."));
    return WL_CONNECTED;
  }
  //check if we have ssid and pass and force those, if not, try with last saved values
  if (ssid != "") {
    WiFi.begin(ssid.c_str(), pass.c_str());
  } else {
    if (WiFi.SSID()) {
      DEBUG_WM(F("Using last saved values, should be faster"));
      //trying to fix connection in progress hanging
      ETS_UART_INTR_DISABLE();
      wifi_station_disconnect();
      ETS_UART_INTR_ENABLE();

      WiFi.begin();
    } else {
      DEBUG_WM(F("No saved credentials"));
    }
}

The best you can hope for is that it didn't 'call home' to a server in China with that information

:slight_smile: :slight_smile: :slight_smile: ...funny
cool....i think i m getting it
how does it even save something on its own.....can i save any string like that
thanks

sabishaw:
:slight_smile: :slight_smile: :slight_smile: …funny
cool…i think i m getting it
how does it even save something on its own…can i save any string like that
thanks

the Espressif SDK libraries handle the WiFi on low level. they save the settings to the flash to a “WiFi settings” page on flash. IDE Tools option “Erase” can erase them.

thanks juraj
i will see if i can do anything