How to store SSID and PASSWORD to access it after restarting
Posted: Mon Jan 23, 2017 11:22 am
We are fairly new to ESP8266 and Arduino. We know how to create an AP, but the moment we switch off the ESP8266 and turn it on again, the settings for SSID and PASSWORD is no longer there. How can we make sure that everytime we restart the ESP8266, the settings for SSID and PASSWORD are still there and can be accessed automatically (without the use of computer) ?
Here is our code we are working on. Please help us figure out how to solve the problem. Thank you!
Here is our code we are working on. Please help us figure out how to solve the problem. Thank you!
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <DNSServer.h>
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "xxxxxx";
const char* password = "xxxxxx";*/
ESP8266WebServer server(80);
String webPage = "";
int gpio5_pin = 5;
void setup(void){
digitalWrite(gpio5_pin, HIGH);
delay(2000);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.println(myIP);
webPage += "<HTML>";
webPage += "<HEAD>";
webPage += "<TITLE>LED</TITLE>";
webPage += "</HEAD>";
webPage += "<BODY>";
webPage += "<H1>LED1</H1>";
webPage += "<a href=\"ON1\"><button>ON1</button></a> <a href=\"OFF1\"><button>OFF1</button></a></p>";
webPage += "<H1>LED2</H1>";
webPage += "<a href=\"ON2\"><button>ON2</button></a> <a href=\"OFF2\"><button>OFF2</button></a></p>";
webPage += "<BODY/>";
webPage += "</HTML>";
// preparing GPIOs
pinMode(gpio5_pin, OUTPUT);
digitalWrite(gpio5_pin, LOW);
delay(1000);
Serial.begin(115200);
//WiFi.begin(ssid, password);
Serial.println("");
server.on("/", [](){
server.send(200, "text/html", webPage);
Serial.println("HELLO");
});
server.on("/ON1", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio5_pin, HIGH);
delay(1000);
});
server.on("/OFF1", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio5_pin, LOW);
delay(1000);
});
server.on("/ON2", [](){
server.send(200, "text/html", webPage);
digitalWrite(14, HIGH);
delay(1000);
});
server.on("/OFF2", [](){
server.send(200, "text/html", webPage);
digitalWrite(14, LOW);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}