From a8396729327d8bd095a42f3ab13b923f3f046dbd Mon Sep 17 00:00:00 2001 From: Bogdan Pilyugin Date: Thu, 13 Apr 2023 16:16:18 +0200 Subject: [PATCH] web design copleted, upload implemented --- HTML/application.html | 3 +- HTML/espfs.paths | 58 ++++----- HTML/res/appstyles.css | 16 ++- HTML/res/cron.js | 104 ++++++++++------ HTML/res/styles.css | 2 + dependencies.lock | 18 +-- main/HTTPPostCustom.c | 264 ++++++++++++++++++++++------------------- 7 files changed, 259 insertions(+), 206 deletions(-) diff --git a/HTML/application.html b/HTML/application.html index 1e8203c..002fba4 100644 --- a/HTML/application.html +++ b/HTML/application.html @@ -20,11 +20,10 @@
TIMER
+
- -
diff --git a/HTML/espfs.paths b/HTML/espfs.paths index b5a6c0d..0976c73 100644 --- a/HTML/espfs.paths +++ b/HTML/espfs.paths @@ -1,30 +1,30 @@ -adapters.html -api -api/dbg.json -api/dbg2.json -api/gendata.json -api/mem.json -api/set1.json -api/set2.json -api/set3.json -api/stat.json -api/status.json -api/tmr.json -api/wifiscan.json -application.html -favicon.ico -index.html -info.html -reboot.html -res -res/appstyles.css -res/ca_cert.pem -res/cron.js -res/iconsfont.css -res/iconsfont.woff2 -res/logo.png -res/main.js -res/res.js -res/styles.css -services.html +adapters.html +api +api/dbg.json +api/dbg2.json +api/gendata.json +api/mem.json +api/set1.json +api/set2.json +api/set3.json +api/stat.json +api/status.json +api/tmr.json +api/wifiscan.json +application.html +favicon.ico +index.html +info.html +reboot.html +res +res/appstyles.css +res/ca_cert.pem +res/cron.js +res/iconsfont.css +res/iconsfont.woff2 +res/logo.png +res/main.js +res/res.js +res/styles.css +services.html system.html \ No newline at end of file diff --git a/HTML/res/appstyles.css b/HTML/res/appstyles.css index 8cda3dc..8a32b2d 100644 --- a/HTML/res/appstyles.css +++ b/HTML/res/appstyles.css @@ -21,7 +21,7 @@ .pwrbox{width:80%; height:auto; padding:5px; margin:10px auto; box-sizing:border-box;} .pwrbox td {font: .9rem consolas, monospace; width:30%; padding:0;margin:0;} -.container{margin: 10px; +.container{ display: flex; flex-wrap:wrap;} @@ -158,9 +158,10 @@ input:checked + .slider:before { .timer { width:100%; +margin: 10px 0 0 0; padding: 10px; -margin:5px; border: 1px solid rgba(255, 255, 255, 0.4); +border-radius: 10px; } .timerrec { @@ -187,10 +188,17 @@ width:100%; .crselect { -height:120px; +display: inline-block; +vertical-align: top; +overflow: hidden; +height:auto; +min-height:30px; +width:120px; margin-top: 0; } .selhed { margin: 15px 5px 2px 5px; -} \ No newline at end of file +} + + diff --git a/HTML/res/cron.js b/HTML/res/cron.js index 9d47e65..98b95ac 100644 --- a/HTML/res/cron.js +++ b/HTML/res/cron.js @@ -1,11 +1,36 @@ objects_test = ["scene_1", "scene_2", "scene_3", "scene_4", "scene_5", "scene_6", "scene_7", "scene_8", "scene_9", "scene_10", "scene_11", "scene_12", "scene_13", "scene_14", "scene_15", "scene_16"]; actions_test = ["start", "stop"]; -timarr_test = [{ 'num': 1, 'obj': 2, 'act': 0, 'cron': '*/2 * * * * *' }, -{ 'num': 2, 'obj': 12, 'act': 1, 'cron': '6 0 12 * * *' }, -{ 'num': 3, 'obj': 8, 'act': 0, 'cron': '* * * * * *' }]; -function savetm(n) { +timarr_test = [ +{ "num": 1, "enab":1, "name":"Timer1 name", "obj": 2, "act": 0, "cron": "*/2 * * * * *" }, +{ "num": 2, "enab":0, "name":"Timer2 name", "obj": 12, "act": 1, "cron": "6 0 12 * * *" }, +{ "num": 3, "enab":1, "name":"Timer3 name", "obj": 8, "act": 0, "cron": "* * * * * *" } +]; +function PostData(data,page,conf,alrt,reld) { +if(conf){if (!confirm(conf)) return;} +var xhr = new XMLHttpRequest(); +xhr.open('POST',page, true); +xhr.timeout = 5000; +xhr.send(data); +xhr.onreadystatechange = function() { +if (xhr.readyState != 4) return; +if (Number(xhr.status) >= 400) {alert(xhr.status+': '+xhr.statusText);} +else {if(reld)location.reload(); +if(alrt) alert(alrt); +}}} + +function savetm(n) { +var payload = "tmrec={\"num\":"+n+","; +payload += "\"enab\":"+((document.getElementById("encb"+n).checked)?1:0)+","; +payload += "\"name\":\""+document.getElementById("tname"+n).value+"\","; +payload += "\"obj\":"+document.getElementById("object"+n).value+","; +payload += "\"act\":"+document.getElementById("action"+n).value+","; +payload += "\"cron\":\""+document.getElementById("cron"+n).value+"\""; +payload += "}"; +console.log(payload); +PostData(payload, "application.html", false, false, false); } + function extractSelectArr(select) { var result = []; @@ -89,19 +114,15 @@ function handleSelect(tnum, type) cinp.value = c[0] + " " + c[1] + " " + c[2] + " " + c[3] + " " + c[4] + " " + c[5]; } function deltm(n) { + if(confirm("Confirm delete timer "+n+"?") == true){ timarr_test.splice(n - 1, 1); - drawtimers(timarr_test); -} -function closecron(n) { - var target = document.getElementById("cronext"+n); - var content = ""; - target.innerHTML = content; + drawtimers(timarr_test);} } function setcron(n) { var target = document.getElementById("cronext" + n); var content = ""; content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -112,7 +133,7 @@ function setcron(n) { content += ("
"); content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -123,7 +144,7 @@ function setcron(n) { content += ("
"); content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -133,7 +154,7 @@ function setcron(n) { content += ("
"); content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -144,7 +165,7 @@ function setcron(n) { content += ("
"); content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -165,7 +186,7 @@ function setcron(n) { content += ("
"); content +=("
"); - content += ("
"); content += (""); content += (""); content += (""); @@ -192,42 +213,51 @@ function drawtimers(tarr) { content += (""); content += ("
"); + content += ("
"); + content +=(""); + var enb = (tarr[i - 1].enab == 1) ? "checked" : ""; + content += ("
"); + + content += ("
"); + content +=(""); + content += ("
"); + + content += ("
"); + content +=("
"); + content += ("
"); + + content += ("
"); + content +=("
"); + content += ("
"); + content += ("
"); content +=(""); - content += (""); - content += ("
") + content += ("
"); + content += ("
") + content += ("
"); /*Extended editor content*/ content += ("
"); - content +=("
"); - content += (""); - - content +=(""); - content += ("
"); - content += (""); content += (""); - content += (""); - target.innerHTML = content; } + target.innerHTML = content; } function applytm() { } function addtm() { var num = timarr_test.length + 1; - timarr_test.push({ 'num': num, 'start': 1500000000, 'cron': '* * * * * *' }); + timarr_test.push({ 'num': num, 'enab':1, 'name':'Timer'+num+' name', 'obj': 0, 'act': 0, 'cron': '* * * * * *' }); drawtimers(timarr_test); } \ No newline at end of file diff --git a/HTML/res/styles.css b/HTML/res/styles.css index 5088516..5dfb9ab 100644 --- a/HTML/res/styles.css +++ b/HTML/res/styles.css @@ -319,6 +319,7 @@ select { -moz-appearance: none; appearance: none; background-color: var(--panel-bgr-color); + width: 150px; } .btn{min-width:100px; color:var(--text-color);} @@ -363,6 +364,7 @@ input[type="radio"] { margin-top: -1px; vertical-align: middle;} margin: 0 0 10px 10px; padding: 10px; background-color:var(--panel-bgr-color); + border-radius: 10px; } .ml { diff --git a/dependencies.lock b/dependencies.lock index b34c22b..55ac77a 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -1,9 +1,9 @@ -dependencies: - idf: - component_hash: null - source: - type: idf - version: 4.4.4 -manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd -target: esp32 -version: 1.0.0 +dependencies: + idf: + component_hash: null + source: + type: idf + version: 4.4.4 +manifest_hash: f9b3d78d7d56685d1c543701158a0fab7a56c908117ed70644f77e4247c831ae +target: esp32 +version: 1.0.0 diff --git a/main/HTTPPostCustom.c b/main/HTTPPostCustom.c index 6184da7..7a85799 100644 --- a/main/HTTPPostCustom.c +++ b/main/HTTPPostCustom.c @@ -1,125 +1,139 @@ - /*! Copyright 2022 Bogdan Pilyugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * \file HTTPPostCustom.c - * \version 1.0 - * \date 2022-08-18 - * \author Bogdan Pilyugin - * \brief - * \details - * \copyright Apache License, Version 2.0 - */ -#include "webguiapp.h" - -const char pg_40[] = "index40.html"; -const char pg_42[] = "index42.html"; -const char pg_43[] = "index43.html"; -const char pg_44[] = "index44.html"; - -static HTTP_IO_RESULT HTTPPostIndex40(httpd_req_t *req, char *PostData); -static HTTP_IO_RESULT HTTPPostIndex42(httpd_req_t *req, char *PostData); -static HTTP_IO_RESULT HTTPPostIndex43(httpd_req_t *req, char *PostData); -static HTTP_IO_RESULT HTTPPostIndex44(httpd_req_t *req, char *PostData); - -HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData) -{ - - - if (!memcmp(filename, pg_40, sizeof(pg_40))) - return HTTPPostIndex40(req, PostData); - if (!memcmp(filename, pg_42, sizeof(pg_42))) - return HTTPPostIndex42(req, PostData); - if (!memcmp(filename, pg_43, sizeof(pg_43))) - return HTTPPostIndex43(req, PostData); - if (!memcmp(filename, pg_44, sizeof(pg_44))) - return HTTPPostIndex44(req, PostData); - - - return HTTP_IO_DONE; -} - -static HTTP_IO_RESULT HTTPPostIndex40(httpd_req_t *req, char *PostData) -{ - char tmp[8]; - if (httpd_query_key_value(PostData, "cmd", tmp, 4) == ESP_OK) - { - if (!strcmp(tmp, (const char*) "1")) - { - // SetCTRL_BAT(ON); - } - else if (!strcmp(tmp, (const char*) "2")) - { - // SetCTRL_BAT(OFF); - } - else if (!strcmp(tmp, (const char*) "3")) - { - //MQTTStart(); - } - else if (!strcmp(tmp, (const char*) "4")) - { - // MQTTStop(); - } - else if (!strcmp(tmp, (const char*) "5")) - { - - } - else if (!strcmp(tmp, (const char*) "6")) - { - - } - else if (!strcmp(tmp, (const char*) "7")) - { - //SetDefaultNetIF(GetETHNetifAdapter()); - } - else if (!strcmp(tmp, (const char*) "8")) - { - //SetDefaultNetIF(GetSTANetifAdapter()); - } - else if (!strcmp(tmp, (const char*) "9")) - { - //SetDefaultNetIF(GetPPPNetifAdapter()); - } - else if (!strcmp(tmp, (const char*) "10")) - { - //NextDefaultNetIF(); - } - else if (!strcmp(tmp, (const char*) "11")) - { - //PrintNetifs(); - } - else if (!strcmp(tmp, (const char*) "12")) - { - // SendTestEvent(); - } - - } - return HTTP_IO_DONE; -} - -static HTTP_IO_RESULT HTTPPostIndex42(httpd_req_t *req, char *PostData) -{ - return HTTP_IO_DONE; -} - -static HTTP_IO_RESULT HTTPPostIndex43(httpd_req_t *req, char *PostData) -{ - return HTTP_IO_DONE; -} - -static HTTP_IO_RESULT HTTPPostIndex44(httpd_req_t *req, char *PostData) -{ - return HTTP_IO_DONE; -} - - + /*! Copyright 2022 Bogdan Pilyugin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * \file HTTPPostCustom.c + * \version 1.0 + * \date 2022-08-18 + * \author Bogdan Pilyugin + * \brief + * \details + * \copyright Apache License, Version 2.0 + */ +#include "webguiapp.h" + +const char pg_40[] = "index40.html"; +const char pg_42[] = "index42.html"; +const char pg_43[] = "index43.html"; +const char pg_44[] = "index44.html"; +const char url_application[] = "application.html"; + +static HTTP_IO_RESULT HTTPPostIndex40(httpd_req_t *req, char *PostData); +static HTTP_IO_RESULT HTTPPostIndex42(httpd_req_t *req, char *PostData); +static HTTP_IO_RESULT HTTPPostIndex43(httpd_req_t *req, char *PostData); +static HTTP_IO_RESULT HTTPPostIndex44(httpd_req_t *req, char *PostData); +static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData); + +HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData) +{ + + + if (!memcmp(filename, pg_40, sizeof(pg_40))) + return HTTPPostIndex40(req, PostData); + if (!memcmp(filename, pg_42, sizeof(pg_42))) + return HTTPPostIndex42(req, PostData); + if (!memcmp(filename, pg_43, sizeof(pg_43))) + return HTTPPostIndex43(req, PostData); + if (!memcmp(filename, pg_44, sizeof(pg_44))) + return HTTPPostIndex44(req, PostData); + if (!memcmp(filename, url_application, sizeof(url_application))) + return HTTPPostApplication(req, PostData); + + return HTTP_IO_DONE; +} + + +static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData) +{ + char tmp[512]; + if (httpd_query_key_value(PostData, "tmrec", tmp, sizeof(tmp)) == ESP_OK) + { + ESP_LOGI("HTTP_POST","%s", tmp); + } + return HTTP_IO_DONE; +} + +static HTTP_IO_RESULT HTTPPostIndex40(httpd_req_t *req, char *PostData) +{ + char tmp[8]; + if (httpd_query_key_value(PostData, "cmd", tmp, 4) == ESP_OK) + { + if (!strcmp(tmp, (const char*) "1")) + { + // SetCTRL_BAT(ON); + } + else if (!strcmp(tmp, (const char*) "2")) + { + // SetCTRL_BAT(OFF); + } + else if (!strcmp(tmp, (const char*) "3")) + { + //MQTTStart(); + } + else if (!strcmp(tmp, (const char*) "4")) + { + // MQTTStop(); + } + else if (!strcmp(tmp, (const char*) "5")) + { + + } + else if (!strcmp(tmp, (const char*) "6")) + { + + } + else if (!strcmp(tmp, (const char*) "7")) + { + //SetDefaultNetIF(GetETHNetifAdapter()); + } + else if (!strcmp(tmp, (const char*) "8")) + { + //SetDefaultNetIF(GetSTANetifAdapter()); + } + else if (!strcmp(tmp, (const char*) "9")) + { + //SetDefaultNetIF(GetPPPNetifAdapter()); + } + else if (!strcmp(tmp, (const char*) "10")) + { + //NextDefaultNetIF(); + } + else if (!strcmp(tmp, (const char*) "11")) + { + //PrintNetifs(); + } + else if (!strcmp(tmp, (const char*) "12")) + { + // SendTestEvent(); + } + + } + return HTTP_IO_DONE; +} + +static HTTP_IO_RESULT HTTPPostIndex42(httpd_req_t *req, char *PostData) +{ + return HTTP_IO_DONE; +} + +static HTTP_IO_RESULT HTTPPostIndex43(httpd_req_t *req, char *PostData) +{ + return HTTP_IO_DONE; +} + +static HTTP_IO_RESULT HTTPPostIndex44(httpd_req_t *req, char *PostData) +{ + return HTTP_IO_DONE; +} + +