mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
парсинг данных страниц в вебе и отправка виджетов в приложение
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -48,6 +48,7 @@
|
|||||||
#include "Utils/JsonUtils.h"
|
#include "Utils/JsonUtils.h"
|
||||||
#include "Utils/SerialPrint.h"
|
#include "Utils/SerialPrint.h"
|
||||||
#include "Utils/StringUtils.h"
|
#include "Utils/StringUtils.h"
|
||||||
|
#include "PeriodicTasks.h"
|
||||||
|
|
||||||
/*********************************************************************************************************************
|
/*********************************************************************************************************************
|
||||||
*****************************************глобальные объекты классов***************************************************
|
*****************************************глобальные объекты классов***************************************************
|
||||||
|
|||||||
@@ -5,3 +5,6 @@
|
|||||||
|
|
||||||
extern void periodicTasksInit();
|
extern void periodicTasksInit();
|
||||||
extern void printGlobalVarSize();
|
extern void printGlobalVarSize();
|
||||||
|
|
||||||
|
extern void handleError(String errorId, String errorValue);
|
||||||
|
extern void handleError(String errorId, int errorValue);
|
||||||
@@ -52,6 +52,10 @@ void setup() {
|
|||||||
|
|
||||||
//инициализация задач переодического выполнения
|
//инициализация задач переодического выполнения
|
||||||
periodicTasksInit();
|
periodicTasksInit();
|
||||||
|
|
||||||
|
// test
|
||||||
|
Serial.println("-------test start--------");
|
||||||
|
Serial.println("--------test end---------");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
@@ -248,73 +248,43 @@ boolean publishInfo(const String& topic, const String& data) {
|
|||||||
return mqtt.publish(path.c_str(), data.c_str(), false);
|
return mqtt.publish(path.c_str(), data.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
|
||||||
void publishWidgets() {
|
void publishWidgets() {
|
||||||
if (all_widgets != "") {
|
auto file = seekFile("layout.json");
|
||||||
int counter = 0;
|
|
||||||
String line;
|
|
||||||
int psn_1 = 0;
|
|
||||||
int psn_2;
|
|
||||||
do {
|
|
||||||
psn_2 = all_widgets.indexOf("\r\n", psn_1); //\r\n
|
|
||||||
line = all_widgets.substring(psn_1, psn_2);
|
|
||||||
line.replace("\n", "");
|
|
||||||
line.replace("\r\n", "");
|
|
||||||
// jsonWriteStr(line, "id", String(counter));
|
|
||||||
// jsonWriteStr(line, "pageId", String(counter));
|
|
||||||
counter++;
|
|
||||||
sendMQTT("config", line);
|
|
||||||
Serial.println("[V] " + line);
|
|
||||||
psn_1 = psn_2 + 1;
|
|
||||||
} while (psn_2 + 2 < all_widgets.length());
|
|
||||||
getMemoryLoad("I after send all widgets");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LAYOUT_IN_RAM
|
|
||||||
void publishWidgets() {
|
|
||||||
auto file = seekFile("layout.txt");
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
SerialPrint("E", F("MQTT"), F("no file layout.txt"));
|
SerialPrint("E", F("MQTT"), F("no file layout.json"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (file.available()) {
|
size_t size = file.size();
|
||||||
String payload = file.readStringUntil('\n');
|
DynamicJsonDocument doc(size * 1.5);
|
||||||
SerialPrint("I", F("MQTT"), "widgets: " + payload);
|
DeserializationError error = deserializeJson(doc, file);
|
||||||
publishData("config", payload);
|
if (error) {
|
||||||
|
SerialPrint("E", F("MQTT"), error.f_str());
|
||||||
|
handleError("jse3", 1);
|
||||||
|
}
|
||||||
|
JsonArray arr = doc.as<JsonArray>();
|
||||||
|
for (JsonVariant value : arr) {
|
||||||
|
publishData("config", value.as<String>());
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void publishState() {
|
void publishState() {
|
||||||
//// берет строку json и ключи превращает в топики а значения колючей в них посылает
|
String json = "{}";
|
||||||
// String str;
|
jsonMerge(json, paramsHeapJson);
|
||||||
// if (paramsHeapJson != "{}") {
|
jsonMerge(json, paramsFlashJson);
|
||||||
// str += paramsHeapJson;
|
json.replace("{", "");
|
||||||
// }
|
json.replace("}", "");
|
||||||
// if (paramsFlashJson != "{}") {
|
json.replace("\"", "");
|
||||||
// str += "," + paramsFlashJson;
|
json += ",";
|
||||||
// }
|
while (json.length() != 0) {
|
||||||
// str.replace("{", "");
|
String tmp = selectToMarker(json, ",");
|
||||||
// str.replace("}", "");
|
String topic = selectToMarker(tmp, ":");
|
||||||
// str.replace("\"", "");
|
String state = deleteBeforeDelimiter(tmp, ":");
|
||||||
// str += ",";
|
if (topic != "" && state != "") {
|
||||||
//
|
publishStatusMqtt(topic, state);
|
||||||
// while (str.length() != 0) {
|
}
|
||||||
// String tmp = selectToMarker(str, ",");
|
json = deleteBeforeDelimiter(json, ",");
|
||||||
//
|
}
|
||||||
// String topic = selectToMarker(tmp, ":");
|
|
||||||
// String state = deleteBeforeDelimiter(tmp, ":");
|
|
||||||
//
|
|
||||||
// if (topic != "" && state != "") {
|
|
||||||
// if (topic != "timenow") {
|
|
||||||
// publishStatusMqtt(topic, state);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// str = deleteBeforeDelimiter(str, ",");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMqttStatus(bool send) {
|
void handleMqttStatus(bool send) {
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ void periodicTasksInit() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleError(String errorId, String errorValue) {
|
||||||
|
jsonWriteStr_(errorsHeapJson, errorId, errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleError(String errorId, int errorValue) {
|
||||||
|
jsonWriteInt_(errorsHeapJson, errorId, errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
void printGlobalVarSize() {
|
void printGlobalVarSize() {
|
||||||
size_t settingsFlashJsonSize = settingsFlashJson.length();
|
size_t settingsFlashJsonSize = settingsFlashJson.length();
|
||||||
// SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize));
|
// SerialPrint(F("i"), F("settingsFlashJson"), String(settingsFlashJsonSize));
|
||||||
@@ -38,3 +46,50 @@ void printGlobalVarSize() {
|
|||||||
jsonWriteInt(errorsHeapJson, "jse1", 1);
|
jsonWriteInt(errorsHeapJson, "jse1", 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
String ESP_getResetReason(void) {
|
||||||
|
return ESP.getResetReason();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
String ESP_getResetReason(void) {
|
||||||
|
return ESP32GetResetReason(0); // CPU 0
|
||||||
|
}
|
||||||
|
String ESP32GetResetReason(uint32_t cpu_no) {
|
||||||
|
// tools\sdk\include\esp32\rom\rtc.h
|
||||||
|
switch (rtc_get_reset_reason((RESET_REASON)cpu_no)) {
|
||||||
|
case POWERON_RESET:
|
||||||
|
return F("Vbat power on reset"); // 1
|
||||||
|
case SW_RESET:
|
||||||
|
return F("Software reset digital core"); // 3
|
||||||
|
case OWDT_RESET:
|
||||||
|
return F("Legacy watch dog reset digital core"); // 4
|
||||||
|
case DEEPSLEEP_RESET:
|
||||||
|
return F("Deep Sleep reset digital core"); // 5
|
||||||
|
case SDIO_RESET:
|
||||||
|
return F("Reset by SLC module, reset digital core"); // 6
|
||||||
|
case TG0WDT_SYS_RESET:
|
||||||
|
return F("Timer Group0 Watch dog reset digital core"); // 7
|
||||||
|
case TG1WDT_SYS_RESET:
|
||||||
|
return F("Timer Group1 Watch dog reset digital core"); // 8
|
||||||
|
case RTCWDT_SYS_RESET:
|
||||||
|
return F("RTC Watch dog Reset digital core"); // 9
|
||||||
|
case INTRUSION_RESET:
|
||||||
|
return F("Instrusion tested to reset CPU"); // 10
|
||||||
|
case TGWDT_CPU_RESET:
|
||||||
|
return F("Time Group reset CPU"); // 11
|
||||||
|
case SW_CPU_RESET:
|
||||||
|
return F("Software reset CPU"); // 12
|
||||||
|
case RTCWDT_CPU_RESET:
|
||||||
|
return F("RTC Watch dog Reset CPU"); // 13
|
||||||
|
case EXT_CPU_RESET:
|
||||||
|
return F("or APP CPU, reseted by PRO CPU"); // 14
|
||||||
|
case RTCWDT_BROWN_OUT_RESET:
|
||||||
|
return F("Reset when the vdd voltage is not stable"); // 15
|
||||||
|
case RTCWDT_RTC_RESET:
|
||||||
|
return F("RTC Watch dog reset digital core and rtc module"); // 16
|
||||||
|
default:
|
||||||
|
return F("NO_MEAN"); // 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -17,14 +17,14 @@ void standWebServerInit() {
|
|||||||
HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
HTTP.send(200, "application/json", readFile(F("settings.json"), 20000));
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
HTTP.on("/errors.json", HTTP_GET, []() {
|
||||||
|
HTTP.send(200, "application/json", errorsHeapJson);
|
||||||
|
});
|
||||||
|
|
||||||
HTTP.on("/config.json", HTTP_GET, []() {
|
HTTP.on("/config.json", HTTP_GET, []() {
|
||||||
HTTP.send(200, "application/json", readFile(F("config.json"), 20000));
|
HTTP.send(200, "application/json", readFile(F("config.json"), 20000));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,7 +51,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
//**отправка**//
|
//**отправка**//
|
||||||
if (headerStr == "/|") {
|
if (headerStr == "/|") {
|
||||||
sendFileToWs("/layout.json", num, 1024);
|
sendFileToWs("/layout.json", num, 1024);
|
||||||
standWebSocket.sendTXT(num, paramsHeapJson);
|
String json = "{}";
|
||||||
|
jsonMerge(json, paramsHeapJson);
|
||||||
|
jsonMerge(json, paramsFlashJson);
|
||||||
|
standWebSocket.sendTXT(num, json);
|
||||||
}
|
}
|
||||||
//**сохранение**//
|
//**сохранение**//
|
||||||
if (headerStr == "/tuoyal|") {
|
if (headerStr == "/tuoyal|") {
|
||||||
@@ -97,6 +100,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length)
|
|||||||
handleMqttStatus(false, 8); //меняем статус на неопределенный
|
handleMqttStatus(false, 8); //меняем статус на неопределенный
|
||||||
mqttReconnect(); //начинаем переподключение
|
mqttReconnect(); //начинаем переподключение
|
||||||
standWebSocket.sendTXT(num, errorsHeapJson); //отправляем что статус неопределен
|
standWebSocket.sendTXT(num, errorsHeapJson); //отправляем что статус неопределен
|
||||||
|
standWebSocket.sendTXT(num, ssidListHeapJson);
|
||||||
}
|
}
|
||||||
// page list ==========================================================================
|
// page list ==========================================================================
|
||||||
//**отправка**//
|
//**отправка**//
|
||||||
|
|||||||
Reference in New Issue
Block a user