Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

added public methods to load and save dynamic data #28

Merged
merged 9 commits into from
Jan 13, 2023
48 changes: 48 additions & 0 deletions src/ESP_WiFiManager_Lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,47 @@ class ESP_WiFiManager_Lite

//////////////////////////////////////

#if USE_DYNAMIC_PARAMETERS

bool extLoadDynamicData()
{
#if ESP8266
// SPIFFS and LittleFS do auto-format if not yet
if (!FileFS.begin())
#else
// Format SPIFFS if not yet
if (!FileFS.begin(true))
#endif
{
ESP_WML_LOGERROR(F("SPIFFS/LittleFS failed!"));
return false;
}

return loadDynamicData();
}

//////////////////////////////////////////////

void extSaveDynamicData()
{
#if ESP8266
// SPIFFS and LittleFS do auto-format if not yet
if (!FileFS.begin())
#else
// Format SPIFFS if not yet
if (!FileFS.begin(true))
#endif
{
ESP_WML_LOGERROR(F("SPIFFS/LittleFS failed!"));
return;
}

saveDynamicData();
}

#endif

//////////////////////////////////////

private:
String ipAddress = "0.0.0.0";
Expand All @@ -1290,6 +1331,7 @@ class ESP_WiFiManager_Lite

unsigned long configTimeout;
bool hadConfigData = false;
bool hadDynamicData = false;

bool isForcedConfigPortal = false;
bool persForcedConfigPortal = false;
Expand Down Expand Up @@ -1675,6 +1717,11 @@ class ESP_WiFiManager_Lite

bool loadDynamicData()
{
if (hadDynamicData)
{
return true;
}

int checkSum = 0;
int readCheckSum;
totalDataSize = sizeof(ESP_WM_LITE_config) + sizeof(readCheckSum);
Expand Down Expand Up @@ -1727,6 +1774,7 @@ class ESP_WiFiManager_Lite
return false;
}

hadDynamicData = true;
return true;
}

Expand Down