//void setup(){
//Same as in original example script.
}
void loop(){
/* read configuration struct from flash */
byte* b = dueFlashStorage.readAddress(4); // byte array which is read from flash at adress 4
Configuration configurationFromFlash; // create a temporary struct
memcpy(&configurationFromFlash, b, sizeof(Configuration)); // copy byte array to temporary struct
char string[]="Name=Marcus&greeting=goodmorning";
char* Name=parsePostData("Name",string); // See function below.
Serial.print(" message:");
Serial.print(configurationFromFlash.message);
configurationFromFlash.message = Name;//This is causing problems in Case 1 inside below function.
// write configuration struct to flash at adress 4
byte b2[sizeof(Configuration)]; // create byte array to store the struct
memcpy(b2, &configurationFromFlash, sizeof(Configuration)); // copy the struct to the byte array
dueFlashStorage.write(4, b2, sizeof(Configuration)); // write byte array to flash
}
char* parsePostData(char s[],char t[])
{
char *pch;
char *pp="Marcus";
char tCpy[512];//Make a copy. Otherwise, strtok works on the char pointer, and original char array gets modified/ corrupted.
strcpy(tCpy,t);
pch = strtok (tCpy,"=&");
while (pch != NULL)
{
if(strcmp(pch,s)==0) {
pch= strtok (NULL, "&");
//**Case 1. what I need. but it is causing issues
//after I write to flash, and restart the board.**
//return pch;
return stdup(pch);
//Case 2. Forced test case. works perfect. Even after board is reset, values are correct.
//return pp;
}else{
pch = strtok (NULL, "=&");
}
}
}```