I now save the OTAA-params in flash also and it works for me. Maybe there is an easier solution, but at least it works.
Variable declaration without initialization:
/* OTAA para*/
uint8_t devEui[8];
uint8_t appEui[8];
uint8_t appKey[16];
In setup function:
// read config_data from flash...
ReadConfigDataFromFlash();
memcpy(devEui, config_data.devEui, sizeof(config_data.devEui));
memcpy(appEui, config_data.appEui, sizeof(config_data.appEui));
memcpy(appKey, config_data.appKey, sizeof(config_data.appKey));
User command to write to flash:
if (strcmp(cmd, "SAVE_OTAA_CONFIG") == 0)
{
if (content[0] == '1')
{
memcpy(config_data.devEui, devEui, sizeof(devEui));
memcpy(config_data.appEui, appEui, sizeof(appEui));
memcpy(config_data.appKey, appKey, sizeof(appKey));
WriteConfigDataToFlash();
Serial.printf("saved OTAA configuration to flash\n");
}
return true;
}