mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +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:
parent
621a341234
commit
a78fb72302
@ -31,16 +31,15 @@ bool loadConfig() {
|
|||||||
// use configFile.readString instead.
|
// use configFile.readString instead.
|
||||||
configFile.readBytes(buf.get(), size);
|
configFile.readBytes(buf.get(), size);
|
||||||
|
|
||||||
StaticJsonBuffer<200> jsonBuffer;
|
StaticJsonDocument<200> doc;
|
||||||
JsonObject& json = jsonBuffer.parseObject(buf.get());
|
auto error = deserializeJson(doc, buf.get());
|
||||||
|
if (error) {
|
||||||
if (!json.success()) {
|
|
||||||
Serial.println("Failed to parse config file");
|
Serial.println("Failed to parse config file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* serverName = json["serverName"];
|
const char* serverName = doc["serverName"];
|
||||||
const char* accessToken = json["accessToken"];
|
const char* accessToken = doc["accessToken"];
|
||||||
|
|
||||||
// Real world application would store these values in some variables for
|
// Real world application would store these values in some variables for
|
||||||
// later use.
|
// later use.
|
||||||
@ -53,10 +52,9 @@ bool loadConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool saveConfig() {
|
bool saveConfig() {
|
||||||
StaticJsonBuffer<200> jsonBuffer;
|
StaticJsonDocument<200> doc;
|
||||||
JsonObject& json = jsonBuffer.createObject();
|
doc["serverName"] = "api.example.com";
|
||||||
json["serverName"] = "api.example.com";
|
doc["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
|
||||||
json["accessToken"] = "128du9as8du12eoue8da98h123ueh9h98";
|
|
||||||
|
|
||||||
File configFile = SPIFFS.open("/config.json", "w");
|
File configFile = SPIFFS.open("/config.json", "w");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
@ -64,7 +62,7 @@ bool saveConfig() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
json.printTo(configFile);
|
serializeJson(doc, configFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ function install_libraries()
|
|||||||
pushd $HOME/Arduino/libraries
|
pushd $HOME/Arduino/libraries
|
||||||
|
|
||||||
# install ArduinoJson library
|
# 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
|
popd
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ function install_platformio()
|
|||||||
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
|
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
|
||||||
# Install dependencies:
|
# Install dependencies:
|
||||||
# - esp8266/examples/ConfigFile
|
# - esp8266/examples/ConfigFile
|
||||||
pio lib install "ArduinoJson@^5.13.4"
|
pio lib install "ArduinoJson@^6.11.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_sketches_with_platformio()
|
function build_sketches_with_platformio()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user