[GH-ISSUE #1521] Clarify semantics of the "length" argument in WiFiManagerParameter #1297

Open
opened 2026-02-28 01:29:28 +03:00 by kerem · 1 comment
Owner

Originally created by @alranel on GitHub (Nov 17, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1521

Hi! I like the WiFiManagerParameter feature very much.
I'm having some issues in understanding exactly the semantics of the "length" argument in constructor. Is it supposed to hold the maximum length of the acceptable parameter or the length of the supplied default char array?

If I call it this way, the parameter will not be displayed in the web portal:

WiFiManagerParameter("device_id", "Device ID",  "", 0);

(Also, can't you just call strlen() on the supplied default to get its default instead of asking the caller?)

If I call it this way, I'm getting an ESP exception:

WiFiManagerParameter("device_id", "Device ID",  "", 1);

If I call it this way, the parameter is not displayed in the web portal and I get an error on the console saying it is "out of scope" while it's not (here I think the "out of scope" logic is giving a false postive):

WiFiManagerParameter("device_id", "Device ID");

The only way I got it working is this one:

char device_id[20] = "";
WiFiManagerParameter("device_id", "Device ID",  device_id, sizeof device_id);

However this approach seems to defeat the purpose of WiFiManager supporting arbitrary length strings, and still requires me to update the char array with strcpy(device_id, param.getValue()) myself so I don't see why the library would force me to declare a static char array because I might want to use a different storage for the returned value.


I would suggest to:

  • clarify the semantics of the 'length' argument
  • consider making it optional
  • consider always using an empty string as default value for the 'default' argument so that WiFiManagerParameter("device_id", "Device ID", "") is completely equivalent to WiFiManagerParameter("device_id", "Device ID")

...unless I did not understand the intended usage of the library, in which case I am sorry in advance :)

Originally created by @alranel on GitHub (Nov 17, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1521 Hi! I like the WiFiManagerParameter feature very much. I'm having some issues in understanding exactly the semantics of the "length" argument in constructor. Is it supposed to hold the maximum length of the acceptable parameter **or** the length of the supplied default char array? If I call it this way, the parameter will not be displayed in the web portal: ``` WiFiManagerParameter("device_id", "Device ID", "", 0); ``` (Also, can't you just call `strlen()` on the supplied default to get its default instead of asking the caller?) If I call it this way, I'm getting an ESP exception: ``` WiFiManagerParameter("device_id", "Device ID", "", 1); ``` If I call it this way, the parameter is not displayed in the web portal and I get an error on the console saying it is "out of scope" while it's not (here I think the "out of scope" logic is giving a false postive): ``` WiFiManagerParameter("device_id", "Device ID"); ``` The only way I got it working is this one: ``` char device_id[20] = ""; WiFiManagerParameter("device_id", "Device ID", device_id, sizeof device_id); ``` However this approach seems to defeat the purpose of WiFiManager supporting arbitrary length strings, and still requires me to update the char array with `strcpy(device_id, param.getValue())` myself so I don't see why the library would force me to declare a static char array because I might want to use a different storage for the returned value. *** I would suggest to: * clarify the semantics of the 'length' argument * consider making it optional * consider always using an empty string as default value for the 'default' argument so that `WiFiManagerParameter("device_id", "Device ID", "")` is completely equivalent to `WiFiManagerParameter("device_id", "Device ID")` ...unless I did not understand the intended usage of the library, in which case I am sorry in advance :)
Author
Owner

@tablatronix commented on GitHub (Nov 28, 2022):

hmm let me check on this I do not this is correct behavior.

WiFiManagerParameter("device_id", "Device ID");

<!-- gh-comment-id:1329804704 --> @tablatronix commented on GitHub (Nov 28, 2022): hmm let me check on this I do not this is correct behavior. >WiFiManagerParameter("device_id", "Device ID");
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1297
No description provided.