From abbfcec92cc0a0a1dacb67b5268d39a7968f34e8 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Wed, 26 Aug 2020 01:03:45 +0300 Subject: [PATCH] Working version with NotAsinc class --- data/set.device.json | 74 +++++++++++++++++++++++++++++++++++++++++ include/Cmd.h | 3 +- include/Consts.h | 3 +- include/Global.h | 2 ++ include/Module/Runner.h | 2 +- src/Cmd.cpp | 22 ++++++++++-- src/MqttClient.cpp | 2 ++ src/Scenario.cpp | 2 +- src/Web.cpp | 31 ++++++++--------- src/main.cpp | 10 +++--- 10 files changed, 123 insertions(+), 28 deletions(-) diff --git a/data/set.device.json b/data/set.device.json index cf059244..6dc2932b 100644 --- a/data/set.device.json +++ b/data/set.device.json @@ -21,6 +21,33 @@ { "type": "hr" }, + { + "type": "h4", + "title": "Device ID: {{chipID}}" + }, + { + "type": "h4", + "title": "IP address: {{ip}}" + }, + { + "type": "h4", + "title": "Time: {{time}}" + }, + { + "type": "h4", + "title": "Uptime: {{uptime}}" + }, + { + "type": "h4", + "title": "Build version: {{firmware_version}}" + }, + { + "type": "h4", + "title": "LittleFS version: 2.3.5" + }, + { + "type": "hr" + }, { "type": "dropdown", "name": "help-url", @@ -52,14 +79,61 @@ "action": "/set?saveItems", "class": "btn btn-block btn-default" }, + { + "type": "hr" + }, { "type": "link", "title": "Удалить все", "action": "/set?delAllItems", "class": "btn btn-block btn-default" }, + { + "type": "h2", + "title": "Сценарии" + }, + { + "type": "checkbox", + "name": "scen", + "title": "Включить сценарии", + "action": "/set?scen=[[scen]]", + "state": "{{scen}}" + }, + { + "type": "file", + "state": "dev_scen.txt", + "style": "width:100%;height:350px", + "title": "Сохранить", + "action": "/set?sceninit", + "class": "btn btn-block btn-default" + }, + { + "type": "link", + "title": "Инструкция к системе автоматизации", + "action": "https://github.com/IoTManagerProject/IoTManager/wiki", + "class": "btn btn-block btn-default" + }, + { + "type": "link", + "title": "Очистить логи сенсоров", + "action": "/set?cleanlog", + "class": "btn btn-block btn-default" + }, { "type": "hr" + }, + { + "type": "h3", + "name": "my-block", + "style": "position:fixed;top:50%;left:50%;width:400px;margin-left:-200px;text-align:center;", + "class": "hidden" + }, + { + "type": "button", + "title": "Обновить прошивку устройства", + "action": "/check", + "response": "[[my-block]]", + "class": "btn btn-block btn-default" } ] } \ No newline at end of file diff --git a/include/Cmd.h b/include/Cmd.h index a536a0e5..70bf975e 100644 --- a/include/Cmd.h +++ b/include/Cmd.h @@ -42,4 +42,5 @@ extern void firmwareUpdate(); extern void loadScenario(); extern void fileExecute(const String& filename); -extern void stringExecute(String& cmdStr); \ No newline at end of file +extern void csvExecute(String& cmdStr); +extern void spaceExecute(String& cmdStr); \ No newline at end of file diff --git a/include/Consts.h b/include/Consts.h index a7d05935..bab4e689 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -85,13 +85,14 @@ enum TimerTask_t { WIFI_SCAN, TEST }; enum notAsincActions { - ZERO, + do_ZERO, do_UPGRADE, do_GETLASTVERSION, do_UDPDATAPARSE, do_MQTTUDP, do_BUSSCAN, do_MQTTPARAMSCHANGED, + do_LAST, }; enum ErrorType_t { diff --git a/include/Global.h b/include/Global.h index 8b3cb440..e0317b4e 100644 --- a/include/Global.h +++ b/include/Global.h @@ -47,6 +47,8 @@ extern Clock* timeNow; extern TickerScheduler ts; + + extern WiFiClient espClient; extern PubSubClient mqtt; diff --git a/include/Module/Runner.h b/include/Module/Runner.h index 3d15c421..6d6c97ec 100644 --- a/include/Module/Runner.h +++ b/include/Module/Runner.h @@ -12,6 +12,6 @@ class CmdRunner : public Runner { public: void run(const char* cmd, Print* out) override { String cmdStr{cmd}; - stringExecute(cmdStr); + csvExecute(cmdStr); } }; \ No newline at end of file diff --git a/src/Cmd.cpp b/src/Cmd.cpp index ca4a1329..1a436d9f 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -128,6 +128,12 @@ void buttonOut() { void buttonOutSet() { String key = sCmd.order(); String state = sCmd.next(); + + Serial.println("=="); + Serial.println(key); + Serial.println(state); + Serial.println("=="); + String pin = jsonReadStr(configOptionJson, key + "_pin"); String inv = jsonReadStr(configOptionJson, key + "_inv"); if (inv == "") { @@ -461,11 +467,10 @@ void addCommandLoop(const String &cmdStr) { void fileExecute(const String &filename) { String cmdStr = readFile(filename, 2048); - stringExecute(cmdStr); + csvExecute(cmdStr); } -void stringExecute(String &cmdStr) { - cmdStr.replace("x;",""); +void csvExecute(String &cmdStr) { cmdStr.replace(";"," "); cmdStr += "\r\n"; cmdStr.replace("\r\n", "\n"); @@ -479,6 +484,17 @@ void stringExecute(String &cmdStr) { } } +void spaceExecute(String &cmdStr) { + cmdStr += "\r\n"; + cmdStr.replace("\r\n", "\n"); + cmdStr.replace("\r", "\n"); + while (cmdStr.length()) { + String buf = selectToMarker(cmdStr, "\n"); + sCmd.readStr(buf); + cmdStr = deleteBeforeDelimiter(cmdStr, "\n"); + } +} + void loopCmd() { if (order_loop.length()) { String tmp = selectToMarker(order_loop, ","); //выделяем первую команду rel 5 1, diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index 168f7cd0..9e6c1b32 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -122,6 +122,7 @@ boolean connect() { void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) { String topicStr = String(topic); + pm.info(topicStr); String payloadStr; @@ -142,6 +143,7 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) { #endif } else if (topicStr.indexOf("control")) { + //iotTeam/12882830-1458415/light 1 String key = selectFromMarkerToMarker(topicStr, "/", 3); diff --git a/src/Scenario.cpp b/src/Scenario.cpp index c7304422..51ff5875 100644 --- a/src/Scenario.cpp +++ b/src/Scenario.cpp @@ -62,7 +62,7 @@ void loopScenario() { block = deleteBeforeDelimiter(block, "\n"); pm.info("do: " + block); // выполняем все команды - stringExecute(block); + spaceExecute(block); } } } diff --git a/src/Web.cpp b/src/Web.cpp index baa1a20b..8cf71556 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -29,37 +29,38 @@ void web_init() { server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) { //==============================presets=========================================================================================================== - uint8_t preset; - if (parseRequestForPreset(request, preset)) { - pm.info("activate #" + String(preset, DEC)); - String configFile = DEVICE_CONFIG_FILE; - String scenarioFile = DEVICE_SCENARIO_FILE; - copyFile(getConfigFile(preset, CT_CONFIG), configFile); - copyFile(getConfigFile(preset, CT_SCENARIO), scenarioFile); - Device_init(); - loadScenario(); - request->redirect("/?set.device"); - } + //uint8_t preset; + //if (parseRequestForPreset(request, preset)) { + // pm.info("activate #" + String(preset, DEC)); + // String configFile = DEVICE_CONFIG_FILE; + // String scenarioFile = DEVICE_SCENARIO_FILE; + // copyFile(getConfigFile(preset, CT_CONFIG), configFile); + // copyFile(getConfigFile(preset, CT_SCENARIO), scenarioFile); + // Device_init(); + // loadScenario(); + // request->redirect("/?set.device"); + //} - //==============================list of items==================================================================================================== + //==============================set.device.json==================================================================================================== if (request->hasArg("addItem")) { String name = request->getParam("addItem")->value(); addItem(name); Device_init(); - request->redirect("/?setn.device"); + request->redirect("/?set.device"); } if (request->hasArg("delAllItems")) { delAllItems(); Device_init(); - request->redirect("/?setn.device"); + request->redirect("/?set.device"); } if (request->hasArg("saveItems")) { Device_init(); - request->redirect("/?setn.device"); + request->redirect("/?set.device"); } + //==============================init==================================================================================================== if (request->hasArg("devinit")) { Device_init(); request->send(200); diff --git a/src/main.cpp b/src/main.cpp index f6e2f00c..9994f67a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,8 @@ void setup() { setChipId(); + myNotAsincActions = new NotAsinc(do_LAST); + pm.info("FS"); fileSystemInit(); @@ -51,9 +53,7 @@ void setup() { pm.info("Uptime"); uptime_init(); - if (!TELEMETRY_UPDATE_INTERVAL) { - pm.info("Telemetry: Disabled"); - } + pm.info("telemetry"); telemetry_init(); pm.info("Updater"); @@ -78,8 +78,6 @@ void setup() { just_load = false; initialized = true; - - myNotAsincActions = new NotAsinc(5); } void loop() { @@ -97,9 +95,9 @@ void loop() { #endif timeNow->loop(); MqttClient::loop(); - loopCmd(); mySwitch->loop(); loopScenario(); + loopCmd(); loopSerial(); myNotAsincActions->loop();