mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
убрали лишние ошибки json
This commit is contained in:
@@ -11,85 +11,105 @@ void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) {
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonRead(String& json, String key, unsigned long& value) {
|
||||
bool jsonRead(String& json, String key, unsigned long& value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
} else if (!doc.containsKey(key)) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
value = doc[key].as<unsigned long>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonRead(String& json, String key, float& value) {
|
||||
bool jsonRead(String& json, String key, float& value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
} else if (!doc.containsKey(key)) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
value = doc[key].as<float>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonRead(String& json, String key, String& value) {
|
||||
bool jsonRead(String& json, String key, String& value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
} else if (!doc.containsKey(key)) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
value = doc[key].as<String>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonRead(String& json, String key, bool& value) {
|
||||
bool jsonRead(String& json, String key, bool& value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
} else if (!doc.containsKey(key)) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
value = doc[key].as<bool>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonRead(String& json, String key, int& value) {
|
||||
bool jsonRead(String& json, String key, int& value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
} else if (!doc.containsKey(key)) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), key + " missing");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
value = doc[key].as<int>();
|
||||
@@ -97,13 +117,15 @@ bool jsonRead(String& json, String key, int& value) {
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String& json, String key, String value) {
|
||||
bool jsonWriteStr_(String& json, String key, String value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
@@ -112,13 +134,15 @@ bool jsonWriteStr_(String& json, String key, String value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
bool jsonWriteBool_(String& json, String key, bool value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
@@ -127,13 +151,15 @@ bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String& json, String key, int value) {
|
||||
bool jsonWriteInt_(String& json, String key, int value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
@@ -142,13 +168,15 @@ bool jsonWriteInt_(String& json, String key, int value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String& json, String key, float value) {
|
||||
bool jsonWriteFloat_(String& json, String key, float value, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
@@ -166,7 +194,7 @@ void writeUint8tValueToJsonString(uint8_t* payload, size_t length, size_t header
|
||||
jsonMergeObjects(json, payloadStr);
|
||||
}
|
||||
|
||||
bool jsonMergeObjects(String& json1, String& json2) {
|
||||
bool jsonMergeObjects(String& json1, String& json2, bool e) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc1(JSON_BUFFER_SIZE);
|
||||
DeserializationError error1 = deserializeJson(doc1, json1);
|
||||
@@ -174,8 +202,10 @@ bool jsonMergeObjects(String& json1, String& json2) {
|
||||
DeserializationError error2 = deserializeJson(doc2, json2);
|
||||
jsonMergeDocs(doc1.as<JsonObject>(), doc2.as<JsonObject>());
|
||||
if (error1 || error2) {
|
||||
SerialPrint("EE", F("json"), "jsonMergeObjects error");
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("json"), "jsonMergeObjects error");
|
||||
jsonErrorDetected();
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
json1 = "";
|
||||
@@ -190,43 +220,51 @@ void jsonMergeDocs(JsonObject dest, JsonObjectConst src) {
|
||||
}
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
String jsonReadStr(String& json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(String& json, String name) {
|
||||
boolean jsonReadBool(String& json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(String& json, String name) {
|
||||
int jsonReadInt(String& json, String name, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
// depricated========================================================================
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
String jsonWriteStr(String& json, String name, String value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
doc[name] = value;
|
||||
json = "";
|
||||
@@ -234,12 +272,14 @@ String jsonWriteStr(String& json, String name, String value) {
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteBool(String& json, String name, boolean value) {
|
||||
String jsonWriteBool(String& json, String name, boolean value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
doc[name] = value;
|
||||
json = "";
|
||||
@@ -247,12 +287,14 @@ String jsonWriteBool(String& json, String name, boolean value) {
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteInt(String& json, String name, int value) {
|
||||
String jsonWriteInt(String& json, String name, int value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
doc[name] = value;
|
||||
json = "";
|
||||
@@ -260,12 +302,14 @@ String jsonWriteInt(String& json, String name, int value) {
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteFloat(String& json, String name, float value) {
|
||||
String jsonWriteFloat(String& json, String name, float value, bool e) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
if (e) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
jsonErrorDetected();
|
||||
}
|
||||
}
|
||||
doc[name] = value;
|
||||
json = "";
|
||||
|
||||
@@ -5,7 +5,9 @@ void SerialPrint(String errorLevel, String module, String msg) {
|
||||
String tosend = prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg;
|
||||
Serial.println(tosend);
|
||||
|
||||
if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
|
||||
standWebSocket.broadcastTXT("/log|" + tosend);
|
||||
if (isNetworkActive()) {
|
||||
if (jsonReadInt(settingsFlashJson, F("log")) != 0) {
|
||||
standWebSocket.broadcastTXT("/log|" + tosend);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user