How to store SSID and PASSWORD to access it after restarting
Posted: Mon Jan 23, 2017 11:08 am
We are fairly new to ESP8266 and Arduino. We can create an AP, but everytime we switch the ESP8266 off, all the settings related to the AP are no longer there. How can we make sure that we can save and access the SSID and PASSWORD after we restart the ESP8266 (without any connection to the computer) ? This is the code we are working on.
Please help us figure this out. Thank you!
Please help us figure this out. 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();
}