-->
Page 1 of 1

How to store SSID and PASSWORD to access it after restarting

PostPosted: Mon Jan 23, 2017 11:22 am
by RoyBlue
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!
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>&nbsp;<a href=\"OFF1\"><button>OFF1</button></a></p>";

  webPage += "<H1>LED2</H1>";
  webPage += "<a href=\"ON2\"><button>ON2</button></a>&nbsp;<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();
}


Re: How to store SSID and PASSWORD to access it after restar

PostPosted: Wed Jan 25, 2017 11:24 pm
by rodmcm
const char* ssid = "xxxxxx";
const char* password = "xxxxxx";*

Just fill in your ssid and password where the xxxx are ie
const char* ssid = "Telecom-Home";
const char* password = "HomePassword";

They stay with the program and read every time ESP boots up

Re: How to store SSID and PASSWORD to access it after restar

PostPosted: Thu Jan 26, 2017 12:20 am
by gdsports
Be sure to pull GPIO0 to 3.3V so the ESP runs the progm in Flash. If GPIO0 is connected to ground, the ESP always goes into bootload mode.