mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 06:41:20 +10:00
use malloc/free for WiFiManagerParameter* array instead of hard coding.
add alternate constructor to specifiy max parameter count origional default constructor uses old hard codded value
This commit is contained in:
@@ -204,6 +204,11 @@ You should also take a look at adding custom HTML to your form.
|
||||
- Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters)
|
||||
- *Save and load custom parameters to EEPROM* (not done yet)
|
||||
|
||||
NOTE: if your need more than 10 (the default) custom parameters you will need to use the alternate constructor:
|
||||
```cpp
|
||||
WiFiManager wifiManager(15); // pass the number of params you will be adding
|
||||
```
|
||||
|
||||
#### Custom IP Configuration
|
||||
You can set a custom IP for both AP (access point, config mode) and STA (station mode, client mode, normal project state)
|
||||
|
||||
|
||||
+25
-2
@@ -60,14 +60,37 @@ const char* WiFiManagerParameter::getCustomHTML() {
|
||||
return _customHTML;
|
||||
}
|
||||
|
||||
|
||||
WiFiManager::WiFiManager() {
|
||||
init(WIFI_MANAGER_MAX_PARAMS);
|
||||
}
|
||||
|
||||
WiFiManager::WiFiManager(int max_params) {
|
||||
init(max_params);
|
||||
}
|
||||
|
||||
void WiFiManager::init(int max_params)
|
||||
{
|
||||
DEBUG_WM(F("setting max_params to:"));
|
||||
DEBUG_WM(max_params);
|
||||
_max_params = max_params;
|
||||
_params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
|
||||
}
|
||||
|
||||
WiFiManager::~WiFiManager()
|
||||
{
|
||||
if (_params != NULL)
|
||||
{
|
||||
DEBUG_WM(F("freeing allocated params!"));
|
||||
free(_params);
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
|
||||
if(_paramsCount + 1 > _max_params)
|
||||
{
|
||||
//Max parameters exceeded!
|
||||
DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!");
|
||||
DEBUG_WM("max_params value exceeded, use WiFiManager(int max_params) constructor with a larger value!");
|
||||
DEBUG_WM("Skipping parameter with ID:");
|
||||
DEBUG_WM(p->getID());
|
||||
return;
|
||||
|
||||
+5
-1
@@ -65,6 +65,8 @@ class WiFiManager
|
||||
{
|
||||
public:
|
||||
WiFiManager();
|
||||
WiFiManager(int max_params);
|
||||
~WiFiManager();
|
||||
|
||||
boolean autoConnect();
|
||||
boolean autoConnect(char const *apName, char const *apPassword = NULL);
|
||||
@@ -119,6 +121,7 @@ class WiFiManager
|
||||
|
||||
//const String HTTP_HEAD = "<!DOCTYPE html><html lang=\"en\"><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>{v}</title>";
|
||||
|
||||
void init(int max_params);
|
||||
void setupConfigPortal();
|
||||
void startWPS();
|
||||
|
||||
@@ -176,7 +179,8 @@ class WiFiManager
|
||||
void (*_apcallback)(WiFiManager*) = NULL;
|
||||
void (*_savecallback)(void) = NULL;
|
||||
|
||||
WiFiManagerParameter* _params[WIFI_MANAGER_MAX_PARAMS];
|
||||
int _max_params;
|
||||
WiFiManagerParameter** _params;
|
||||
|
||||
template <typename Generic>
|
||||
void DEBUG_WM(Generic text);
|
||||
|
||||
Reference in New Issue
Block a user