Closed hmueller01 closed 1 year ago
Hi @hmueller01
Thanks for your precious time to make the PR.
But sorry I think this way is too drastic, and requires much more time to test, verify to be sure OK and not breaking anything.
I suggest you just create 2 new public functions, such as
bool extLoadDynamicData(bool forceLoad = false)
{
// Condition to be satisfied before calling this
if (checking_everything_OK)
{
return loadDynamicData(forceLoad);
}
else
{
ESP_WML_LOGERROR("Some error");
return false;
}
}
void extSaveDynamicData()
{
// similar checking, etc before calling saveDynamicData()
// Condition to be satisfied before calling this
if (checking_everything_OK)
{
saveDynamicData();
}
else
{
ESP_WML_LOGERROR("Some error");
}
}
then you can do whatever you'd like without worrying breaking anything.
It took me much time to implement the feature in way of this PR. For the moment it works good for me so I do not like to do more work on this. I'll keep my branch and can merge to your main any time.
BTW your suggestion won't work. I added hadDynamicData
to avoid loading dynamic data a second time. This needs to be located in your private methods. And this is important to avoid loading data a second time while changed and possibly not yet saved data are in RAM. So the main change needs to be done anyway.
I'll give you an example:
// host_name is in dynamic data and is empty per default
m_wifi_manager->loadDynamicData();
if (os_strlen(host_name) == 0) {
Serial.println(F("host_name was empty, setting default host name"));
os_sprintf(host_name, "ESP-%08X", ESP.getChipId());
m_wifi_manager->saveDynamicData(); // if you forget this before begin() changes are lost without hadDynamicData flag!
}
m_wifi_manager->setConfigPortal(host_name, "password");
// Set customized DHCP HostName
m_wifi_manager->begin(host_name);
See discussion #17. Also added a flag to not load data twice, if already loaded. Also renamed
CREDENTIALS_FILENAME
andwm_cred.dat
toDYNAMIC_DATA_FILENAME
andwm_dynamic.dat
to align with method names (the credentials are stored inCONFIG_FILENAME
). I tested/compiled the code on ESP8266 with LittleFS and EEPROM. What I did not check is ESP32, as I do not have the dev env.