Open Lithimlin opened 4 years ago
Any idea what could be causing this? I'm trying to understand the library atm to see if I find the issue and am possibly able to fix it.
So the issue seems to lie with this method:
void WiFiManager::doParamSave(){
// @todo use new callback for before paramsaves, is this really needed?
if ( _presavecallback != NULL) {
_presavecallback();
}
//parameters
if(_paramsCount > 0){
DEBUG_WM(DEBUG_VERBOSE,F("Parameters"));
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL || _params[i]->_length == 0) {
DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope");
break; // @todo might not be needed anymore
}
//read parameter from server
String name = (String)FPSTR(S_parampre)+(String)i;
String value;
if(server->hasArg(name)) {
value = server->arg(name);
} else {
value = server->arg(_params[i]->getID());
}
//store it in params array
value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated
DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value);
}
DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR));
}
if ( _saveparamscallback != NULL) {
_saveparamscallback();
}
}
and the saveParamCallback
in the example. I added two lines to reset the value afterwards in the example:
void saveParamCallback(){
Serial.println("[CALLBACK] saveParamCallback fired");
Serial.println("PARAM customfieldid = " + getParam("customfieldid"));
String value = "Custom Field Value";
custom_field.setValue(value.c_str(), value.length());
}
I have the same problem. Someone managed to solve?
is it an issue with ids? There was a similar issue reported
iirc, this was indeed an issue with the IDs. I think #1130 fixed it. Though it's been a while so no guarantees.
I know this thread is old but i run into the same issue. I have some checkboxes with const hidden ip address but if the user don't enable the check box the value of this uncheck checkbox will be overwritten with an empty string. So I don't thing this issue is fixed.
Maybe its not important but all parameters are global.
main.cpp
const char* title_str = "<br/><label style='font-weight: bold; font-size: 25px;'>NTP Server Auswahl</label><br/>";
const char* lineBreak_str = "<br/><br />";
const char* tu_berlin_ip = "130.149.7.7";
const char* tu_dresden_ip = "141.76.32.160";
const char* t_online_ip = "194.25.134.196";
const char* custom_0_ip = "000.000.000.000";
new (&title) WiFiManagerParameter (title_str);
new (&tu_berlin_ntp_server) WiFiManagerParameter("tu_berlin_ntp_server", "TU Berlin", tu_berlin_ip, strlen(tu_berlin_ip), checkbox_unchecked, WFM_LABEL_AFTER); // custom html input for tu berlin ntp server
new (&tu_dresden_ntp_server) WiFiManagerParameter("tu_dresden_ntp_server", "TU Dresden", tu_dresden_ip, strlen(tu_dresden_ip), checkbox_unchecked, WFM_LABEL_AFTER); // custom html input for tu dresden ntp server
new (&t_online_ntp_server) WiFiManagerParameter("t_online_ntp_server", "T-Online", t_online_ip, strlen(t_online_ip),checkbox_checked, WFM_LABEL_AFTER); // custom html input for t-online ntp server
new (&lineBreak) WiFiManagerParameter (lineBreak_str);
new (&custom_0_ntp_server) WiFiManagerParameter("custom_0_ntp_server", "NTP Server IP:", NULL, strlen(custom_0_ip), "placeholder=\"000.000.000.000\"");
wm.addParameter(&title);
wm.addParameter(&tu_berlin_ntp_server);
wm.addParameter(&tu_dresden_ntp_server);
wm.addParameter(&t_online_ntp_server);
wm.addParameter(&lineBreak);
wm.addParameter(&custom_0_ntp_server);
wm.setPreSaveParamsCallback(saveParamCallback);
wm.setSaveParamsCallback(saveParamCallback);
callback function
const char* getParam(const char* name){
//read parameter from server, for customhmtl input
if (wm.server->hasArg(name)) {
String value = wm.server->arg(name);
return value.length() > 0 ? value.c_str() : nullptr;
}
else {
return nullptr;
}
}
void saveParamCallback(void) {
static char* lost_ips[3];
static int lost_len[3];
uint8_t lost_cnt = 0;
static bool preSave = true;
preSave ? Serial.println("[CALLBACK] savePreParamCallback fired") : Serial.println("[CALLBACK] saveParamCallback fired");
preSave = ! preSave;
for (uint8_t i = 0; i < wm.getParametersCount(); i++) {
const char* name = wm.getParameters()[i]->getID();
if (name) {
const char* param = getParam(name);
if (param) {
Serial.println(String(i) + " was checked");
Serial.print("PARAM[" + String(name) + "]: ");
Serial.println(param);
// hier dann die ntp client objecte erstellen
}
else {
const char* value = wm.getParameters()[i]->getValue();
int length = wm.getParameters()[i]->getValueLength();
Serial.println(String(i) + " was nullptr");
Serial.println("val: " + String(value));
Serial.println("len: " + String(length));
//wm.getParameters()[i]->setValue(value,length);
}
}
else {
Serial.println(String(i) + " has no id");
}
Serial.println();
}
}
LOG output
// const hidden ip addresses
130.149.7.7
141.76.32.160
194.25.134.196
// before the data are saved from webserver
[CALLBACK] savePreParamCallback fired
0 has no id
1 was nullptr
val: 130.149.7.7
len: 11
2 was nullptr
val: 141.76.32.160
len: 13
3 was checked
PARAM[t_online_ntp_server]: PARAM[t_online_ntp_server]:
4 has no id
5 was nullptr
val:
len: 15
// after the data are saved from webserver
[CALLBACK] saveParamCallback fired
0 has no id
1 was nullptr
val:
len: 11
2 was nullptr
val:
len: 13
3 was checked
PARAM[t_online_ntp_server]: PARAM[t_online_ntp_server]:
4 has no id
5 was nullptr
val:
len: 15
Basic Infos
Hardware
WiFimanager Branch/Release:
Esp8266/Esp32:
Hardware: ESP-12e, esp01, esp25
ESP Core Version: 2.4.0, staging
Description
I've tried using the checkboxes (as in the "Advanced" example) to enable and disable things on my ESP. While doing that I figured out that once you disable a checkbox and exit the configuration or let the AP timeout, the value saved in the
WiFiManagerParameter
is lost and the checkbox will not work again.How to reproduce
Params
, clicksave
without enabling the checkboxThe value of the checkbox will remain empty even if it is checked
Sketch
"Advanced" example:
Debug Messages