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

User avatar
By Mattta
#96053 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?

Code: Select all#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() {

}
User avatar
By btidey
#96062 Your setup code is always calling beginSmartConfig which means it will always enter the routine that expects the smartConfig to be completed.

You need to arrange it so that one configured when it starts up and successfully connects then it skips the beginSmartConfig and only calls it if it fails to connect.

When you do the connection first you should be able to use the devices capability to internally remember the connection parameters without having to use EEPROM to save it yourself.