System checks eeprom for magic bytes. If magic bytes are different then set structure values to default values. Essentially I want to set email to empty by default.
@StngBo, for the initialization, you can let the compiler do the work:
// Create a struct typedef named eepromConfig with the defined member variables
typedef struct eepromConfig {
uint32_t magic;
char email[40];
};
// Create a global structure variable of the type previously defined and assign values to each member
eepromConfig config_data = { DATA_MAGIC, "" };
However, for the Particle.function(), command is an Arduino String while config is a c-string. As such, you need to use the c_str() function of the String class to convert it to a c-string:
int setEmail(String command) {
strcpy (config_data.email, command.c_str());
storeConfigVariables(); // This just writes the struct to eeprom
return 1;
}
An alternative to Paul’s suggestions (with the benefit to not overshoot the array boundaries )
int setEmail(const char* command) {
int retVal = strncpy(config_data.email, command, sizeof(config_data.email)-1);
...
return retVal; // use the return value to communicate something at least
// somewhat useful like the length of the actually copied string
// or the result of the storeConfigVariables() call
}
works just as well.
Additionally, if you ever want to wipe the content of the array entirely you can use