Hi there!
I'm very confused with char variables.
I have a struct
struct smsConfig
{
byte version;
byte smsMode;
char *times[10];
char *mobiles[4];
} config = {200, 1, {"15:00"}, {}};
I don't know if char's are declared rightly. I don't know if I can delcare something like char times[10]5];
What I want:
times: 10 rows and each row will contain from 1 to 5 chars. Example
config.times[0]="1";
config.times[1]="13:34";
config.times[2]="1:00"; //it's same with first row
mobiles: 4 rows and each row will contain from 10 to 12 chars. Example
config.mobiles[0]="6987654321";
config.mobiles[1]="306987654321";
I use the the Arduino Playground - EEPROMWriteAnything
The main problem is that I store the data, and on EEPROM read, char variables are not stored exactly or random chars are displayed.
commands are parsed through SMS message that is a String.
So what I have done
Version check
Serial.begin(9600);
while (!Serial);
EEPROM_readAnything(0, config);
//check if ever stored on EEPROM
if (config.version != 200)
{
smsConfig config = {200, 1, {"15:00"}, {}}; //Write default
EEPROM_writeAnything(0, config);
Serial.println(F("Default Configuration loaded"));
}
byte c=0;
for (byte i = 0; i < countof(config.mobiles); i++)
{
//newValue = getValue(cmd, ' ', i); //spliting and returning substring ex:
newValue="306978932198";
if (newValue.length() > 9 && newValue.length() < 14)
{
if (newValue.substring(0, 1) == "+") newValue = newValue.substring(1); //remove +
Serial.println("NewMobile["+String(c)+"]:" + newValue);
config.mobiles[c] = string2char(newValue);
c++;
storeConfig = 1;
}
}
if(storeConfig) EEPROM_writeAnything(0, config);
"NewValue" values parsed correctly: IMAGE PARSED VALUES but returns similar or cutted
IMAGE STORED VALUES
Same with times:
times issue IMAGE
In other words...
String to char does not work for me when is stored to epprrom
If don't pass string to config.mobiles
and I write the value in the code works...is going crazy! Ex.
config.mobiles[0] ="value-10length";
I tried
config.mobiles[c] = string2char(newValue); //https://coderwall.com/p/zfmwsg/arduino-string-to-char
config.mobiles[c] = newValue.c_str();
no luck....
ANY CLUE?
It supposed EEPROM_writeAnything can write anything