From d511c29b462eeac3af3a2969b4ea6d5660ca3eb0 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sat, 15 Jun 2019 12:28:01 +0200 Subject: [PATCH 1/6] Updated Example to use ArduinoJson6 --- .../examples/ConfigFile/ConfigFile.ino | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino index 3503a10b59..b71c33517b 100644 --- a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino +++ b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino @@ -4,7 +4,7 @@ // https://github.com/bblanchon/ArduinoJson // // Created Aug 10, 2015 by Ivan Grokhotkov. -// +// Updated Jun 15, 2019 by Ruan de Villiers to use ArduinoJson6 // This example code is in the public domain. #include @@ -31,16 +31,15 @@ bool loadConfig() { // use configFile.readString instead. configFile.readBytes(buf.get(), size); - StaticJsonBuffer<200> jsonBuffer; - JsonObject& json = jsonBuffer.parseObject(buf.get()); - - if (!json.success()) { + StaticJsonDocument<200> doc; + auto error = deserializeJson(doc, buf.get()); + if (error) { Serial.println("Failed to parse config file"); return false; } - const char* serverName = json["serverName"]; - const char* accessToken = json["accessToken"]; + const char* serverName = doc["serverName"]; + const char* accessToken = doc["accessToken"]; // Real world application would store these values in some variables for // later use. @@ -53,10 +52,10 @@ bool loadConfig() { } bool saveConfig() { - StaticJsonBuffer<200> jsonBuffer; - JsonObject& json = jsonBuffer.createObject(); - json["serverName"] = "api.example.com"; - json["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98"; + StaticJsonDocument<200> doc; + + doc["serverName"] = "api.example.com"; + doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98"; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { @@ -64,7 +63,7 @@ bool saveConfig() { return false; } - json.printTo(configFile); + deserializeJson(doc,configFile); return true; } @@ -94,4 +93,4 @@ void setup() { } void loop() { -} +} \ No newline at end of file From 33c6b562460691c73b06b37c58ad575a3592eff0 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sat, 15 Jun 2019 12:43:15 +0200 Subject: [PATCH 2/6] Updated save method to Serialize and not Deserialize --- libraries/esp8266/examples/ConfigFile/ConfigFile.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino index b71c33517b..b65b1c38ec 100644 --- a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino +++ b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino @@ -4,7 +4,7 @@ // https://github.com/bblanchon/ArduinoJson // // Created Aug 10, 2015 by Ivan Grokhotkov. -// Updated Jun 15, 2019 by Ruan de Villiers to use ArduinoJson6 +// // This example code is in the public domain. #include @@ -63,7 +63,7 @@ bool saveConfig() { return false; } - deserializeJson(doc,configFile); + serializeJson(doc,configFile); return true; } @@ -93,4 +93,4 @@ void setup() { } void loop() { -} \ No newline at end of file +} From 74b84ff8ab121c14d2e0bac1665458bc67ead3b2 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sat, 15 Jun 2019 19:11:04 +0200 Subject: [PATCH 3/6] Updated References to ArduinoJson 6.11.0 --- tests/common.sh | 2 +- tests/platformio.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common.sh b/tests/common.sh index 3d2a107d5d..636d01ce67 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -135,7 +135,7 @@ function install_libraries() pushd $HOME/Arduino/libraries # install ArduinoJson library - { 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 + { test -r ArduinoJson-v6.11.0 || wget https://github.com/bblanchon/ArduinoJson/releases/download/v6.11.0/ArduinoJson-v6.11.0.zip; } && unzip ArduinoJson-v6.11.0 popd } diff --git a/tests/platformio.sh b/tests/platformio.sh index c6db433fbb..bacd1704eb 100755 --- a/tests/platformio.sh +++ b/tests/platformio.sh @@ -12,7 +12,7 @@ function install_platformio() ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266 # Install dependencies: # - esp8266/examples/ConfigFile - pio lib install "ArduinoJson@^5.13.4" + pio lib install "ArduinoJson@^6.11.0" } function build_sketches_with_platformio() From 6a4885e700dc22473f34cadf2ca9fce6337acd48 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sat, 15 Jun 2019 20:11:02 +0200 Subject: [PATCH 4/6] Style Fix --- libraries/esp8266/examples/ConfigFile/ConfigFile.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino index b65b1c38ec..0d8caa68f0 100644 --- a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino +++ b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino @@ -53,7 +53,6 @@ bool loadConfig() { bool saveConfig() { StaticJsonDocument<200> doc; - doc["serverName"] = "api.example.com"; doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98"; From 1cb937cbfea839951fd589186464f6b8b33693e7 Mon Sep 17 00:00:00 2001 From: Ruan Date: Sat, 15 Jun 2019 20:47:38 +0200 Subject: [PATCH 5/6] another line missed --- libraries/esp8266/examples/ConfigFile/ConfigFile.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino index 0d8caa68f0..77bbfabaa9 100644 --- a/libraries/esp8266/examples/ConfigFile/ConfigFile.ino +++ b/libraries/esp8266/examples/ConfigFile/ConfigFile.ino @@ -62,7 +62,7 @@ bool saveConfig() { return false; } - serializeJson(doc,configFile); + serializeJson(doc, configFile); return true; } From 4be6716379dcf5c6e2ef4a756b4e2e4ea891ad05 Mon Sep 17 00:00:00 2001 From: Ruan de Villiers Date: Tue, 18 Jun 2019 11:28:02 +0200 Subject: [PATCH 6/6] Added the file extension to the new version --- tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common.sh b/tests/common.sh index 636d01ce67..ca2c535232 100755 --- a/tests/common.sh +++ b/tests/common.sh @@ -135,7 +135,7 @@ function install_libraries() pushd $HOME/Arduino/libraries # install ArduinoJson library - { test -r ArduinoJson-v6.11.0 || wget https://github.com/bblanchon/ArduinoJson/releases/download/v6.11.0/ArduinoJson-v6.11.0.zip; } && unzip ArduinoJson-v6.11.0 + { 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 popd }