Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266-WROOM-02D EEPROM issue #7719

Closed
6 tasks
pravinzende12 opened this issue Nov 24, 2020 · 3 comments
Closed
6 tasks

ESP8266-WROOM-02D EEPROM issue #7719

pravinzende12 opened this issue Nov 24, 2020 · 3 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@pravinzende12
Copy link

pravinzende12 commented Nov 24, 2020

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP-WROOM-02D
  • Core Version: [latest git hash or date]
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: ESP-WROOM-02D
  • Flash Mode: [Standard SPI, DIO (Dual I/O), DOUT (Dual)]
    Output), QIO (Quad I/O) and QOUT (Quad Output)]
  • Flash Size: [2-MB SPI flash]
  • lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz|160MHz]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [115200|other] (serial upload only)

Problem Description

After writing on memory by SSID & Password for Wi-fi
when there is power off module gets reset & flsh gets
erased with SSID & Password any one having idea for this

Edit by @devyte : attached zip files removed.
Please include a MCVE as part of the post.

MCVE Sketch

Code is attached

#include "main.h"


#define CREDENTIALS_FLAG               1
#define CREDENTIALS_START_ADDRESS      2


bool credentialsAvailableFlag = false;


typedef struct{
  char ssid[32];
  char password[64];
  char qrCode[20];
}UserCredentials_t;


UserCredentials_t wifiCredentials;


WiFiServer server(8080);      
WiFiClient client;

void setup()
{
  EEPROM.begin(512);                                                            //EEPROM initialized
  Serial.begin(11520);                                                          //Serial port for debug
  Serial.println("Hindware Test program for EEPROM issue - 19112020");  
  if(EEPROM.read(CREDENTIALS_FLAG) == 1)                                        //will read credentials flag at power on 
  {                                                                               //if 1 then credentials available
    credentialsAvailableFlag = true;                                              // if not 1 then credentials not available
  } 
  else
  {
    credentialsAvailableFlag = false;
  }
}

void loop()
{
  /*
   * if credentials available then read the credentials from EEPROM
   * if not available then initialize hotspot mode and wait for credentials from user through TCP
   */
  if(credentialsAvailableFlag)                    
  {
    ReadCredentialsFromEeprom();                                                
    ConnectToRouter();
  }
  else
  {
    SetHotspot();
    WaitForCredentials();
  }
}


void ConnectToRouter(void)
{
   WiFi.mode(WIFI_STA);                                           //will connect to the router whose credentials have been read from EEPROM
   WiFi.begin(wifiCredentials.ssid,wifiCredentials.password);
   Serial.print("Connecting to ");
   Serial.println(wifiCredentials.ssid);
}

void ReadCredentialsFromEeprom(void)
{
  EEPROM.get(CREDENTIALS_START_ADDRESS,wifiCredentials);    // reading credentials from EEPROM and savind it in struct
}



void SetHotspot(void)
{
    WiFi.mode(WIFI_AP);                       //Initialize Hotspot with crendentials as SSID: HotspotName | Paasword: password 
    IPAddress local_IP(192, 168, 1, 1);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress subnet(255, 255, 255, 0);
    WiFi.softAPConfig (local_IP, gateway, subnet);
    WiFi.softAP("HotspotName", "password" , 1, false , 1);
    server.begin();
}

void WaitForCredentials(void)
{
  while(client.connected())     //if client connected at 192.168.1.1:8080
  {
    if (client.available())
    {
      String tempBuffWifiDirect = client.readStringUntil('\r\n\r\n');              //will read data printed on local IP
      Serial.println(tempBuffWifiDirect);
                                                                                // packet recieved {"SSID":"userssid","Password":"userpassword","QRcodeSerial":"12345"}
      StaticJsonBuffer<1000> jsonBuffer;                                          //parse the received JSON
      JsonObject& root = jsonBuffer.parseObject(tempBuffWifiDirect);
      
      if (root.success())          //if credentials JSON  parsing is Successful
      {
        const char* ssidTempBuff = "";
        const char* pwdTempBuff = "";
        const char* qrCodeSerial = "";
        ssidTempBuff = root["SSID"];
        pwdTempBuff = root["Password"];
        qrCodeSerial = root["QRcodeSerial"];
        Serial.println("Received Credentials:");
        Serial.println("SSID: " + (String)ssidTempBuff);
        Serial.println("Password: " + (String)pwdTempBuff);
        Serial.println("QRCode: " + (String)qrCodeSerial);
        memset(wifiCredentials.ssid, 0, sizeof(wifiCredentials.ssid));
        memset(wifiCredentials.password, 0, sizeof(wifiCredentials.password));
        memset(wifiCredentials.qrCode, 0 , sizeof(wifiCredentials.qrCode));
        strcpy(wifiCredentials.ssid, ssidTempBuff);
        strcpy(wifiCredentials.password, pwdTempBuff);
        strcpy(wifiCredentials.qrCode, qrCodeSerial);
        SetCredentialsToEeprom();              //save credentials to EEPROM
        credentialsAvailableFlag = true;        // set flad to read from EEPROM and connect to router
      }  
    }
  } 
}

void SetCredentialsToEeprom(void)
{
  EEPROM.put(CREDENTIALS_START_ADDRESS,wifiCredentials); //save credentials
  EEPROM.write(CREDENTIALS_FLAG,(int)1);                  //save credentials flag 1 so it connecets to router from next power on

  EEPROM.commit();    //commit to EEPROM
}
@devyte
Copy link
Collaborator

devyte commented Nov 24, 2020

@pravinzende12 please don't attach zip files and add your MCVE directly to your post above.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Nov 24, 2020
@pravinzende12
Copy link
Author

pravinzende12 commented Nov 25, 2020

ok attached MCVE file

@Tech-TX
Copy link
Contributor

Tech-TX commented Nov 28, 2020

Two issues in 2 days with corrupt EEPROM on a WROOM-02D, and neither of them apparently read #6551

Sounds like a school project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

4 participants