json 6 version

This commit is contained in:
Dmitry Borisenko
2021-10-08 20:12:01 +08:00
parent 2fce26ff29
commit 08d3ab8754
4 changed files with 43 additions and 16 deletions

View File

@@ -64,47 +64,63 @@
String jsonReadStr(String& json, String name) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonRead"), error.f_str());
return doc[name].as<String>();
}
boolean jsonReadBool(String& json, String name) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonRead"), error.f_str());
return doc[name].as<bool>();
}
int jsonReadInt(String& json, String name) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonRead"), error.f_str());
return doc[name].as<int>();
}
//=================================================================================
String jsonWriteStr(String& json, String name, String value) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DynamicJsonDocument doc(json.length());
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonWrite"), error.f_str());
doc[name] = value;
json = "";
serializeJson(doc, json);
return json;
}
String jsonWriteBool(String& json, String name, boolean value) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DynamicJsonDocument doc(json.length());
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonWrite"), error.f_str());
doc[name] = value;
json = "";
serializeJson(doc, json);
return json;
}
String jsonWriteInt(String& json, String name, int value) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DynamicJsonDocument doc(json.length());
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonWrite"), error.f_str());
doc[name] = value;
json = "";
serializeJson(doc, json);
return json;
}
String jsonWriteFloat(String& json, String name, float value) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
deserializeJson(doc, json);
DynamicJsonDocument doc(json.length());
DeserializationError error = deserializeJson(doc, json);
if (error) SerialPrint("E", F("jsonWrite"), error.f_str());
doc[name] = value;
json = "";
serializeJson(doc, json);
return json;
}

View File

@@ -11,6 +11,7 @@
#include "Global.h"
#include "Init.h"
#include "ItemsList.h"
#include "MySensorsDataParse.h"
#include "RemoteOrdersUdp.h"
#include "SoftUART.h"
#include "Telegram.h"
@@ -18,7 +19,6 @@
#include "Utils/StatUtils.h"
#include "Utils/Timings.h"
#include "Utils/WebUtils.h"
#include "MySensorsDataParse.h"
#include "items/ButtonInClass.h"
#include "items/vCountDown.h"
#include "items/vImpulsOut.h"
@@ -29,10 +29,10 @@
#include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h"
#include "items/vSensorDht.h"
#include "items/vSensorNode.h"
#include "items/vSensorPzem.h"
#include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h"
#include "items/vSensorNode.h"
void not_async_actions();
@@ -83,6 +83,16 @@ void setup() {
just_load = false;
initialized = true;
const int capacity = JSON_OBJECT_SIZE(35);
SerialPrint("I", F("Test"), String(capacity));
ts.add(
MYTEST, 10000, [&](void*) {
Serial.println(configSetupJson.length());
},
nullptr, true);
SerialPrint("I", F("System"), F("✔ Initialization completed"));
}