You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+22-12Lines changed: 22 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -825,7 +825,7 @@ Once WiFi network information is saved in the `ESP32 / ESP8266`, it will try to
825
825
826
826
These illustrating steps is based on the example [Async_ConfigOnSwitchFS](https://github.com/khoih-prog/ESPAsync_WiFiManager/tree/master/examples/Async_ConfigOnSwitchFS)
827
827
828
-
####1. Determine the variables to be configured via Config Portal (CP)
828
+
### 1. Determine the variables to be configured via Config Portal (CP)
829
829
830
830
The application will:
831
831
@@ -865,9 +865,9 @@ int pinScl = PIN_D1; // Pin D1 mapped to pin GPIO5
865
865
866
866
---
867
867
868
-
####2. Initialize the variables to prepare for Config Portal (CP)
868
+
### 2. Initialize the variables to prepare for Config Portal (CP)
869
869
870
-
The example [Async_ConfigOnSwitchFS](https://github.com/khoih-prog/ESPAsync_WiFiManager/tree/master/examples/Async_ConfigOnSwitchFS) will open the CP whenever a SW press is detected in loop(). So the code to add vars will be there, just after the CP `ESPAsync_WiFiManager` class initialization to create `ESPAsync_wifiManager` object.
870
+
The example [Async_ConfigOnSwitchFS](https://github.com/khoih-prog/ESPAsync_WiFiManager/tree/master/examples/Async_ConfigOnSwitchFS) will open the CP whenever a SW press is detected in loop(). So the code to add `dynamic variables` will be there, just after the CP `ESPAsync_WiFiManager` class initialization to create `ESPAsync_wifiManager` object.
871
871
872
872
```
873
873
void loop()
@@ -972,7 +972,7 @@ where
972
972
- labelPlacement => WFM_LABEL_AFTER : to place label after
973
973
```
974
974
975
-
where customhtml Code is:
975
+
and customhtml Code is:
976
976
977
977
```
978
978
char customhtml[24] = "type=\"checkbox\"";
@@ -985,7 +985,7 @@ if (sensorDht22)
985
985
986
986
---
987
987
988
-
####3. Add the variables to Config Portal (CP)
988
+
### 3. Add the variables to Config Portal (CP)
989
989
990
990
Adding those `ESPAsync_WMParameter` objects created in Step 2 using the function `addParameter()` of object `ESPAsync_wifiManager`
####4. Save the variables configured in Config Portal (CP)
1015
+
### 4. Save the variables configured in Config Portal (CP)
1016
1016
1017
1017
When the CP exits, we have to store the parameters' values that users input via CP to use later.
1018
1018
@@ -1048,7 +1048,7 @@ writeConfigFile();
1048
1048
1049
1049
---
1050
1050
1051
-
####5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
1051
+
### 5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
1052
1052
1053
1053
First, you have to familiarize yourself with `ArduinoJson` library, its functions, the disruptive differences between `ArduinoJson version 5.x.x-` and `v6.0.0+`. The best documentation can be found at [The best JSON library for embedded C++](https://arduinojson.org/).
1054
1054
@@ -1147,7 +1147,13 @@ Now just open the file for writing, and abort if open-for-writing error:
1147
1147
1148
1148
```
1149
1149
// Open file for writing
1150
-
File f = FileFS.open(CONFIG_FILE, "w");
1150
+
File f = FileFS.open(CONFIG_FILE, "w");
1151
+
1152
+
if (!f)
1153
+
{
1154
+
Serial.println("Failed to open config file for writing");
1155
+
return false;
1156
+
}
1151
1157
```
1152
1158
1153
1159
@@ -1172,7 +1178,7 @@ f.close();
1172
1178
But **HOWTO use the saved data in the next startup** ???? That's in next step 6.
1173
1179
1174
1180
1175
-
####6. Read from FS using JSON format
1181
+
### 6. Read from FS using JSON format
1176
1182
1177
1183
1178
1184
Now, you have familiarized yourself with ArduinoJson library, its functions. We'll discuss HOWTO read data from the CONFIG_FILE in Jsonified format, then HOWTO parse the to use.
@@ -1272,7 +1278,11 @@ File f = FileFS.open(CONFIG_FILE, "r");
1272
1278
We'll inform and abort if the CONFIG_FILE can't be opened (file not found, can't be opened, etc.)
1273
1279
1274
1280
```
1275
-
Serial.println("Configuration file not found");
1281
+
if (!f)
1282
+
{
1283
+
Serial.println("Configuration file not found");
1284
+
return false;
1285
+
}
1276
1286
```
1277
1287
1278
1288
### 6.2 Open CONFIG_FILE to read
@@ -1311,13 +1321,13 @@ We first create the object with enough size
1311
1321
DynamicJsonDocument json(1024);
1312
1322
```
1313
1323
1314
-
then populate it with data from buffer we read from CONFIG_FILE in step 6.2
1324
+
then populate it with data from buffer we read from CONFIG_FILE in step 6.2, pre-parse and check for error. All is done just by one command `deserializeJson()`
1315
1325
1316
1326
```
1317
1327
auto deserializeError = deserializeJson(json, buf.get());
1318
1328
```
1319
1329
1320
-
also check if any data error in the process of writing, storing, reading back:
1330
+
Abort if there is any data error in the process of writing, storing, reading back. If OK, just nicely print out to the Debug Terminal
0 commit comments