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