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

User avatar
By Amorphous
#91645 Hi,

I am trying to use SmartConfig to share the SSID and Password to the NodeMCU. But when I reset it or it loses power, I have to configure it again. What can I do to prevent this from happening and so that the module remembers the SSID-Password unless user presses a button to initiate restart?

My code -

#include <ESP8266WiFi.h>;
#include <EEPROM.h>;

void setup() {
Serial.begin(115200);
delay(10);

WiFi.mode(WIFI_STA);
delay(500);
IPAddress local_IP(192, 168, 1, 199);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); // this is optional
IPAddress secondaryDNS(8, 8, 4, 4); // this is optional

// Print feedback if the settings are not configured
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.beginSmartConfig();

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println(WiFi.smartConfigDone());
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {

}