Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Custom Field Value" from array not working #1785

Open
namork opened this issue Dec 15, 2024 · 0 comments
Open

"Custom Field Value" from array not working #1785

namork opened this issue Dec 15, 2024 · 0 comments

Comments

@namork
Copy link

namork commented Dec 15, 2024

Basic Infos

Hardware

WiFimanager Branch/Release: Master 2.0.17

Esp32:

Hardware: m5coreink

Core Version: ?

Description

we would like to store the values from wifi-manager in an array and have them displayed on the captive website.

here is the code:
// new (&custom_field) WiFiManagerParameter("customfieldid", blinds[], "Custom Field Value", customFieldLength,"placeholder="Custom Field Placeholder"");

Settings in IDE

Module: M5CoreInk

Additional libraries:

Sketch

/**

  • WiFiManager advanced demo, contains advanced configurartion options
  • Implements TRIGGEN_PIN button press, press for ondemand configportal, hold for 3 seconds for reset settings.
    */
    #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
    #include <Preferences.h>

#define TRIGGER_PIN 38

Preferences prefs;

// wifimanager can run in a blocking mode or a non blocking mode
// Be sure to know how to process loops with no delay() if using non blocking
bool wm_nonblocking = false; // change to true to use non blocking

WiFiManager wm; // global wm instance
WiFiManagerParameter ip01; // global param ( for non blocking w params )
WiFiManagerParameter ip02; // global param ( for non blocking w params )
WiFiManagerParameter ip03; // global param ( for non blocking w params )
WiFiManagerParameter ip04; // global param ( for non blocking w params )
WiFiManagerParameter ip05; // global param ( for non blocking w params )
WiFiManagerParameter ip06; // global param ( for non blocking w params )
WiFiManagerParameter ip07; // global param ( for non blocking w params )
WiFiManagerParameter ip08; // global param ( for non blocking w params )
WiFiManagerParameter ip09; // global param ( for non blocking w params )
WiFiManagerParameter ip10; // global param ( for non blocking w params )
WiFiManagerParameter ip11; // global param ( for non blocking w params )
WiFiManagerParameter ip12; // global param ( for non blocking w params )
WiFiManagerParameter ip13; // global param ( for non blocking w params )
WiFiManagerParameter ip14; // global param ( for non blocking w params )
WiFiManagerParameter ip15; // global param ( for non blocking w params )
WiFiManagerParameter ip16; // global param ( for non blocking w params )

String blinds[3];

void setup() {

WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Serial.begin(115200);
Serial.setDebugOutput(true);
delay(1000);

Serial.println("\n Starting");

prefs.begin("Array", false); //namespace
prefs.getBytes("SavedIntegers", &blinds, sizeof(blinds));
//prefs.end();

Serial.println(blinds[0]);
Serial.println(blinds[1]);
Serial.println(blinds[2]);

// for (int i = 0; i < 16; i++) { // loop number of blinds}
// Serial.println(blinds[i]);
// }

pinMode(TRIGGER_PIN, INPUT);

// wm.resetSettings(); // wipe settings

if (wm_nonblocking) wm.setConfigPortalBlocking(false);

// add a custom input field
int customFieldLength = 16;
String ein = blinds[0];

new (&ip01) WiFiManagerParameter("ip01", "IP 01", blinds[0], customFieldLength, "placeholder="0.0.0.0"");
new (&ip02) WiFiManagerParameter("ip02", "IP 02", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip03) WiFiManagerParameter("ip03", "IP 03", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip04) WiFiManagerParameter("ip04", "IP 04", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip05) WiFiManagerParameter("ip05", "IP 05", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip06) WiFiManagerParameter("ip06", "IP 06", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip07) WiFiManagerParameter("ip07", "IP 07", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip08) WiFiManagerParameter("ip08", "IP 08", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip09) WiFiManagerParameter("ip09", "IP 09", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip10) WiFiManagerParameter("ip10", "IP 10", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip11) WiFiManagerParameter("ip11", "IP 11", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip12) WiFiManagerParameter("ip12", "IP 12", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip13) WiFiManagerParameter("ip13", "IP 13", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip14) WiFiManagerParameter("ip14", "IP 14", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip15) WiFiManagerParameter("ip15", "IP 15", "", customFieldLength, "placeholder="0.0.0.0"");
new (&ip16) WiFiManagerParameter("ip16", "IP 16", "", customFieldLength, "placeholder="0.0.0.0"");

// test custom html input type(checkbox)
// new (&custom_field) WiFiManagerParameter("customfieldid", "Custom Field Label", "Custom Field Value", customFieldLength,"placeholder="Custom Field Placeholder" type="checkbox""); // custom html type

// test custom html(radio)
//const char* custom_radio_str = "
Custom Field Label One
Two
Three";
//new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input

wm.addParameter(&ip01);
wm.addParameter(&ip02);
wm.addParameter(&ip03);
wm.addParameter(&ip04);
wm.addParameter(&ip05);
wm.addParameter(&ip06);
wm.addParameter(&ip07);
wm.addParameter(&ip08);
wm.addParameter(&ip09);
wm.addParameter(&ip10);
wm.addParameter(&ip11);
wm.addParameter(&ip12);
wm.addParameter(&ip13);
wm.addParameter(&ip14);
wm.addParameter(&ip15);
wm.addParameter(&ip16);

wm.setSaveParamsCallback(saveParamCallback);

// custom menu via array or vector
//
// menu tokens, "wifi","wifinoscan","info","param","close","sep","erase","restart","exit" (sep is seperator) (if param is in menu, params will not show up in wifi page!)
// const char* menu[] = {"wifi","info","param","sep","restart","exit"};
// wm.setMenu(menu,6);
std::vector<const char *> menu = { "wifi", "info", "param", "sep", "restart", "exit" };
wm.setMenu(menu);

// set dark theme
wm.setClass("invert");

//set static ip
// wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn
// wm.setShowStaticFields(true); // force show static ip fields
// wm.setShowDnsFields(true); // force show dns field always

// wm.setConnectTimeout(20); // how long to try to connect for before continuing
wm.setConfigPortalTimeout(30); // auto close configportal after n seconds
// wm.setCaptivePortalEnable(false); // disable captive portal redirection
// wm.setAPClientCheck(true); // avoid timeout if client connected to softap

// wifi scan settings
// wm.setRemoveDuplicateAPs(false); // do not remove duplicate ap names (true)
// wm.setMinimumSignalQuality(20); // set min RSSI (percentage) to show in scans, null = 8%
// wm.setShowInfoErase(false); // do not show erase button on info page
// wm.setScanDispPerc(true); // show RSSI as percentage not graph icons

// wm.setBreakAfterConfig(true); // always exit configportal even if wifi save fails

bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP", "password"); // password protected ap

if (!res) {
Serial.println("Failed to connect or hit timeout");
// ESP.restart();
} else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}

void checkButton() {
// check for button press
if (digitalRead(TRIGGER_PIN) == LOW) {
// poor mans debounce/press-hold, code not ideal for production
delay(50);
if (digitalRead(TRIGGER_PIN) == LOW) {
Serial.println("Button Pressed");
// still holding button for 3000 ms, reset settings, code not ideaa for production
delay(3000); // reset delay hold
if (digitalRead(TRIGGER_PIN) == LOW) {
Serial.println("Button Held");
Serial.println("Erasing Config, restarting");
wm.resetSettings();
ESP.restart();
}

  // start portal w delay
  Serial.println("Starting config portal");
  wm.setConfigPortalTimeout(120);

  if (!wm.startConfigPortal("OnDemandAP", "password")) {
    Serial.println("failed to connect or hit timeout");
    delay(3000);
    // ESP.restart();
  } else {
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
  }
}

}
}

String getParam(String name) {
//read parameter from server, for customhmtl input
String value;
if (wm.server->hasArg(name)) {
value = wm.server->arg(name);
}
return value;
}

void saveParamCallback() {
Serial.println("[CALLBACK] saveParamCallback fired");
Serial.println("PARAM ip01 = " + getParam("ip01"));
Serial.println("PARAM ip02 = " + getParam("ip02"));
Serial.println("PARAM ip03 = " + getParam("ip03"));
Serial.println("PARAM ip04 = " + getParam("ip04"));
Serial.println("PARAM ip05 = " + getParam("ip05"));
Serial.println("PARAM ip06 = " + getParam("ip06"));
Serial.println("PARAM ip07 = " + getParam("ip07"));
Serial.println("PARAM ip08 = " + getParam("ip08"));
Serial.println("PARAM ip09 = " + getParam("ip09"));
Serial.println("PARAM ip10 = " + getParam("ip10"));
Serial.println("PARAM ip11 = " + getParam("ip11"));
Serial.println("PARAM ip12 = " + getParam("ip12"));
Serial.println("PARAM ip13 = " + getParam("ip13"));
Serial.println("PARAM ip14 = " + getParam("ip14"));
Serial.println("PARAM ip15 = " + getParam("ip15"));
Serial.println("PARAM ip16 = " + getParam("ip16"));

//String blinds[] = {getParam("ip01"), getParam("ip02"), getParam("ip03"), getParam("ip04"), getParam("ip05"), getParam("ip06"), getParam("ip07"), getParam("ip08"), getParam("ip09"), getParam("ip10"), getParam("ip11"), getParam("ip12"), getParam("ip12"), getParam("ip13"), getParam("ip14"), getParam("ip15"), getParam("ip16")};
String blinds[] = { getParam("ip01"), getParam("ip02"), getParam("ip03") };

//prefs.begin("array", false); //namespace
prefs.putBytes("SavedIntegers", (byte *)(&blinds), sizeof(blinds));
//prefs.end();

Serial.println(blinds[0]);
for (int i = 0; i < 3; i++) { // loop number of blinds}

Serial.println(blinds[i]);

}
}

void loop() {
if (wm_nonblocking) wm.process(); // avoid delays() in loop when non-blocking and other long running code
checkButton();
// put your main code here, to run repeatedly:
}

#END


### Debug Messages

/Users/romankeller/pCloud Drive/priv_kel/hagelwarn/wifi-manger-example-advanced/wifi-manger-example-advanced.ino:67:108: error: no matching function for call to 'WiFiManagerParameter::WiFiManagerParameter(const char [5], const char [6], String&, int&, const char [22])'
   67 |   new (&ip01) WiFiManagerParameter("ip01", "IP 01", blinds[0], customFieldLength, "placeholder=\"0.0.0.0\"");
      |                                                                                                            ^

Compilation error: no matching function for call to 'WiFiManagerParameter::WiFiManagerParameter(const char [5], const char [6], String&, int&, const char [22])'

messages here


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant