Auto check ArduinoJson rather than using a #define

This commit is contained in:
Ruan de Villiers
2020-01-15 07:24:28 +02:00
parent 9669bfd1a3
commit a6438edb3c
2 changed files with 6 additions and 12 deletions
@@ -7,9 +7,6 @@
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
//Comment out this line if you are still using ArduinoJsonV5
#define UseJsonV6
//define your default values here, if there are different values in config.json, they are overwritten.
char mqtt_server[40];
char mqtt_port[6] = "8080";
@@ -49,7 +46,7 @@ void setup() {
configFile.readBytes(buf.get(), size);
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
DynamicJsonDocument json(1024);
auto deserializeError = deserializeJson(json, buf.get());
serializeJson(json, Serial);
@@ -136,7 +133,7 @@ void setup() {
//save the custom parameters to FS
if (shouldSaveConfig) {
Serial.println("saving config");
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
DynamicJsonDocument json(1024);
#else
DynamicJsonBuffer jsonBuffer;
@@ -151,7 +148,7 @@ void setup() {
Serial.println("failed to open config file for writing");
}
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
serializeJson(json, Serial);
serializeJson(json, configFile);
#else
@@ -9,9 +9,6 @@
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
//Comment out this line if you are still using ArduinoJsonV5
#define UseJsonV6
//define your default values here, if there are different values in config.json, they are overwritten.
//length should be max size + 1
char mqtt_server[40];
@@ -55,7 +52,7 @@ void setup() {
std::unique_ptr<char[]> buf(new char[size]);
configFile.readBytes(buf.get(), size);
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
DynamicJsonDocument json(1024);
auto deserializeError = deserializeJson(json, buf.get());
serializeJson(json, Serial);
@@ -157,7 +154,7 @@ void setup() {
//save the custom parameters to FS
if (shouldSaveConfig) {
Serial.println("saving config");
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
DynamicJsonDocument json(1024);
#else
DynamicJsonBuffer jsonBuffer;
@@ -176,7 +173,7 @@ void setup() {
Serial.println("failed to open config file for writing");
}
#ifdef UseJsonV6
#ifdef ARDUINOJSON_VERSION_MAJOR >= 6
serializeJson(json, Serial);
serializeJson(json, configFile);
#else