title: ESP32 writing string to EEPROM
body: <p>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.</p>
  <p>I have no problems saving integer value to EEPROM as following:</p>
  <pre><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, &quot;Serial&quot;);
  
      cJSON* quantity = cJSON_GetObjectItem(jsonObj, &quot;Quantity&quot;);
  
       //Get integer value - other fields allow access to strings, floats etc.
  
  
  
      strcpy(item_inside.serial,serial-&gt;valuestring);
  
      item_inside.quantity = quantity-&gt;valueint;
  
  
  
      EEPROM.put(2, item_inside.quantity);
  
      Serial.print(&quot;Checking serial before puting to eeprom=&quot;);
  
      Serial.println(item_inside.serial);
  
      EEPROM.put(4, item_inside.serial);
  
      //EEPROM.write(4,item_inside.serial);
  
  
  
      EEPROM.commit();
  
  
  
      Serial.print(&quot;ITEM_INSIDE_QUANTITY=&quot;);
  
      Serial.println(EEPROM.read(2));
  
  
  
  
  
  
  
      Serial.print(&quot;ITEM_INSIDE_SERIAL READ=&quot;);
  
      Serial.println(EEPROM.read(4));
  
      Serial.print(&quot;ITEM_INSIDE_SERIAL get=&quot;);
  
      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></pre>
  <p>However, when I try to put a string variable ( item_inside.serial)</p>
  <pre><code>EEPROM.put(4, item_inside.serial);
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/d7o1e.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>As you can see both functions, EEPROM.read and EEPROM.get did not work</p>
  <p>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.</p>
  <p>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</p>