mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
clean up spiffs examples
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
|
||||
#ifdef ARDUINO_ESP8266_RELEASE_2_3_0
|
||||
#warning "ARDUINO_ESP8266_RELEASE_2_3_0, some WM features disabled"
|
||||
// @todo check failing on platform = espressif8266@1.7.3
|
||||
#define WM_NOASYNC // esp8266 no async scan wifi
|
||||
#define WM_NOCOUNTRY // esp8266 no country
|
||||
#define WM_NOAUTH // no httpauth
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||
char mqtt_server[40];
|
||||
char mqtt_port[6] = "8080";
|
||||
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
|
||||
char api_token[34] = "YOUR_API_TOKEN";
|
||||
|
||||
//flag for saving data
|
||||
bool shouldSaveConfig = false;
|
||||
@@ -60,7 +60,7 @@ void setup() {
|
||||
Serial.println("\nparsed json");
|
||||
strcpy(mqtt_server, json["mqtt_server"]);
|
||||
strcpy(mqtt_port, json["mqtt_port"]);
|
||||
strcpy(blynk_token, json["blynk_token"]);
|
||||
strcpy(api_token, json["api_token"]);
|
||||
} else {
|
||||
Serial.println("failed to load json config");
|
||||
}
|
||||
@@ -77,7 +77,7 @@ 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_api_token("apikey", "API token", api_token, 32);
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
@@ -92,7 +92,7 @@ void setup() {
|
||||
//add all your parameters here
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
wifiManager.addParameter(&custom_mqtt_port);
|
||||
wifiManager.addParameter(&custom_blynk_token);
|
||||
wifiManager.addParameter(&custom_api_token);
|
||||
|
||||
//reset settings - for testing
|
||||
//wifiManager.resetSettings();
|
||||
@@ -124,11 +124,11 @@ void setup() {
|
||||
//read updated parameters
|
||||
strcpy(mqtt_server, custom_mqtt_server.getValue());
|
||||
strcpy(mqtt_port, custom_mqtt_port.getValue());
|
||||
strcpy(blynk_token, custom_blynk_token.getValue());
|
||||
strcpy(api_token, custom_api_token.getValue());
|
||||
Serial.println("The values in the file are: ");
|
||||
Serial.println("\tmqtt_server : " + String(mqtt_server));
|
||||
Serial.println("\tmqtt_port : " + String(mqtt_port));
|
||||
Serial.println("\tblynk_token : " + String(blynk_token));
|
||||
Serial.println("\tapi_token : " + String(api_token));
|
||||
|
||||
//save the custom parameters to FS
|
||||
if (shouldSaveConfig) {
|
||||
@@ -141,7 +141,7 @@ void setup() {
|
||||
#endif
|
||||
json["mqtt_server"] = mqtt_server;
|
||||
json["mqtt_port"] = mqtt_port;
|
||||
json["blynk_token"] = blynk_token;
|
||||
json["api_token"] = api_token;
|
||||
|
||||
File configFile = SPIFFS.open("/config.json", "w");
|
||||
if (!configFile) {
|
||||
|
||||
+11
-12
@@ -1,19 +1,18 @@
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
|
||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||
|
||||
//needed for library
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
||||
|
||||
#ifdef ESP32
|
||||
#include <SPIFFS.h>
|
||||
#endif
|
||||
|
||||
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
//define your default values here, if there are different values in config.json, they are overwritten.
|
||||
//length should be max size + 1
|
||||
char mqtt_server[40];
|
||||
char mqtt_port[6] = "8080";
|
||||
char blynk_token[34] = "YOUR_BLYNK_TOKEN";
|
||||
char api_token[34] = "YOUR_APITOKEN";
|
||||
//default custom static IP
|
||||
char static_ip[16] = "10.0.1.56";
|
||||
char static_gw[16] = "10.0.1.1";
|
||||
@@ -67,7 +66,7 @@ void setup() {
|
||||
|
||||
strcpy(mqtt_server, json["mqtt_server"]);
|
||||
strcpy(mqtt_port, json["mqtt_port"]);
|
||||
strcpy(blynk_token, json["blynk_token"]);
|
||||
strcpy(api_token, json["api_token"]);
|
||||
|
||||
if (json["ip"]) {
|
||||
Serial.println("setting custom ip from config");
|
||||
@@ -88,7 +87,7 @@ void setup() {
|
||||
}
|
||||
//end read
|
||||
Serial.println(static_ip);
|
||||
Serial.println(blynk_token);
|
||||
Serial.println(api_token);
|
||||
Serial.println(mqtt_server);
|
||||
|
||||
|
||||
@@ -97,7 +96,7 @@ 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, 5);
|
||||
WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 34);
|
||||
WiFiManagerParameter custom_api_token("apikey", "API token", api_token, 34);
|
||||
|
||||
//WiFiManager
|
||||
//Local intialization. Once its business is done, there is no need to keep it around
|
||||
@@ -117,7 +116,7 @@ void setup() {
|
||||
//add all your parameters here
|
||||
wifiManager.addParameter(&custom_mqtt_server);
|
||||
wifiManager.addParameter(&custom_mqtt_port);
|
||||
wifiManager.addParameter(&custom_blynk_token);
|
||||
wifiManager.addParameter(&custom_api_token);
|
||||
|
||||
//reset settings - for testing
|
||||
//wifiManager.resetSettings();
|
||||
@@ -149,7 +148,7 @@ void setup() {
|
||||
//read updated parameters
|
||||
strcpy(mqtt_server, custom_mqtt_server.getValue());
|
||||
strcpy(mqtt_port, custom_mqtt_port.getValue());
|
||||
strcpy(blynk_token, custom_blynk_token.getValue());
|
||||
strcpy(api_token, custom_api_token.getValue());
|
||||
|
||||
//save the custom parameters to FS
|
||||
if (shouldSaveConfig) {
|
||||
@@ -162,7 +161,7 @@ void setup() {
|
||||
#endif
|
||||
json["mqtt_server"] = mqtt_server;
|
||||
json["mqtt_port"] = mqtt_port;
|
||||
json["blynk_token"] = blynk_token;
|
||||
json["api_token"] = api_token;
|
||||
|
||||
json["ip"] = WiFi.localIP().toString();
|
||||
json["gateway"] = WiFi.gatewayIP().toString();
|
||||
|
||||
Reference in New Issue
Block a user