mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-22 02:32:10 +10:00
updated example due to memory issues
added more readme
This commit is contained in:
@@ -231,6 +231,10 @@ If you get compilation errors, more often than not, you may need to install a ne
|
|||||||
|
|
||||||
I am trying to keep releases working with release versions of the core, so they can be installed through boards manager, but if you checkout the latest version directly from github, sometimes, the library will only work if you update the ESP8266 core to the latest version because I am using some newly added function.
|
I am trying to keep releases working with release versions of the core, so they can be installed through boards manager, but if you checkout the latest version directly from github, sometimes, the library will only work if you update the ESP8266 core to the latest version because I am using some newly added function.
|
||||||
|
|
||||||
|
|
||||||
|
If you connect to the created configuration Access Point but the configuration portal does not show up, just open a browser and type in the IP of the web portal, by default `192.168.4.1`.
|
||||||
|
|
||||||
|
|
||||||
## Releases
|
## Releases
|
||||||
#### 0.6
|
#### 0.6
|
||||||
- custom parameters
|
- custom parameters
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||||
|
|
||||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||||
const char *mqtt_server = NULL;
|
char mqtt_server[40];
|
||||||
const char *mqtt_port = "8080";
|
char mqtt_port[6] = "8080";
|
||||||
const char *blynk_token = "YOUR_BLYNK_TOKEN";
|
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
|
||||||
|
|
||||||
//flag for saving data
|
//flag for saving data
|
||||||
bool shouldSaveConfig = false;
|
bool shouldSaveConfig = false;
|
||||||
@@ -54,9 +54,10 @@ void setup() {
|
|||||||
if (json.success()) {
|
if (json.success()) {
|
||||||
Serial.println("\nparsed json");
|
Serial.println("\nparsed json");
|
||||||
|
|
||||||
mqtt_server = json["mqtt_server"];
|
strcpy(mqtt_server, json["mqtt_server"]);
|
||||||
mqtt_port = json["mqtt_port"];
|
strcpy(mqtt_port, json["mqtt_port"]);
|
||||||
blynk_token = json["blynk_token"];
|
strcpy(blynk_token, json["blynk_token"]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("failed to load json config");
|
Serial.println("failed to load json config");
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ void setup() {
|
|||||||
// After connecting, parameter.getValue() will get you the configured value
|
// After connecting, parameter.getValue() will get you the configured value
|
||||||
// id/name placeholder/prompt default length
|
// id/name placeholder/prompt default length
|
||||||
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
|
||||||
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 8);
|
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5);
|
||||||
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
|
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);
|
||||||
|
|
||||||
//WiFiManager
|
//WiFiManager
|
||||||
@@ -83,13 +84,16 @@ void setup() {
|
|||||||
//set config save notify callback
|
//set config save notify callback
|
||||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||||
|
|
||||||
|
//set static ip
|
||||||
|
wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
|
||||||
|
|
||||||
//add all your parameters here
|
//add all your parameters here
|
||||||
wifiManager.addParameter(&custom_mqtt_server);
|
wifiManager.addParameter(&custom_mqtt_server);
|
||||||
wifiManager.addParameter(&custom_mqtt_port);
|
wifiManager.addParameter(&custom_mqtt_port);
|
||||||
wifiManager.addParameter(&custom_blynk_token);
|
wifiManager.addParameter(&custom_blynk_token);
|
||||||
|
|
||||||
//reset settings - for testing
|
//reset settings - for testing
|
||||||
wifiManager.resetSettings();
|
//wifiManager.resetSettings();
|
||||||
|
|
||||||
//set minimu quality of signal so it ignores AP's under that quality
|
//set minimu quality of signal so it ignores AP's under that quality
|
||||||
//defaults to 8%
|
//defaults to 8%
|
||||||
@@ -116,9 +120,9 @@ void setup() {
|
|||||||
Serial.println("connected...yeey :)");
|
Serial.println("connected...yeey :)");
|
||||||
|
|
||||||
//read updated parameters
|
//read updated parameters
|
||||||
mqtt_server = custom_mqtt_server.getValue();
|
strcpy(mqtt_server, custom_mqtt_server.getValue());
|
||||||
mqtt_port = custom_mqtt_port.getValue();
|
strcpy(mqtt_port, custom_mqtt_port.getValue());
|
||||||
blynk_token = custom_blynk_token.getValue();
|
strcpy(blynk_token, custom_blynk_token.getValue());
|
||||||
|
|
||||||
//save the custom parameters to FS
|
//save the custom parameters to FS
|
||||||
if (shouldSaveConfig) {
|
if (shouldSaveConfig) {
|
||||||
@@ -139,6 +143,10 @@ void setup() {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
//end save
|
//end save
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.println("local ip");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user