1
1
/* ***************************************************************************************************************************
2
- * ConfigOnSwitchFS.ino
3
- * For ESP8266 / ESP32 boards
4
- *
5
- * ESP_WiFiManager is a library for the ESP8266/ESP32 platform (https://github.com/esp8266/Arduino) to enable easy
6
- * configuration and reconfiguration of WiFi credentials using a Captive Portal. Inspired by:
7
- * http://www.esp8266.com/viewtopic.php?f=29&t=2520
8
- * https://github.com/chriscook8/esp-arduino-apboot
9
- * https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/
10
- *
11
- * Forked from Tzapu https://github.com/tzapu/WiFiManager
12
- * and from Ken Taylor https://github.com/kentaylor
13
- *
14
- * Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
15
- * Licensed under MIT license
16
- * Version: 1.0.6
17
- *
18
- * Version Modified By Date Comments
19
- * ------- ----------- ---------- -----------
20
- * 1.0.0 K Hoang 07/10/2019 Initial coding
21
- * 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
22
- * 1.0.4 K Hoang 07/01/2020 Use ESP_WiFiManager setHostname feature
23
- * 1.0.5 K Hoang 15/01/2020 Add configurable DNS feature. Thanks to @Amorphous of https://community.blynk.cc
24
- * 1.0.6 K Hoang 03/02/2020 Add support for ArduinoJson version 6.0.0+ ( tested with v6.14.1 )
2
+ ConfigOnSwitchFS.ino
3
+ For ESP8266 / ESP32 boards
4
+
5
+ ESP_WiFiManager is a library for the ESP8266/ESP32 platform (https://github.com/esp8266/Arduino) to enable easy
6
+ configuration and reconfiguration of WiFi credentials using a Captive Portal. Inspired by:
7
+ http://www.esp8266.com/viewtopic.php?f=29&t=2520
8
+ https://github.com/chriscook8/esp-arduino-apboot
9
+ https://github.com/esp8266/Arduino/blob/master/libraries/DNSServer/examples/CaptivePortalAdvanced/
10
+
11
+ Forked from Tzapu https://github.com/tzapu/WiFiManager
12
+ and from Ken Taylor https://github.com/kentaylor
13
+
14
+ Built by Khoi Hoang https://github.com/khoih-prog/ESP_WiFiManager
15
+ Licensed under MIT license
16
+ Version: 1.0.6
17
+
18
+ Version Modified By Date Comments
19
+ ------- ----------- ---------- -----------
20
+ 1.0.0 K Hoang 07/10/2019 Initial coding
21
+ 1.0.1 K Hoang 13/12/2019 Fix bug. Add features. Add support for ESP32
22
+ 1.0.2 K Hoang 19/12/2019 Fix bug that keeps ConfigPortal in endless loop if Portal/Router SSID or Password is NULL.
23
+ 1.0.4 K Hoang 07/01/2020 Use ESP_WiFiManager setHostname feature
24
+ 1.0.5 K Hoang 15/01/2020 Add configurable DNS feature. Thanks to @Amorphous of https://community.blynk.cc
25
+ 1.0.6 K Hoang 03/02/2020 Add support for ArduinoJson version 6.0.0+ ( tested with v6.14.1 )
25
26
*****************************************************************************************************************************/
26
27
/* ***************************************************************************************************************************
27
28
This example will open a configuration portal when the reset button is pressed twice.
@@ -493,7 +494,7 @@ bool readConfigFile()
493
494
// we could open the file
494
495
size_t size = f.size ();
495
496
// Allocate a buffer to store contents of the file.
496
- std::unique_ptr<char []> buf (new char [size]);
497
+ std::unique_ptr<char []> buf (new char [size + 1 ]);
497
498
498
499
// Read and store file contents in buf
499
500
f.readBytes (buf.get (), size);
@@ -555,10 +556,10 @@ bool writeConfigFile()
555
556
Serial.println (" Saving config file" );
556
557
557
558
#if (ARDUINOJSON_VERSION_MAJOR >= 6)
558
- DynamicJsonDocument json (1024 );
559
+ DynamicJsonDocument json (1024 );
559
560
#else
560
- DynamicJsonBuffer jsonBuffer;
561
- JsonObject& json = jsonBuffer.createObject ();
561
+ DynamicJsonBuffer jsonBuffer;
562
+ JsonObject& json = jsonBuffer.createObject ();
562
563
#endif
563
564
564
565
// JSONify local configuration parameters
@@ -577,13 +578,13 @@ bool writeConfigFile()
577
578
}
578
579
579
580
#if (ARDUINOJSON_VERSION_MAJOR >= 6)
580
- serializeJsonPretty (json, Serial);
581
- // Write data to file and close it
582
- serializeJson (json, f);
581
+ serializeJsonPretty (json, Serial);
582
+ // Write data to file and close it
583
+ serializeJson (json, f);
583
584
#else
584
- json.prettyPrintTo (Serial);
585
- // Write data to file and close it
586
- json.printTo (f);
585
+ json.prettyPrintTo (Serial);
586
+ // Write data to file and close it
587
+ json.printTo (f);
587
588
#endif
588
589
589
590
f.close ();
0 commit comments