From 0b06e465ce9fa94a9341ff1ded4e48a8a4f3547b Mon Sep 17 00:00:00 2001 From: Alex Tudorache Date: Mon, 18 Jan 2016 15:33:45 +0200 Subject: [PATCH] updated example due to memory issues added more readme --- README.md | 4 +++ .../AutoConnectWithFSParameters.ino | 30 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c8f8e31..91ad77a 100644 --- a/README.md +++ b/README.md @@ -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. + +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 #### 0.6 - custom parameters diff --git a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index e5c9d9f..447f99e 100644 --- a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -10,9 +10,9 @@ #include //https://github.com/bblanchon/ArduinoJson //define your default values here, if there are different values in config.json, they are overwritten. -const char *mqtt_server = NULL; -const char *mqtt_port = "8080"; -const char *blynk_token = "YOUR_BLYNK_TOKEN"; +char mqtt_server[40]; +char mqtt_port[6] = "8080"; +char blynk_token[34] = "YOUR_BLYNK_TOKEN"; //flag for saving data bool shouldSaveConfig = false; @@ -54,9 +54,10 @@ void setup() { if (json.success()) { Serial.println("\nparsed json"); - mqtt_server = json["mqtt_server"]; - mqtt_port = json["mqtt_port"]; - blynk_token = json["blynk_token"]; + strcpy(mqtt_server, json["mqtt_server"]); + strcpy(mqtt_port, json["mqtt_port"]); + strcpy(blynk_token, json["blynk_token"]); + } else { Serial.println("failed to load json config"); } @@ -73,7 +74,7 @@ void setup() { // After connecting, parameter.getValue() will get you the configured value // 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, 8); + WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5); WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32); //WiFiManager @@ -83,13 +84,16 @@ void setup() { //set config save notify callback 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 wifiManager.addParameter(&custom_mqtt_server); wifiManager.addParameter(&custom_mqtt_port); wifiManager.addParameter(&custom_blynk_token); //reset settings - for testing - wifiManager.resetSettings(); + //wifiManager.resetSettings(); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% @@ -116,9 +120,9 @@ void setup() { Serial.println("connected...yeey :)"); //read updated parameters - mqtt_server = custom_mqtt_server.getValue(); - mqtt_port = custom_mqtt_port.getValue(); - blynk_token = custom_blynk_token.getValue(); + strcpy(mqtt_server, custom_mqtt_server.getValue()); + strcpy(mqtt_port, custom_mqtt_port.getValue()); + strcpy(blynk_token, custom_blynk_token.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { @@ -139,6 +143,10 @@ void setup() { configFile.close(); //end save } + + Serial.println("local ip"); + Serial.println(WiFi.localIP()); + } void loop() {