Go Down

Topic: Problem writing/reading string in EEPROM (Read 977 times) previous topic - next topic

stoianvictor618

Hello guys!
I want to store in EEPROM my Wi-Fi's  ssid and password, but I have difficulties doing that.
Please, can you have a look over my code, to tell me why can't read string back? Thank you!!!
Code: [Select]

#include<EEPROM.h>
char ssid[]="my_wifi";
char pass[30];

void setup()
 {
  Serial.begin(9600);
  setSSID();
 }


void loop(){;}


void setSSID()
  {
   byte l=strlen(ssid);
   EEPROM.write(1,l);
   byte x=0;
   int i=24;

   while(i<i+l)
      {
       EEPROM.write(i,ssid[x++]);
       delay(4);
       i++;
      }

   char readBack[l+1];
   byte y=0;
   int j=24;
   while(j<j+l)
      {
       readBack[y++]=EEPROM.read(j);
       j++;
      }
   
   readBack[y]='\0';
   Serial.print("\n This is the Network's SSID:  ");
   Serial.print(readBack);
  }


























wvmarle

If you're using an ESP8266 it will store the last connected credentials by itself, no need to try and store it yourself.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

stoianvictor618

Yes, I will use ESP8266,but anyway,I want to write this function in case that I will  use also Arduino
Wi-Fi Shield, and for general purposes of using EEPROM,other than storing network configuration.
 

Gippopotam


stoianvictor618

At this very moment I am only sure that I need any help I can get. :)

stoianvictor618

i know that somothing is wrong somewhere.
Any way, I've started from from this premise: the "ssid" and "pass" arrays will be initiated from
Serial Monitor and I don't know the length of them.

wvmarle

Do look up the EEPROM documentation - especially the EEPROM.put() and EEPROM.get() functions. Those make storage easy.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up