-
Notifications
You must be signed in to change notification settings - Fork 11
Custom Parameters
smurf0969 edited this page Mar 17, 2019
·
3 revisions
To add custom parameters to the captive portal for connecting to your network, first define the custom parameter you would like.
char myCustomParam[16]="192.168.0.1" ;
Next we need to add make a custom parameter object to store the information for WiFiConnect to use.
/*
* param 1: The html id/name for our input. This needs to be unique.
* param 2: The text to be displayed if no value is present.
* param 3: The default value for the input
* param 4: The maximum amout of characters allowed for the input.
*/
WiFiConnectParam wc_myCustomParam("server_ip", "Server IP", server_ip, 16);
/*
* This will make a input box in the portal with the following html markup
* <input id='server_ip' name='server_id' maxlength=16 placeholder='Server IP' value='192.168.0.1'>
*/
If you do not supply default text you input will look similar to this. 
After you have defined your WiFiConnect object you can add your custom parameter to it.
char myCustomParam[16]="192.168.0.1";
bool saveChanges=false;
void saveConfiguration(){
saveChanges=true;
}
void startup(){
WiFiConnectParam wc_myCustomParam("server_ip", "Server IP", server_ip, 16);
// Your WifiConnect object can exist globally if you need to use it in multiple places or in startup();
WiFiConnect wc;
wc.setSaveConfigCallback(saveConfiguration);
wc.addParameter(&wc_myCustomParam);
/*
* You can get and set any of the parameters in you object by using the supplied methods.
* See the supplied example in the project or the documentation at https://smurf0969.github.io/WiFiConnect/
*/
... Other code left out for brevity
if(saveChanges){
strcpy(myCustomParam, wc_myCustomParam.getValue());
// Code to save changes to SPIFFS or SD
}
}
By default the maximum amout of custom parameters you can use is 10, which is set by WiFiConnect_MAX_PARAMS in WiFiConnectParam.h. You can override this value by placing a define prior to including
#define WiFiConnect_MAX_PARAMS 5
#include "WiFiConnect.h" //or WiFiConnectOLED.h if using an OLED display