mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
json обмен между вебом и esp
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -77,6 +77,6 @@ extern String settingsFlashJson;
|
||||
extern String paramsFlashJson;
|
||||
extern String paramsHeapJson;
|
||||
|
||||
extern DynamicJsonDocument settingsFlashJsonDoc;
|
||||
extern DynamicJsonDocument paramsFlashJsonDoc;
|
||||
extern DynamicJsonDocument paramsHeapJsonDoc;
|
||||
// extern DynamicJsonDocument settingsFlashJsonDoc;
|
||||
// extern DynamicJsonDocument paramsFlashJsonDoc;
|
||||
// extern DynamicJsonDocument paramsHeapJsonDoc;
|
||||
@@ -32,6 +32,6 @@ String settingsFlashJson = "{}"; //переменная в которой хр
|
||||
String paramsFlashJson = "{}"; //переменная в которой хранятся все параметры, находится в оперативной памяти и синхронизированна с flash памятью
|
||||
String paramsHeapJson = "{}"; //переменная в которой хранятся все параметры, находится в оперативной памяти только
|
||||
|
||||
DynamicJsonDocument settingsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
DynamicJsonDocument paramsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
DynamicJsonDocument paramsHeapJsonDoc(JSON_BUFFER_SIZE);
|
||||
// DynamicJsonDocument settingsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
// DynamicJsonDocument paramsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
// DynamicJsonDocument paramsHeapJsonDoc(JSON_BUFFER_SIZE);
|
||||
@@ -14,7 +14,8 @@ void StreamJsonArray::sendFile(String path, uint8_t num) {
|
||||
void StreamJsonArray::loop() {
|
||||
// if (ws.availableForWriteAll()) {
|
||||
if (file.available()) {
|
||||
String jsonArrayElement = file.readStringUntil('}') + "}";
|
||||
String jsonArrayElement = _path + file.readStringUntil('}') + "}";
|
||||
//jsonArrayElement.replace("]}", "]");
|
||||
// Serial.println(jsonArrayElement);
|
||||
standWebSocket.sendTXT(_num, jsonArrayElement);
|
||||
// ws.textAll(jsonArrayElement);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
//================================================================================
|
||||
// new================================================================================
|
||||
String jsonReadStrDoc(DynamicJsonDocument& doc, String name) {
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
@@ -57,6 +57,63 @@ bool jsonRead(String& json, String key, int& value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String& json, String key, String value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String& json, String key, int value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String& json, String key, float value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
@@ -119,62 +176,3 @@ String jsonWriteFloat(String& json, String name, float value) {
|
||||
serializeJson(doc, json);
|
||||
return json;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String& json, String key, String value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String& json, String key, int value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String& json, String key, float value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
|
||||
Reference in New Issue
Block a user