Skip to content

Updated Example to use ArduinoJson6 #6203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions libraries/esp8266/examples/ConfigFile/ConfigFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -53,18 +52,17 @@ 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) {
Serial.println("Failed to open config file for writing");
return false;
}

json.printTo(configFile);
serializeJson(doc, configFile);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tests/platformio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down