Changing the devEui

in amongst my code there is an option to push a new DevEui, this is stored in eeprom and loaded when the system boots.

After changing the setting I do a HW_Reset(0);

However after comming back up the unit is still using the old devEui and even a power cycle will not set the new devEui.

Am i missing something?

how do you store this in eeprom?

Storing the data is noting special, I have defined the locations because they will never change
#define memLoc_devEui 0
#define memLoc_appEui 8
#define memLoc_appKey 16

Saving the settings…

void saveSettings(){ 
  Serial.println("saving config");
  EEPROM.begin(512);
  int memLoc = 0;
  EEPROM.put(memLoc_devEui, devEui);
  EEPROM.put(memLoc_appEui, appEui);
  EEPROM.put(memLoc_appKey, appKey);
  EEPROM.end();
  Serial.println("config saved");
}

loading the settings

  void loadSettings(){
  Serial.println("get config");
  EEPROM.begin(512);
  EEPROM.get(memLoc_devEui, devEui);
  EEPROM.get(memLoc_appEui, appEui);
  EEPROM.get(memLoc_appKey, appKey);
  EEPROM.end();
  Serial.println("config set");
}

I think i just found a solution, when i push the new settings to the device doing an

LoRaWAN.init(loraWanClass,loraWanRegion);

instead of doing a restart seems to work.

And the change is instant allthough the settings dont seem to revert back to the older ones on reboot.

Not at the PC right now, but don’t you miss a EEPROM.commit?

Yes, just verified it:

void saveSettings(){ 
  Serial.println("saving config");
  EEPROM.begin(512);
  int memLoc = 0;
  EEPROM.put(memLoc_devEui, devEui);
  EEPROM.put(memLoc_appEui, appEui);
  EEPROM.put(memLoc_appKey, appKey);
  EEPROM.commit();
  EEPROM.end();
  Serial.println("config saved");
}

You could also use a union which makes it easier to check if config was saved correctly. And I would use a checksum to verify if your config is valid. Especially useful with new devices or if you change something in the EEPROM organisation to avoid devices trying to join forever and blocking the join frequencies.

EEPROM.end() has EEPROM.commit() already built in so you dont need to call it is you are using .end() I also decided ot use .put() over .write() because if the data is the same it’s not overwritten handy when you are only updating one of the items and not all of them.

I ended up removing the config from the system for the time being as the only way I could get it to stick was to turn off the OTAA mode. even then as soon as OTAA was turned back on the settings would go back to what they were. Im assuming OTAA was getting them from flash.

I have used the saveSettings to update and save the cycle time, trigger levels etc. and will look at adding a union as well as a checksum once I have worked out how to apply thse changes to the system either while its running in OTAA or before turning it back on again.