mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
добавил новые json утилиты
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "AsyncWebServer.h"
|
||||
#ifdef ASYNC_WEB_SERVER
|
||||
AsyncWebSocket ws("/ws");
|
||||
AsyncEventSource events("/events");
|
||||
|
||||
void asyncWebServerInit() {
|
||||
String login = jsonReadStr(settingsFlashJson, "weblogin");
|
||||
@@ -70,6 +68,12 @@ void asyncWebServerInit() {
|
||||
|
||||
SerialPrint("i", F("WEB"), F("WebServer Init"));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ASYNC_WEB_SOCKETS
|
||||
|
||||
AsyncWebSocket ws("/ws");
|
||||
AsyncEventSource events("/events");
|
||||
|
||||
void asyncWebSocketsInit() {
|
||||
ws.onEvent(onWsEvent);
|
||||
|
||||
@@ -30,4 +30,8 @@ WebSocketsServer standWebSocket = WebSocketsServer(81);
|
||||
|
||||
String settingsFlashJson = "{}"; //переменная в которой хранятся все настройки, находится в оперативной памяти и синхронизированна с flash памятью
|
||||
String paramsFlashJson = "{}"; //переменная в которой хранятся все параметры, находится в оперативной памяти и синхронизированна с flash памятью
|
||||
String paramsHeapJson = "{}"; //переменная в которой хранятся все параметры, находится в оперативной памяти только
|
||||
String paramsHeapJson = "{}"; //переменная в которой хранятся все параметры, находится в оперативной памяти только
|
||||
|
||||
DynamicJsonDocument settingsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
DynamicJsonDocument paramsFlashJsonDoc(JSON_BUFFER_SIZE);
|
||||
DynamicJsonDocument paramsHeapJsonDoc(JSON_BUFFER_SIZE);
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "StandWebServer.h"
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
|
||||
File fsUploadFile;
|
||||
|
||||
void standWebServerInit() {
|
||||
// Кэшировать файлы для быстрой работы
|
||||
HTTP.serveStatic("/css/", FileFS, "/css/", "max-age=31536000"); // кеширование на 1 год
|
||||
@@ -19,11 +22,7 @@ void standWebServerInit() {
|
||||
// httpUpdater.setup(&HTTP);
|
||||
// Запускаем HTTP сервер
|
||||
HTTP.begin();
|
||||
}
|
||||
|
||||
File fsUploadFile;
|
||||
|
||||
void standWebServerFiles() {
|
||||
#ifdef REST_FILE_OPERATIONS
|
||||
SPIFFS.begin();
|
||||
{
|
||||
@@ -224,7 +223,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
||||
|
||||
case WStype_BIN: {
|
||||
Serial.printf("[%u] get binary length: %u\n", num, length);
|
||||
//hexdump(payload, length);
|
||||
// hexdump(payload, length);
|
||||
|
||||
// send message to client
|
||||
// standWebSocket.sendBIN(num, payload, length);
|
||||
@@ -246,5 +245,4 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols = 16) {
|
||||
Serial.printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
13
src/main.cpp
13
src/main.cpp
@@ -12,25 +12,26 @@ void setup() {
|
||||
//синхронизация глобальных переменных с flash
|
||||
globalVarsSync();
|
||||
|
||||
//подключаемся к роутеру
|
||||
routerConnect();
|
||||
|
||||
//инициализация асинхронного веб сервера и веб сокетов
|
||||
#ifdef ASYNC_WEB_SERVER
|
||||
asyncWebServerInit();
|
||||
#endif
|
||||
#ifdef ASYNC_WEB_SOCKETS
|
||||
asyncWebSocketsInit();
|
||||
#endif
|
||||
|
||||
//инициализация стандартного веб сервера
|
||||
//инициализация стандартного веб сервера и веб сокетов
|
||||
#ifdef STANDARD_WEB_SERVER
|
||||
standWebServerInit();
|
||||
standWebServerFiles();
|
||||
#endif
|
||||
|
||||
#ifdef STANDARD_WEB_SOCKETS
|
||||
standWebSocketsInit();
|
||||
#endif
|
||||
|
||||
//подключаемся к роутеру
|
||||
routerConnect();
|
||||
|
||||
//создаем объект класса выгружающего json массив из файла
|
||||
myStreamJsonArray = new StreamJsonArray;
|
||||
|
||||
//выводим остаток оперативной памяти после старта
|
||||
|
||||
@@ -2,26 +2,13 @@
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
//================================================================================
|
||||
String jsonReadStrDoc(DynamicJsonDocument& doc, String name) {
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
return doc[name].as<int>();
|
||||
void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) {
|
||||
doc[name] = value;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
@@ -69,6 +56,29 @@ bool jsonRead(String& json, String key, int& value) {
|
||||
value = doc[key].as<int>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) SerialPrint("EE", F("jsonRead"), error.f_str());
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
// depricated========================================================================
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user