Last active
January 8, 2018 12:05
-
-
Save Ozsie/980416e8c047c6a21a7f78dc280b45f3 to your computer and use it in GitHub Desktop.
EEPROM storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "wifitemp.h" | |
void storeEeprom() { | |
EEPROM.begin(eepromSize); | |
EEPROM.put(0, conf); | |
char ok[2+1] = "OK"; | |
EEPROM.put(0+sizeof(conf), ok); | |
bool commited = EEPROM.commit(); | |
EEPROM.end(); | |
Serial.print("Commit result: "); | |
Serial.println(commited); | |
} | |
void loadEeprom() { | |
EEPROM.begin(eepromSize); | |
EEPROM.get(0, conf); | |
char ok[2+1]; | |
EEPROM.get(0+sizeof(conf), ok); | |
EEPROM.end(); | |
if (String(ok) != String("OK")) { | |
Serial.println("Recovery not OK or nothing stored yet."); | |
conf.wifiSsid[0] = 0; | |
conf.wifiPassword[0] = 0; | |
} else { | |
Serial.println("Recovered credentials"); | |
Serial.print("SSID: "); | |
Serial.println(conf.wifiSsid); | |
Serial.print("Password: "); | |
Serial.println(strlen(conf.wifiPassword)>0?"********":"<no password>"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment