How to Read and Write Eeprom in Esp32

(Last Updated On: September 21, 2020)

Table of Contents:

  • 1 Introduction:
  • 2 PCBway:
  • 3 Video Tutorial:
  • 4 Required Components:
  • 5 Why alter WiFi Credentials wirelessly???
  • 6 What is WiFi Provisioning???
  • 7 What is Acces Point???
  • 8 Program & Source Lawmaking: Change ESP32 WiFi credentials without uploading lawmaking
    • 8.1 Final Output:
  • ix Video Tutorial:
    • ix.ane Share this:

Introduction:

In this commodity, we are going to walk through " how to Alter & Shop ESP32 WiFi credentials in EEPROM without uploading code from Arduino IDE", We will update WiFi Credential wirelessly and shop the same credentials in the EEPROM memory of the ESP32  using a actually awesome library "EEPROM.h". We are going to develop an Arduino Program, Which Commencement Reads the WiFi Credentials from the EEPROM, and tries to connect to that; If the WiFi is non bachelor or there are no credentials stored in the EEPROM, ESP32 will Acts an Accespoint and creates a Hotspot which will allow usa to connect and modify the WiFi credential. And so information technology connects to the freshly configured WiFi Credentials. It will only take a couple of minutes to go through these steps.

So, without wasting time allow'south get started.

PCBway:

If you want to convert your image projects to realtime, applications & deploy in the realtime field, You need to pattern a PCB, because Devices with these Veroboards volition not last long.

Convert prototype to PCB

PCB manner is one of the best ways to convert your prototypes into realtime applications. I take used their services to convert my prototypes into the realtime Applications.

Conver prototype PCB

PCBWAY is one of the best PCB manufacturers in the current industry. At PCBway.com nosotros tin can get 10 pieces of two layered PCBs at merely $five with 24 hours build fourth dimension & also PCB way offering PCB associates services at just $thirty along with Free aircraft. PCBway is also offering services similar PCB prototype, SMD Stencil, PCB assembly, Flexible PCBs & Advanced PCBs. The best function of PCBway is the Instant quote feature, merely enter the PCB size, choose the quantity, layers, and thickness. That'southward it, nosotros will get the instant quote. place an order by clicking on saving to cart. check out their website for more details.

PCBway.com

Video Tutorial:

This tutorial is also available in the video format, you tin can lookout man the below videos or continue reading this article.

Required Components:

  1. Breadboard     (Buy on Amazon)
  2. ESP32 Module  (Buy on Amazon)
  3. 10k Resistor (Purchase on Amazon)
  4. Push-push (Buy on Amazon)
  5. Connecting wires (Buy on Amazon)
  6. Information Cable to Program ESP32. (Purchase on Amazon)

Why modify WiFi Credentials wirelessly???

If you lot take difficult-coded values in your sketch, if you change your WiFi router or want to bring your device to somewhere else, you take to re-program your esp32, which isn't ideal!

It too makes your sketches less sharable, equally you lot probably will want to supervene upon your SSID and Countersign with placeholders before uploading to somewhere public like GitHub and anyone who is using your code is going to have to update the code earlier they can apply it on their network. This is why nosotros should have WiFi Provisioning in our solutions. Even all IoT Devices that are available in the market have this WiFi Provisioning Characteristic.

What is WiFi Provisioning???

Provisioning IoT products, that do not have a keyboard and display as a user interface, in a elementary and robust fashion is a significant claiming.

Wi-Fi provisioning is the process of connecting a new Wi-Fi device (station) to a Wi-Fi network. The provisioning procedure involves loading the station with the network name (often referred to every bit SSID) and its security credentials. In this process, The target device volition commencement act as an access point and allow the states to connect and change the WiFi credential.

What is Acces Point???

"Anadmission signal is a device that creates a wireless local area network. or WLAN, usually in an office or large building. Anaccess point sometimes connects to a wired router, switch, or hub via an Ethernet cablevision, and projects a Wi-Fi signal to a designated surface area. It is also used for users to configure IoT devices for commencement-time use, or password changes"

Accespoint

Program & Source Code: Change ESP32 WiFi credentials without uploading code

The Program is designed to follow the below steps.

  • On Outset boot, ESP32 will be in set up Station mode, and Read the pre-registered SSID and password combination and tries to connect to the aforementioned.
  • If this process fails, it sets the ESP into Access Bespeak style and creates Open up Wifi(Non protected with Countersign);
  • This open wifi volition allow the user to connect Using whatsoever Wi-Fi enabled device with a browser
  • Later establishing a connection with the Access betoken, y'all can get to the default IP address 192.168.four.i to open up a spider web page that allows user to configure your SSID and countersign;
  • Once a new SSID and password is set, the ESP reboots and tries to connect;
  • If it establishes a connection, the process is completed successfully. and prints the following message "Connected to <EEPROM SSID> Successfully"
  • If the connection fails again, it volition exist gear up every bit an Access Betoken to configure the new SSID and Password.

Each and Every cake of the code explained in the Video, you lot tin can refer to the video for the detailed explanation.

#include <WiFi.h> #include <HTTPClient.h> #include <WebServer.h> #include <EEPROM.h>  //Variables int i = 0; int statusCode; const char* ssid = "Default SSID"; const char* passphrase = "Default passord"; String st; String content; String esid; String epass = "";   //Function Decalration bool testWifi(void); void launchWeb(void); void setupAP(void);  //Establishing Local server at port eighty WebServer server(lxxx);  void setup() {    Series.begin(115200); //Initialising if(DEBUG)Serial Monitor   Series.println();   Serial.println("Disconnecting current wifi connection");   WiFi.disconnect();   EEPROM.begin(512); //Initialasing EEPROM   filibuster(10);   pinMode(15, INPUT);   Serial.println();   Serial.println();   Series.println("Startup");    //---------------------------------------- Read eeprom for ssid and laissez passer   Series.println("Reading EEPROM ssid");     for (int i = 0; i < 32; ++i)   {     esid += char(EEPROM.read(i));   }   Serial.println();   Serial.impress("SSID: ");   Serial.println(esid);   Serial.println("Reading EEPROM laissez passer");    for (int i = 32; i < 96; ++i)   {     epass += char(EEPROM.read(i));   }   Serial.print("Pass: ");   Serial.println(epass);     WiFi.begin(esid.c_str(), epass.c_str()); } void loop() {    if ((WiFi.status() == WL_CONNECTED))   {      for (int i = 0; i < 10; i++)     {       Serial.print("Connected to ");       Serial.impress(esid);       Series.println(" Successfully");       delay(100);     }    }   else   {   }    if (testWifi() && (digitalRead(xv) != 1))   {     Serial.println(" connexion status positive");     return;   }   else   {     Series.println("Connexion Condition Negative / D15 High");     Serial.println("Turning the HotSpot On");     launchWeb();     setupAP();// Setup HotSpot   }    Serial.println();   Serial.println("Waiting.");    while ((WiFi.status() != WL_CONNECTED))   {     Series.print(".");     delay(100);     server.handleClient();   }   delay(1000); }   //----------------------------------------------- Fuctions used for WiFi credentials saving and connecting to information technology which you exercise not demand to alter bool testWifi(void) {   int c = 0;   //Series.println("Waiting for Wifi to connect");   while ( c < xx ) {     if (WiFi.status() == WL_CONNECTED)     {       return true;     }     delay(500);     Serial.print("*");     c++;   }   Serial.println("");   Serial.println("Connect timed out, opening AP");   return simulated; }  void launchWeb() {   Serial.println("");   if (WiFi.status() == WL_CONNECTED)     Serial.println("WiFi connected");   Series.print("Local IP: ");   Serial.println(WiFi.localIP());   Series.print("SoftAP IP: ");   Serial.println(WiFi.softAPIP());   createWebServer();   // Starting time the server   server.begin();   Serial.println("Server started"); }  void setupAP(void) {   WiFi.mode(WIFI_STA);   WiFi.disconnect();   filibuster(100);   int northward = WiFi.scanNetworks();   Serial.println("scan washed");   if (n == 0)     Serial.println("no networks institute");   else   {     Serial.print(north);     Series.println(" networks found");     for (int i = 0; i < n; ++i)     {       // Print SSID and RSSI for each network found       Serial.print(i + 1);       Serial.print(": ");       Series.print(WiFi.SSID(i));       Serial.impress(" (");       Serial.print(WiFi.RSSI(i));       Series.print(")");       //Series.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");       delay(ten);     }   }   Serial.println("");   st = "<ol>";   for (int i = 0; i < due north; ++i)   {     // Impress SSID and RSSI for each network found     st += "<li>";     st += WiFi.SSID(i);     st += " (";     st += WiFi.RSSI(i);      st += ")";     //st += (WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*";     st += "</li>";   }   st += "</ol>";   delay(100);   WiFi.softAP("ElectronicsInnovation", "");   Serial.println("Initializing_softap_for_wifi credentials_modification");   launchWeb();   Serial.println("over"); }  void createWebServer() {   {     server.on("/", []() {        IPAddress ip = WiFi.softAPIP();       String ipStr = String(ip[0]) + '.' + String(ip[ane]) + '.' + String(ip[2]) + '.' + String(ip[three]);       content = "<!DOCTYPE HTML>\r\northward<html>Welcome to Wifi Credentials Update page";       content += "<form action=\"/scan\" method=\"POST\"><input type=\"submit\" value=\"scan\"></form>";       content += ipStr;       content += "<p>";       content += st;       content += "</p><course method='become' action='setting'><label>SSID: </label><input name='ssid' length=32><input proper noun='laissez passer' length=64><input type='submit'></grade>";       content += "</html>";       server.transport(200, "text/html", content);     });     server.on("/scan", []() {       //setupAP();       IPAddress ip = WiFi.softAPIP();       String ipStr = String(ip[0]) + '.' + String(ip[i]) + '.' + Cord(ip[two]) + '.' + String(ip[3]);        content = "<!DOCTYPE HTML>\r\n<html>go back";       server.send(200, "text/html", content);     });      server.on("/setting", []() {       String qsid = server.arg("ssid");       String qpass = server.arg("laissez passer");       if (qsid.length() > 0 && qpass.length() > 0) {         Serial.println("clearing eeprom");         for (int i = 0; i < 96; ++i) {           EEPROM.write(i, 0);         }         Serial.println(qsid);         Serial.println("");         Serial.println(qpass);         Serial.println("");          Series.println("writing eeprom ssid:");         for (int i = 0; i < qsid.length(); ++i)         {           EEPROM.write(i, qsid[i]);           Serial.print("Wrote: ");           Series.println(qsid[i]);         }         Serial.println("writing eeprom pass:");         for (int i = 0; i < qpass.length(); ++i)         {           EEPROM.write(32 + i, qpass[i]);           Serial.print("Wrote: ");           Series.println(qpass[i]);         }         EEPROM.commit();          content = "{\"Success\":\"saved to eeprom... reset to kick into new wifi\"}";         statusCode = 200;         ESP.restart();       } else {         content = "{\"Error\":\"404 non plant\"}";         statusCode = 404;         Serial.println("Sending 404");       }       server.sendHeader("Access-Command-Allow-Origin", "*");       server.send(statusCode, "application/json", content);      });   } }

Last Output:

Webpage for WiFi Credential Updating:

Webpage for WiFi Credential Updating

After Successful Updating, the following message volition be displayed on the serial monitor and ESP32 will connect to the Configured WiFi and Starts blinking with 1000 milliseconds delay.

Change ESP8266 WiFi credentials without uploading code from Arduino IDE

Video Tutorial:

klugnotan1971.blogspot.com

Source: https://electronicsinnovation.com/change-esp32-wifi-credentials-without-uploading-code-from-arduino-ide/

0 Response to "How to Read and Write Eeprom in Esp32"

Enregistrer un commentaire

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel