the purpose of the keyword is to know if what is in EEPROM can be somewhat trusted to be your sensor addresses. it's just bytes at the end of the day... So the code first checks if there is a known value in a known location of the EEPROM --> I use tmpKey to extract whatever is at the location of the keyword and use it to compare its value with 0xDEADBEEF. If it finds this value, it assumes that the sensor addresses are correct. if it does not find the keyword, then the code initializes the sensor addresses with the default ones and write them in EEPROM for the next time.
you can keep 0xDEADBEEF if you want, but if you use the same technics on the same Arduino later for something else, then the code will believe the memory has already been initialized. So make up one code for each sketch.
the EEPROM.put() method writes data on EEPROM using the EEPROM.update()method. so it only writes the bytes that have changed but it's smarter as it adapts to the type of the data you pass (here a structure, so I don't have to deal with the individual bytes)
PS: on second thoughts it's probably better to write
void saveParam()
{
EEPROM.put(paramAddress, myParamters);
EEPROM.put(keywordAddress, keyword);
}
so that the keyword is only written once the parameters have actually been written (in case of power failure right at that time)
ideally you would want to erase the keyword before an update — just in case the updates fails in the middle — and write it back again at the end.. or use a smarter approach with 2 areas to update the parameters...
but as a start that's good enough ![]()