mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
начал добавление виджетов
This commit is contained in:
@@ -7,14 +7,16 @@ void createWidget(String& parameters) {
|
|||||||
String page = jsonReadStr(parameters, "page");
|
String page = jsonReadStr(parameters, "page");
|
||||||
String descr = jsonReadStr(parameters, "descr");
|
String descr = jsonReadStr(parameters, "descr");
|
||||||
|
|
||||||
|
SerialPrint(F("i"), F("Widget"), "Start create widget: " + widget);
|
||||||
|
|
||||||
if (widget != "na") {
|
if (widget != "na") {
|
||||||
String buf = "{}";
|
String buf = "{}";
|
||||||
if (!loadWidget(widget, buf)) {
|
if (!loadWidget(widget, buf)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if (_cnt != "") {
|
// if (_cnt != "") {
|
||||||
// if (widget.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
|
// if (widget.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
#ifdef GATE_MODE
|
#ifdef GATE_MODE
|
||||||
jsonWriteStr(buf, "info", " ");
|
jsonWriteStr(buf, "info", " ");
|
||||||
@@ -25,21 +27,37 @@ void createWidget(String& parameters) {
|
|||||||
jsonWriteStr(buf, "descr", descr);
|
jsonWriteStr(buf, "descr", descr);
|
||||||
jsonWriteStr(buf, "topic", prex + "/" + id);
|
jsonWriteStr(buf, "topic", prex + "/" + id);
|
||||||
|
|
||||||
|
SerialPrint(F("i"), F("Widget"), buf);
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
all_widgets += widget + "\r\n";
|
all_widgets += widget + "\r\n";
|
||||||
#else
|
#else
|
||||||
addFileLn("layout.txt", buf);
|
addFileLn("layout.json", buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadWidget(const String& widget, String& buf) {
|
bool loadWidget(const String& widget, String& buf) {
|
||||||
buf = readFile(getWidgetFile(widget), 2048);
|
File file = seekFile("/widgets.json");
|
||||||
bool res = !(buf == "Failed" || buf == "Large");
|
file.find("[");
|
||||||
if (!res) {
|
bool ret = false;
|
||||||
SerialPrint("E", "module", "on load" + widget);
|
while (file.available()) {
|
||||||
|
String jsonArrayElement = file.readStringUntil('}') + "}";
|
||||||
|
if (jsonArrayElement.startsWith(",")) {
|
||||||
|
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
||||||
|
}
|
||||||
|
String name;
|
||||||
|
if (!jsonRead(jsonArrayElement, F("name"), name)) { //если нет такого ключа в представленном json или он не валидный
|
||||||
|
SerialPrint(F("E"), F("Config"), "json error " + name);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (name == widget) {
|
||||||
|
buf = jsonArrayElement;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const String getWidgetFile(const String& name) {
|
const String getWidgetFile(const String& name) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ bool fileSystemInit() {
|
|||||||
void globalVarsSync() {
|
void globalVarsSync() {
|
||||||
settingsFlashJson = readFile(F("settings.json"), 4096);
|
settingsFlashJson = readFile(F("settings.json"), 4096);
|
||||||
settingsFlashJson.replace("\r\n", "");
|
settingsFlashJson.replace("\r\n", "");
|
||||||
|
writeFile("layout.json", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveSettingsFlashJson() {
|
void saveSettingsFlashJson() {
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ void setup() {
|
|||||||
|
|
||||||
configure("/config.json");
|
configure("/config.json");
|
||||||
|
|
||||||
// readFileBin("/config.json");
|
|
||||||
|
|
||||||
//создали задачу которая будет выполняться каждые 30 секунд
|
//создали задачу которая будет выполняться каждые 30 секунд
|
||||||
ts.add(
|
ts.add(
|
||||||
MYTEST, 1000 * 30, [&](void*) {
|
MYTEST, 1000 * 30, [&](void*) {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ void standWebServerInit() {
|
|||||||
HTTP.send(200, "application/json", readFile(F("config.json"), 10000));
|
HTTP.send(200, "application/json", readFile(F("config.json"), 10000));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
HTTP.on("/layout.json", HTTP_GET, []() {
|
||||||
|
HTTP.send(200, "application/json", readFile(F("layout.json"), 10000));
|
||||||
|
});
|
||||||
|
|
||||||
HTTP.on("/restart", HTTP_GET, []() {
|
HTTP.on("/restart", HTTP_GET, []() {
|
||||||
// ESP.restart();
|
// ESP.restart();
|
||||||
HTTP.send(200, "text/plain", "ok");
|
HTTP.send(200, "text/plain", "ok");
|
||||||
|
|||||||
Reference in New Issue
Block a user