PDA

View Full Version : Question using EEPROM



brian25
08-14-2013, 12:18 AM
How to save the password in eeprom? when the device is turn off the pass was still in the chip.
and what syntax to use for changing the password?

tnx



char p1[] = {"11111"};

void Password(){

char p2[5];
int y = sizeof(p1);
int flag=0;

for (int x=0;x<=y;x++)
{
p2[x]= p1[x];
}


if(gsm.readSMS(smsbuffer, 5, p2, 5) == 0)
flag=1;
{
if(strstr(smsbuffer,"11111") != NULL){
Serial.println(strcmp(smsbuffer,"Matched"));
}
else if(strstr(smsbuffer," ") != NULL){
flag=2;


}
}
if(flag==2){
Serial.println(strcmp(smsbuffer,"Matched"));
delF();
}
else if(flag==1){
Serial.println(strcmp(smsbuffer,"Don't Matched"));
delF();

}
}

void delF()
{
Serial.println("Executing delete");
for (int j=0;j<=4;++j){
Serial.println(sms.DeleteSMS(j));
}
}

jwatte
08-14-2013, 12:20 AM
sizeof(p1) is 6, because it includes the terminating 0. You only allocate 5 characters for p2. That means you're overwriting the stack, which can cause various undefined behavior that's hard to track down.

To save data to the eeprom, check out the <eeprom.h> header in avr-libc (I'm assuming you're using this library?)
Or the EEPROM module (if you're using Arduino.)