1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

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
This commit is contained in:
Ruandv 2019-06-20 21:24:33 +02:00 committed by Develo
parent 621a341234
commit a78fb72302
3 changed files with 11 additions and 13 deletions

View File

@ -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,9 @@ 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 +62,7 @@ bool saveConfig() {
return false;
}
json.printTo(configFile);
serializeJson(doc, configFile);
return true;
}

View File

@ -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.zip || wget https://github.com/bblanchon/ArduinoJson/releases/download/v6.11.0/ArduinoJson-v6.11.0.zip; } && unzip ArduinoJson-v6.11.0.zip
popd
}

View File

@ -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()