Hello. I need to save some data to EEPROM because I want to retain that value even when the device is switched OFF. When the device is powered again, I need to remember what was the last value.
I have no problems saving integer value to EEPROM as following:
However, when I try to put a string variable ( item_inside.serial)
As you can see both functions, EEPROM.read and EEPROM.get did not work
Also, can someone help me understand when should I use EEPROM.write and EEPROM.put. Both of these seem to work fine for integer variable, However, EEPROM.write does not compile with string as it expects integer.
Also, is using EEPROM.read correct in this case , or should I use EEPROM.get function instead as I am not sure what are the differences
I have no problems saving integer value to EEPROM as following:
Code:
void parse_item_inside(char* payload){
cJSON* jsonObj = cJSON_Parse((char*)(payload));
// Get pointer to specific field in JSON object
cJSON* serial = cJSON_GetObjectItem(jsonObj, "Serial");
cJSON* quantity = cJSON_GetObjectItem(jsonObj, "Quantity");
//Get integer value - other fields allow access to strings, floats etc.
strcpy(item_inside.serial,serial->valuestring);
item_inside.quantity = quantity->valueint;
EEPROM.put(2, item_inside.quantity);
Serial.print("Checking serial before puting to eeprom=");
Serial.println(item_inside.serial);
EEPROM.put(4, item_inside.serial);
//EEPROM.write(4,item_inside.serial);
EEPROM.commit();
Serial.print("ITEM_INSIDE_QUANTITY=");
Serial.println(EEPROM.read(2));
Serial.print("ITEM_INSIDE_SERIAL READ=");
Serial.println(EEPROM.read(4));
Serial.print("ITEM_INSIDE_SERIAL get=");
Serial.println(EEPROM.get(4,local_serial));
OLED_display(item_inside.quantity,number_to_pick);
// Delete JSON object (don't forget this)
cJSON_Delete(jsonObj);
}
Code:
EEPROM.put(4, item_inside.serial);
As you can see both functions, EEPROM.read and EEPROM.get did not work
Also, can someone help me understand when should I use EEPROM.write and EEPROM.put. Both of these seem to work fine for integer variable, However, EEPROM.write does not compile with string as it expects integer.
Also, is using EEPROM.read correct in this case , or should I use EEPROM.get function instead as I am not sure what are the differences
Attachments
-
7.2 KB Views: 5
Last edited: