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

Commit 5d5a0ac

Browse files
authored
Add HOWTO Add Dynamic Parameters section
Add HOWTO Add Dynamic Parameters section
1 parent 64980e8 commit 5d5a0ac

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ Once WiFi network information is saved in the `ESP32 / ESP8266`, it will try to
825825

826826
These illustrating steps is based on the example [Async_ConfigOnSwitchFS](https://github.com/khoih-prog/ESPAsync_WiFiManager/tree/master/examples/Async_ConfigOnSwitchFS)
827827

828-
#### 1. Determine the variables to be configured via Config Portal (CP)
828+
### 1. Determine the variables to be configured via Config Portal (CP)
829829

830830
The application will:
831831

@@ -865,9 +865,9 @@ int pinScl = PIN_D1; // Pin D1 mapped to pin GPIO5
865865

866866
---
867867

868-
#### 2. Initialize the variables to prepare for Config Portal (CP)
868+
### 2. Initialize the variables to prepare for Config Portal (CP)
869869

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.
871871

872872
```
873873
void loop()
@@ -972,7 +972,7 @@ where
972972
- labelPlacement => WFM_LABEL_AFTER : to place label after
973973
```
974974

975-
where customhtml Code is:
975+
and customhtml Code is:
976976

977977
```
978978
char customhtml[24] = "type=\"checkbox\"";
@@ -985,7 +985,7 @@ if (sensorDht22)
985985

986986
---
987987

988-
#### 3. Add the variables to Config Portal (CP)
988+
### 3. Add the variables to Config Portal (CP)
989989

990990
Adding those `ESPAsync_WMParameter` objects created in Step 2 using the function `addParameter()` of object `ESPAsync_wifiManager`
991991

@@ -1012,7 +1012,7 @@ ESPAsync_wifiManager.addParameter(&p_pinScl);
10121012

10131013
---
10141014

1015-
#### 4. Save the variables configured in Config Portal (CP)
1015+
### 4. Save the variables configured in Config Portal (CP)
10161016

10171017
When the CP exits, we have to store the parameters' values that users input via CP to use later.
10181018

@@ -1048,7 +1048,7 @@ writeConfigFile();
10481048

10491049
---
10501050

1051-
#### 5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
1051+
### 5. Write to FS (SPIFFS, LittleFS, etc.) using JSON format
10521052

10531053
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/).
10541054

@@ -1147,7 +1147,13 @@ Now just open the file for writing, and abort if open-for-writing error:
11471147

11481148
```
11491149
// 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+
}
11511157
```
11521158

11531159

@@ -1172,7 +1178,7 @@ f.close();
11721178
But **HOWTO use the saved data in the next startup** ???? That's in next step 6.
11731179

11741180

1175-
#### 6. Read from FS using JSON format
1181+
### 6. Read from FS using JSON format
11761182

11771183

11781184
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");
12721278
We'll inform and abort if the CONFIG_FILE can't be opened (file not found, can't be opened, etc.)
12731279

12741280
```
1275-
Serial.println("Configuration file not found");
1281+
if (!f)
1282+
{
1283+
Serial.println("Configuration file not found");
1284+
return false;
1285+
}
12761286
```
12771287

12781288
### 6.2 Open CONFIG_FILE to read
@@ -1311,13 +1321,13 @@ We first create the object with enough size
13111321
DynamicJsonDocument json(1024);
13121322
```
13131323

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()`
13151325

13161326
```
13171327
auto deserializeError = deserializeJson(json, buf.get());
13181328
```
13191329

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
13211331

13221332
```
13231333
if ( deserializeError )

0 commit comments

Comments
 (0)