Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit b1c9f04

Browse files
authored
Fix bug for v1.0.6
Fix [Having issue to read the SPIFF file](#14) for 1. [ConfigOnSwitchFS](examples/ConfigOnSwitchFS) 2. [ConfigPortalParamsOnSwitch](examples/ConfigPortalParamsOnSwitch)
1 parent 382ab76 commit b1c9f04

File tree

2 files changed

+257
-257
lines changed

2 files changed

+257
-257
lines changed

examples/ConfigOnSwitchFS/ConfigOnSwitchFS.ino

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
/****************************************************************************************************************************
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 )
2526
*****************************************************************************************************************************/
2627
/****************************************************************************************************************************
2728
This example will open a configuration portal when the reset button is pressed twice.
@@ -493,7 +494,7 @@ bool readConfigFile()
493494
// we could open the file
494495
size_t size = f.size();
495496
// 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]);
497498

498499
// Read and store file contents in buf
499500
f.readBytes(buf.get(), size);
@@ -555,10 +556,10 @@ bool writeConfigFile()
555556
Serial.println("Saving config file");
556557

557558
#if (ARDUINOJSON_VERSION_MAJOR >= 6)
558-
DynamicJsonDocument json(1024);
559+
DynamicJsonDocument json(1024);
559560
#else
560-
DynamicJsonBuffer jsonBuffer;
561-
JsonObject& json = jsonBuffer.createObject();
561+
DynamicJsonBuffer jsonBuffer;
562+
JsonObject& json = jsonBuffer.createObject();
562563
#endif
563564

564565
// JSONify local configuration parameters
@@ -577,13 +578,13 @@ bool writeConfigFile()
577578
}
578579

579580
#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);
583584
#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);
587588
#endif
588589

589590
f.close();

0 commit comments

Comments
 (0)