24 bool valid()
const {
return data_.magic == kMagic && data_.ssid[0] != 0; }
28 memset(&data_, 0,
sizeof(data_));
30 snprintf(data_.ssid,
sizeof(data_.ssid),
"%s",
ssid ?
ssid :
"");
31 snprintf(data_.password,
sizeof(data_.password),
"%s",
password ?
password :
"");
37 memset(&data_, 0,
sizeof(data_));
42 const char*
ssid()
const {
return data_.ssid; }
45 const char*
password()
const {
return data_.password[0] ? data_.password :
nullptr; }
48 static constexpr uint32_t kMagic = 0x54574431;
60 EEPROM.begin(
sizeof(Data));
67 return EEPROM.commit();
Keeps the name and password of one WiFi network in flash.
bool forget()
Removes the saved network. False if the flash could not be written.
bool load()
Reads the flash. Returns true if a network is saved.
const char * ssid() const
Name of the saved network.
bool valid() const
True if a network is saved (after load() or save()).
bool save(const char *ssid, const char *password)
Saves the network; an empty or null password means an open network. False if the flash could not be w...
const char * password() const
Password of the saved network, nullptr if it is an open network.