mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-10-18 16:21:28 +08:00
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#ifdef ESP8266
|
|
/** Load WLAN credentials from EEPROM */
|
|
void loadCredentials() {
|
|
EEPROM.begin(512);
|
|
EEPROM.get(0, ssid);
|
|
EEPROM.get(0+sizeof(ssid), password);
|
|
char ok[2+1];
|
|
EEPROM.get(0+sizeof(ssid)+sizeof(password), ok);
|
|
EEPROM.end();
|
|
if (String(ok) != String("OK")) {
|
|
ssid[0] = 0;
|
|
password[0] = 0;
|
|
}
|
|
Serial.println("Recovered credentials:");
|
|
Serial.println(ssid);
|
|
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
}
|
|
|
|
/** Store WLAN credentials to EEPROM */
|
|
void saveCredentials() {
|
|
EEPROM.begin(512);
|
|
EEPROM.put(0, ssid);
|
|
EEPROM.put(0+sizeof(ssid), password);
|
|
char ok[2+1] = "OK";
|
|
EEPROM.put(0+sizeof(ssid)+sizeof(password), ok);
|
|
EEPROM.commit();
|
|
EEPROM.end();
|
|
}
|
|
#else
|
|
/** Load WLAN credentials from Preferences */
|
|
void loadCredentials() {
|
|
preferences.getString("ssid", ssid, sizeof(ssid));
|
|
preferences.getString("password", password, sizeof(password));
|
|
Serial.println("Recovered credentials:");
|
|
Serial.println(ssid);
|
|
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
}
|
|
|
|
/** Store WLAN credentials to Preference */
|
|
void saveCredentials() {
|
|
preferences.putString("ssid", ssid);
|
|
preferences.putString("password", password);
|
|
Serial.println("Saved credentials:");
|
|
Serial.println(ssid);
|
|
Serial.println(strlen(password)>0?"********":"<no password>");
|
|
}
|
|
#endif
|