Skip to content

Commit a78fb72

Browse files
Ruandvdevyte
authored andcommitted
Updated Example to use ArduinoJson6 (#6203)
* Updated Example to use ArduinoJson6 * Updated save method to Serialize and not Deserialize * Updated References to ArduinoJson 6.11.0 * Style Fix * another line missed * Added the file extension to the new version
1 parent 621a341 commit a78fb72

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

libraries/esp8266/examples/ConfigFile/ConfigFile.ino

+9-11
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ bool loadConfig() {
3131
// use configFile.readString instead.
3232
configFile.readBytes(buf.get(), size);
3333

34-
StaticJsonBuffer<200> jsonBuffer;
35-
JsonObject& json = jsonBuffer.parseObject(buf.get());
36-
37-
if (!json.success()) {
34+
StaticJsonDocument<200> doc;
35+
auto error = deserializeJson(doc, buf.get());
36+
if (error) {
3837
Serial.println("Failed to parse config file");
3938
return false;
4039
}
4140

42-
const char* serverName = json["serverName"];
43-
const char* accessToken = json["accessToken"];
41+
const char* serverName = doc["serverName"];
42+
const char* accessToken = doc["accessToken"];
4443

4544
// Real world application would store these values in some variables for
4645
// later use.
@@ -53,18 +52,17 @@ bool loadConfig() {
5352
}
5453

5554
bool saveConfig() {
56-
StaticJsonBuffer<200> jsonBuffer;
57-
JsonObject& json = jsonBuffer.createObject();
58-
json["serverName"] = "api.example.com";
59-
json["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
55+
StaticJsonDocument<200> doc;
56+
doc["serverName"] = "api.example.com";
57+
doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
6058

6159
File configFile = SPIFFS.open("/config.json", "w");
6260
if (!configFile) {
6361
Serial.println("Failed to open config file for writing");
6462
return false;
6563
}
6664

67-
json.printTo(configFile);
65+
serializeJson(doc, configFile);
6866
return true;
6967
}
7068

tests/common.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function install_libraries()
135135
pushd $HOME/Arduino/libraries
136136

137137
# install ArduinoJson library
138-
{ test -r ArduinoJson-v4.6.1.zip || wget https://github.com/bblanchon/ArduinoJson/releases/download/v4.6.1/ArduinoJson-v4.6.1.zip; } && unzip ArduinoJson-v4.6.1.zip
138+
{ test -r ArduinoJson-v6.11.0.zip || wget https://github.com/bblanchon/ArduinoJson/releases/download/v6.11.0/ArduinoJson-v6.11.0.zip; } && unzip ArduinoJson-v6.11.0.zip
139139

140140
popd
141141
}

tests/platformio.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function install_platformio()
1212
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
1313
# Install dependencies:
1414
# - esp8266/examples/ConfigFile
15-
pio lib install "ArduinoJson@^5.13.4"
15+
pio lib install "ArduinoJson@^6.11.0"
1616
}
1717

1818
function build_sketches_with_platformio()

0 commit comments

Comments
 (0)