mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
json utils updated
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"functional": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ int jsonReadInt(String& json, String name);
|
|||||||
|
|
||||||
boolean jsonReadBool(String& json, String name);
|
boolean jsonReadBool(String& json, String name);
|
||||||
|
|
||||||
|
bool jsonReadFromStr(String& json, String key, String& value);
|
||||||
|
|
||||||
String jsonWriteStr(String& json, String name, String value);
|
String jsonWriteStr(String& json, String name, String value);
|
||||||
|
|
||||||
String jsonWriteInt(String& json, String name, int value);
|
String jsonWriteInt(String& json, String name, int value);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
//=================================================================================
|
//depricated======================================================================
|
||||||
String jsonReadStr(String& json, String name) {
|
String jsonReadStr(String& json, String name) {
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
DeserializationError error = deserializeJson(doc, json);
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
@@ -27,6 +27,51 @@ int jsonReadInt(String& json, String name) {
|
|||||||
return doc[name].as<int>();
|
return doc[name].as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//new==============================================================================
|
||||||
|
bool jsonReadFromStr(String& json, String key, String& value) {
|
||||||
|
bool ret = true;
|
||||||
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
|
if (error) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||||
|
ret = false;
|
||||||
|
} else if (!doc.containsKey(key)) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
value = doc[key].as<String>();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool jsonReadFromStr(String& json, String key, bool& value) {
|
||||||
|
bool ret = true;
|
||||||
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
|
if (error) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||||
|
ret = false;
|
||||||
|
} else if (!doc.containsKey(key)) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
value = doc[key].as<bool>();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool jsonReadFromStr(String& json, String key, int& value) {
|
||||||
|
bool ret = true;
|
||||||
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
DeserializationError error = deserializeJson(doc, json);
|
||||||
|
if (error) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||||
|
ret = false;
|
||||||
|
} else if (!doc.containsKey(key)) {
|
||||||
|
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
value = doc[key].as<int>();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
//=================================================================================
|
//=================================================================================
|
||||||
String jsonWriteStr(String& json, String name, String value) {
|
String jsonWriteStr(String& json, String name, String value) {
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
|||||||
18
src/main.cpp
18
src/main.cpp
@@ -88,14 +88,16 @@ void setup() {
|
|||||||
SerialPrint("I", F("Test"), String(capacity));
|
SerialPrint("I", F("Test"), String(capacity));
|
||||||
|
|
||||||
ts.add(
|
ts.add(
|
||||||
MYTEST, 10000, [&](void*) {
|
MYTEST, 5000, [&](void*) {
|
||||||
//Serial.println(configSetupJson.length());
|
Serial.println(configSetupJson.length());
|
||||||
//Serial.println(F("--------------------------------------"));
|
Serial.println(F("--------------------------------------"));
|
||||||
//Serial.println(jsonReadStr(configSetupJson, "apssidx"));
|
|
||||||
//Serial.println(jsonReadBool(configSetupJson, "telegonof"));
|
String value;
|
||||||
//Serial.println(jsonReadInt(configSetupJson, "mqttPort"));
|
if (jsonReadFromStr(configSetupJson, "name", value)) {
|
||||||
//Serial.println(jsonReadInt(configSetupJson, "uartTX"));
|
Serial.println(value);
|
||||||
//Serial.println(F("--------------------------------------"));
|
}
|
||||||
|
|
||||||
|
Serial.println(F("--------------------------------------"));
|
||||||
},
|
},
|
||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user