mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-13 14:51:21 +10:00
This commit is contained in:
+16
-10
@@ -31,6 +31,10 @@ WiFiManagerParameter::WiFiManagerParameter(const char *custom) {
|
||||
_customHTML = custom;
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) {
|
||||
init(id, placeholder, "", 0, "", WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) {
|
||||
init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE);
|
||||
}
|
||||
@@ -46,17 +50,9 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold
|
||||
void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
_id = id;
|
||||
_placeholder = placeholder;
|
||||
_length = length;
|
||||
_labelPlacement = labelPlacement;
|
||||
_value = new char[length + 1];
|
||||
for (int i = 0; i < length + 1; i++) {
|
||||
_value[i] = 0;
|
||||
}
|
||||
if (defaultValue != NULL) {
|
||||
strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string
|
||||
}
|
||||
|
||||
_customHTML = custom;
|
||||
_customHTML = custom;
|
||||
setValue(defaultValue,length);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::~WiFiManagerParameter() {
|
||||
@@ -65,6 +61,16 @@ WiFiManagerParameter::~WiFiManagerParameter() {
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiManagerParameter::setValue(const char *defaultValue, int length) {
|
||||
_length = length;
|
||||
_value = new char[length + 1];
|
||||
for (int i = 0; i < length + 1; i++) {
|
||||
_value[i] = 0;
|
||||
}
|
||||
if (defaultValue != NULL) {
|
||||
strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string
|
||||
}
|
||||
}
|
||||
const char* WiFiManagerParameter::getValue() {
|
||||
return _value;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ class WiFiManagerParameter {
|
||||
@id is used for HTTP queries and must not contain spaces nor other special characters
|
||||
*/
|
||||
WiFiManagerParameter(const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
@@ -78,6 +79,7 @@ class WiFiManagerParameter {
|
||||
int getValueLength();
|
||||
int getLabelPlacement();
|
||||
const char *getCustomHTML();
|
||||
void setValue(const char *defaultValue, int length);
|
||||
private:
|
||||
const char *_id;
|
||||
const char *_placeholder;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <FS.h> // this needs to be first, or it all crashes and burns...
|
||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||
#include <spiffs.h>
|
||||
|
||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||
char mqtt_server[40];
|
||||
@@ -68,7 +69,10 @@ void setup() {
|
||||
// id/name placeholder/prompt default length
|
||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
|
||||
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
|
||||
// WiFiManagerParameter custom_blynk_token("blynk", "blynk token", "", 0);
|
||||
|
||||
WiFiManagerParameter custom_blynk_token("blynk", "blynk token");
|
||||
custom_blynk_token.setValue("setvalue override",32);
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
|
||||
Reference in New Issue
Block a user