mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-06-10 20:09:19 +03:00
управление ошибками
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//Это версия прошивки
|
//Это версия прошивки
|
||||||
#define FIRMWARE_VERSION 400
|
#define FIRMWARE_VERSION 401
|
||||||
|
|
||||||
//Размер буфера json
|
//Размер буфера json
|
||||||
#define JSON_BUFFER_SIZE 1024
|
#define JSON_BUFFER_SIZE 1024
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
|
void writeUint8tToString(uint8_t* payload, size_t length, size_t headerLenth, String& payloadStr);
|
||||||
|
|
||||||
void hex2string(byte array[], unsigned int len, char buffer[]);
|
void hex2string(byte array[], unsigned int len, char buffer[]);
|
||||||
|
|
||||||
int string2hex(const char* str, unsigned char* bytes);
|
int string2hex(const char* str, unsigned char* bytes);
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ void standWebServerInit() {
|
|||||||
HTTP.send(200, "application/json", settingsFlashJson);
|
HTTP.send(200, "application/json", settingsFlashJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
HTTP.on("/errors.json", HTTP_GET, []() {
|
||||||
|
HTTP.send(200, "application/json", errorsHeapJson);
|
||||||
|
});
|
||||||
|
|
||||||
HTTP.on("/paramsh.json", HTTP_GET, []() {
|
HTTP.on("/paramsh.json", HTTP_GET, []() {
|
||||||
HTTP.send(200, "application/json", paramsHeapJson);
|
HTTP.send(200, "application/json", paramsHeapJson);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,69 +30,80 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WStype_TEXT: {
|
case WStype_TEXT: {
|
||||||
//максимальное количество символов заголовка
|
bool endOfHeaderFound = false;
|
||||||
size_t headerLenth = 7;
|
size_t maxAllowedHeaderSize = 15; //максимальное количество символов заголовка
|
||||||
|
size_t headerLenth = 0;
|
||||||
String headerStr;
|
String headerStr;
|
||||||
headerStr.reserve(headerLenth + 1);
|
for (size_t i = 0; i <= maxAllowedHeaderSize; i++) {
|
||||||
for (size_t i = 0; i < headerLenth; i++) {
|
headerLenth++;
|
||||||
headerStr += (char)payload[i];
|
char s = (char)payload[i];
|
||||||
|
headerStr += s;
|
||||||
|
if (s == '|') {
|
||||||
|
endOfHeaderFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//отправка данных которые нужны для всех страниц веб интерфейса
|
if (!endOfHeaderFound) {
|
||||||
//эти данные мы отправляем в двух случаях:
|
SerialPrint("E", "WS " + String(num), "Package without header");
|
||||||
// 1 пользователь перешел на новую страницу
|
}
|
||||||
// 2 каждые 30 секунд
|
|
||||||
// all pages===================================================================
|
// all pages===================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == ("/all")) {
|
if (headerStr == ("/all|")) {
|
||||||
standWebSocket.sendTXT(num, ssidListHeapJson);
|
standWebSocket.sendTXT(num, ssidListHeapJson);
|
||||||
standWebSocket.broadcastTXT(errorsHeapJson);
|
standWebSocket.sendTXT(num, errorsHeapJson);
|
||||||
}
|
}
|
||||||
// dashboard===================================================================
|
// dashboard===================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/") {
|
if (headerStr == "/|") {
|
||||||
sendFileToWs("/layout.json", num, 1024);
|
sendFileToWs("/layout.json", num, 1024);
|
||||||
standWebSocket.sendTXT(num, paramsHeapJson);
|
standWebSocket.sendTXT(num, paramsHeapJson);
|
||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/tuoyal") {
|
if (headerStr == "/tuoyal|") {
|
||||||
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("layout.json", payload, length, headerLenth, 256);
|
||||||
}
|
}
|
||||||
// configutation===============================================================
|
// configutation===============================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/config") {
|
if (headerStr == "/config|") {
|
||||||
sendFileToWs("/items.json", num, 1024);
|
sendFileToWs("/items.json", num, 1024);
|
||||||
sendFileToWs("/widgets.json", num, 1024);
|
sendFileToWs("/widgets.json", num, 1024);
|
||||||
sendFileToWs("/config.json", num, 1024);
|
sendFileToWs("/config.json", num, 1024);
|
||||||
sendFileToWs("/settings.json", num, 1024);
|
sendFileToWs("/settings.json", num, 1024);
|
||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/gifnoc") {
|
if (headerStr == "/gifnoc|") {
|
||||||
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("config.json", payload, length, headerLenth, 256);
|
||||||
}
|
}
|
||||||
// connection===================================================================
|
// connection===================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/connec") {
|
if (headerStr == "/connection|") {
|
||||||
sendFileToWs("/settings.json", num, 1024);
|
sendFileToWs("/settings.json", num, 1024);
|
||||||
//запуск асинхронного сканирования wifi сетей при переходе на страницу соединений
|
//запуск асинхронного сканирования wifi сетей при переходе на страницу соединений
|
||||||
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
||||||
}
|
}
|
||||||
//**отправка**//
|
|
||||||
if (headerStr == "/scan") {
|
|
||||||
//запуск асинхронного сканирования wifi сетей при нажатии выпадающего списка
|
|
||||||
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
|
||||||
}
|
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/cennoc") {
|
if (headerStr == "/sgnittes|") {
|
||||||
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
writeFileUint8tByFrames("settings.json", payload, length, headerLenth, 256);
|
||||||
settingsFlashJson = readFile(F("settings.json"), 4096);
|
settingsFlashJson = readFile(F("settings.json"), 4096);
|
||||||
}
|
}
|
||||||
|
//**отправка**//
|
||||||
|
if (headerStr == "/scan|") {
|
||||||
|
//запуск асинхронного сканирования wifi сетей при нажатии выпадающего списка
|
||||||
|
RouterFind(jsonReadStr(settingsFlashJson, F("routerssid")));
|
||||||
|
}
|
||||||
// list ===================================================================
|
// list ===================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/list") {
|
if (headerStr == "/list|") {
|
||||||
standWebSocket.sendTXT(num, devListHeapJson);
|
standWebSocket.sendTXT(num, devListHeapJson);
|
||||||
}
|
}
|
||||||
|
// system ===================================================================
|
||||||
|
//**сохранение**//
|
||||||
|
if (headerStr == "/rorre|") {
|
||||||
|
writeUint8tToString(payload, length, headerLenth, errorsHeapJson);
|
||||||
|
}
|
||||||
// orders ===================================================================
|
// orders ===================================================================
|
||||||
if (headerStr == "/reboot") {
|
if (headerStr == "/reboot|") {
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
|
||||||
void writeStrValueToJsonFile(const String& filename, String key, String value) {
|
|
||||||
String tmp = readFile(filename, 4096);
|
|
||||||
if (!jsonWriteStr_(tmp, key, value)) {
|
|
||||||
Serial.println(F("failed write json value to file"));
|
|
||||||
}
|
|
||||||
writeFile(filename, tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//данная функция записывает файл из буфера страницами указанного размера
|
//данная функция записывает файл из буфера страницами указанного размера
|
||||||
void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, size_t length, size_t headerLenth, size_t frameSize) {
|
void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, size_t length, size_t headerLenth, size_t frameSize) {
|
||||||
String path = filepath(filename);
|
String path = filepath(filename);
|
||||||
@@ -31,6 +23,14 @@ void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, size_t l
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void writeStrValueToJsonFile(const String& filename, String key, String value) {
|
||||||
|
// String tmp = readFile(filename, 4096);
|
||||||
|
// if (!jsonWriteStr_(tmp, key, value)) {
|
||||||
|
// Serial.println(F("failed write json value to file"));
|
||||||
|
// }
|
||||||
|
// writeFile(filename, tmp);
|
||||||
|
// }
|
||||||
|
|
||||||
//данная функция читает из файла страницами указанного размера
|
//данная функция читает из файла страницами указанного размера
|
||||||
// void readFileUint8tByFrames(const String& filename, size_t frameSize) {
|
// void readFileUint8tByFrames(const String& filename, size_t frameSize) {
|
||||||
// String path = filepath(filename);
|
// String path = filepath(filename);
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
|
void writeUint8tToString(uint8_t* payload, size_t length, size_t headerLenth, String& payloadStr) {
|
||||||
|
payloadStr = "";
|
||||||
|
payloadStr.reserve(length + 1);
|
||||||
|
for (size_t i = headerLenth; i < length; i++) {
|
||||||
|
payloadStr += (char)payload[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String selectToMarkerLast(String str, String found) {
|
String selectToMarkerLast(String str, String found) {
|
||||||
int p = str.lastIndexOf(found);
|
int p = str.lastIndexOf(found);
|
||||||
return str.substring(p + found.length());
|
return str.substring(p + found.length());
|
||||||
|
|||||||
Reference in New Issue
Block a user