Advertisement
sspence65

esp8266 eeprom get

Jun 20th, 2018
292
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <EEPROM.h>
  2. int eeAddress = 0; //EEPROM address to start reading from
  3.  
  4.  
  5. void setup() {
  6.  
  7.  
  8. Serial.begin(9600);
  9.  
  10. EEPROM.begin(1024);
  11.  
  12. //Get the float data from the EEPROM at position 'eeAddress'
  13.  
  14.  
  15.  
  16. /***
  17. Get can be used with custom structures too.
  18. I have separated this into an extra function.
  19. ***/
  20.  
  21. secondTest(); //Run the next test.
  22. }
  23.  
  24. struct MyObject {
  25. char ssid[20];
  26. char password[20];
  27.  
  28. };
  29.  
  30. void secondTest() {
  31.  
  32. MyObject customVar; //Variable to store custom object read from EEPROM.
  33. EEPROM.get(eeAddress, customVar);
  34.  
  35. Serial.println("Read custom object from EEPROM: ");
  36. Serial.println(customVar.ssid);
  37. Serial.println(customVar.password);
  38.  
  39. }
  40.  
  41. void loop() {
  42. /* Empty loop */
  43. }
Advertisement
RAW Paste Data Copied
Advertisement