123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476 |
- #include "html.h"
- #include "html_conf.h"
- #include "html_confAdd.h"
- #include "html_confAdv.h"
- #include "html_confBas.h"
- #include "html_confDevWiFi.h"
- #include "html_confMqtt.h"
- #include "html_confWeb.h"
- #include "html_confTime.h"
- #include "html_confLog.h"
- #include "html_main.h"
- #include "html_redTemps.h"
- #include "html_console.h"
- void httpServerHandleMainPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_main_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_main_body);
- if (httpIsAuthenticatedAdmin()) {
- httpServer.sendContent_P(html_main_body_adminonly);
- if(confWeb.enableConsole) httpServer.sendContent_P(html_main_body_adminonly_console);
- }
- httpServer.sendContent_P(html_main_body2);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleRedTempsPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_redTemps_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_redTemps_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_conf_body);
- if(confWeb.enableConsole) httpServer.sendContent_P(html_conf_body_console);
- httpServer.sendContent_P(html_conf_body_end);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfWebPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confweb_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confweb_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfMqttPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confmqtt_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confmqtt_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfDevWiFiPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confDevWiFi_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confDevWiFi_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfBasPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confbas_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confbas_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfAdvPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confadv_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confadv_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfAddPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_confadd_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confadd_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfTimePage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_conftime_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_conftime_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfLogPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_conflog_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_conflog_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConsolePage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_console_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfSavedPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confsaved_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleConfSavedRestartPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_confsavedrestart_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleRestartPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_restarting_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerHandleClearconfPage() {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_clearconf_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerSendHtmlHeadChunked() {
- httpServer.setContentLength(CONTENT_LENGTH_UNKNOWN); //Enable Chunked Transfer
- httpServer.send(200, "text/html", html_head_part1);
- httpServer.sendContent(FIRMWARE_NAME);
- httpServer.sendContent(" - ");
- httpServer.sendContent(confDevWiFi.deviceName);
- httpServer.sendContent_P(html_head_part2);
- }
- void httpServerSendHtmlBodyPageheadChunked() {
- httpServer.sendContent_P(html_body_pagehead_part1);
- httpServer.sendContent(FIRMWARE_NAME);
- httpServer.sendContent(" - ");
- httpServer.sendContent(confDevWiFi.deviceName);
- httpServer.sendContent_P(html_body_pagehead_part2);
- if(config_was_changed) httpServer.sendContent_P(html_body_pagehead_confchangednote);
- }
- void httpServerSendHtmlFooterChunked() {
- httpServer.sendContent_P(html_footer1);
- httpServer.sendContent("<a href='");
- httpServer.sendContent(FIRMWARE_URL);
- httpServer.sendContent("' target='_blank' style='color:#AAA;'>");
- httpServer.sendContent(FIRMWARE_NAME);
- httpServer.sendContent("</a> v");
- httpServer.sendContent(FIRMWARE_VERSION);
- #ifdef DEBUGMODE
- httpServer.sendContent(" <span style='color:red;font-weight:bold;'>DEBUG</span>");
- #endif
- httpServer.sendContent(" by <a href='");
- httpServer.sendContent(FIRMWARE_COPYRIGHT_URL);
- httpServer.sendContent("' target='_blank' style='color:#AAA;'>");
- httpServer.sendContent(FIRMWARE_COPYRIGHT);
- httpServer.sendContent("</a>");
- httpServer.sendContent_P(html_footer2);
- httpServer.sendContent("");
- httpServer.client().stop();
- }
- boolean httpIsAuthenticated() {
- if (confWeb.http_user_auth) {
- boolean useAuth = false;
- boolean isAuthenticated = false;
- // user authentication enabled - only allow access without authentication if no admin credentials are set
- // or if user1 credentials are empty
- if ((strlen(confWeb.http_user) > 0 && strlen(confWeb.http_pass) > 0) || (strlen(confWeb.http_user1) > 0 && strlen(confWeb.http_pass1) > 0) || (strlen(confWeb.http_user2) > 0 && strlen(confWeb.http_pass2) > 0)) useAuth = true;
- if (useAuth) {
- // allow access if one set of valid credentials are given
- if ((strlen(confWeb.http_user) > 0 && strlen(confWeb.http_pass) > 0)) {
- if (httpServer.authenticate(confWeb.http_user, confWeb.http_pass)) isAuthenticated = true;
- }
- if ((strlen(confWeb.http_user1) > 0 && strlen(confWeb.http_pass1) > 0)) {
- if (httpServer.authenticate(confWeb.http_user1, confWeb.http_pass1)) isAuthenticated = true;
- }
- if ((strlen(confWeb.http_user2) > 0 && strlen(confWeb.http_pass2) > 0)) {
- if (httpServer.authenticate(confWeb.http_user2, confWeb.http_pass2)) isAuthenticated = true;
- }
- // also allow access if admin credentials are set but user1 credentials are empty and user-authentication is enabled
- if ((strlen(confWeb.http_user1) == 0 && strlen(confWeb.http_pass1) == 0)) {
- isAuthenticated = true;
- }
- return isAuthenticated;
- }
- // allow access if all credentials are empty
- else return true;
- }
- // user authentication disabled - only allow access without password if no admin credentials are set
- else {
- if ((strlen(confWeb.http_user) > 0 && strlen(confWeb.http_pass) > 0)) {
- if (httpServer.authenticate(confWeb.http_user, confWeb.http_pass)) return true;
- else return false;
- }
- else return true;
- }
- }
- boolean httpIsAuthenticatedAdmin() {
- boolean auth = false;
- if ((strlen(confWeb.http_user) > 0 && strlen(confWeb.http_pass) > 0)) auth = true;
- if (auth) {
- if (!httpServer.authenticate(confWeb.http_user, confWeb.http_pass)) return false;
- else return true;
- }
- else return true;
- }
- void httpServerHandleNotFound() {
- httpServer.send(404, "text/plain", "404 NOT FOUND");
- }
- void httpSendUnauthorized() {
- httpServer.send (401, "text/plain", "UNAUTHORIZED");
- }
- void httpSend200OK() {
- httpServer.send (200, "text/plain", "OK");
- }
- boolean httpCheckToken() {
- if (confWeb.http_token[0] != '\0') { // dont accept empty token
- if (httpServer.hasArg("token")) {
- char buf[20];
- httpServer.arg("token").toCharArray(buf, 20);
- if (strcmp(buf, confWeb.http_token) == 0) return true;
- else return false;
- }
- else return false;
- }
- else return false;
- }
- void httpServerInit() {
- httpServer.on("/style.css", []() {
- httpServer.sendHeader("cache-control", "max-age=86400", false);
- httpServer.send_P(200, "text/css", html_stylesheet);
- });
- httpServer.on("/wsapp.js", []() {
- httpServer.sendHeader("cache-control", "max-age=86400", false);
- httpServer.send_P(200, "text/javascript", js_wsapp);
- });
- httpServer.on("/api", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /api (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- //sendLog("WEB: /api", LOGLEVEL_INFO);
- if (httpServer.hasArg("BtnPlus")) {
- setTempStepUp();
- sendLog(F("WEB: Btn +"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnMinus")) {
- setTempStepDown();
- sendLog(F("WEB: Btn -"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset0")) {
- setPresetTo(0);
- sendLog(F("WEB: Btn PSet0"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset1")) {
- setPresetTo(1);
- sendLog(F("WEB: Btn PSet1"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset2")) {
- setPresetTo(2);
- sendLog(F("WEB: Btn PSet2"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnOn")) {
- setHeatingmodeTo(1);
- sendLog(F("WEB: Btn ON"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnOff")) {
- setHeatingmodeTo(0);
- sendLog(F("WEB: Btn OFF"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL1Plus")) {
- setTempLowStepUp();
- sendLog(F("WEB: Btn L1+"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL1Minus")) {
- setTempLowStepDown();
- sendLog(F("WEB: Btn L1-"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL2Plus")) {
- setTempLow2StepUp();
- sendLog(F("WEB: Btn L2+"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL2Minus")) {
- setTempLow2StepDown();
- sendLog(F("WEB: Btn L2-"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("setTemp")) {
- sendLog(F("WEB: api?setTemp"), LOGLEVEL_INFO);
- char bufVal[20];
- httpServer.arg("setTemp").toCharArray(bufVal, 20);
- float valueFloat = round(atof(bufVal) * 2.0) / 2.0;
- setTempTo(valueFloat);
- }
- if (httpServer.hasArg("setMode")) {
- sendLog(F("WEB: api?setMode"), LOGLEVEL_INFO);
- char bufVal[20];
- httpServer.arg("setMode").toCharArray(bufVal, 20);
- int valueInt = atoi(bufVal);
- if (valueInt >= 0 && valueInt <= 1) setHeatingmodeTo(valueInt);
- }
- if (httpServer.hasArg("setPreset")) {
- sendLog(F("WEB: api?setPreset"), LOGLEVEL_INFO);
- char bufVal[20];
- httpServer.arg("setPreset").toCharArray(bufVal, 20);
- int valueInt = atoi(bufVal);
- if (valueInt >= 0 && valueInt <= 2) setPresetTo(valueInt);
- }
- //char ch_currTemp[6];
- //char ch_currSetTemp[6];
- //dtostrf(currTemp, 1, 1, ch_currTemp );
- //dtostrf(setTemp, 1, 1, ch_currSetTemp );
- //build json object of program data
- StaticJsonDocument<700> json;
- json["devname"] = confDevWiFi.deviceName;
- json["ssid"] = WiFi.SSID();
- json["WiFiNum"] = persWM.getActiveWiFiNum();
- json["uptime"] = uptimeStr;
- //json["uptime"] = NTP.getUptimeString();
- if(confTime.ntpEnable) {
- char buf[13];
- updateTime();
- strftime(buf, sizeof(buf), "%H:%M", <);
- json["time"] = buf;
- strftime(buf, sizeof(buf), "%d.%m.%Y", <);
- json["date"] = buf;
- }
- json["freeheap"] = ESP.getFreeHeap();
- mqtt_updateCurrentStateName();
- json["mqttstate"] = mqttCurrentStateName;
- //if (mqttclient.state() == -4) json["mqttstate"] = "CONNECTION_TIMEOUT";
- //else if (mqttclient.state() == -3) json["mqttstate"] = "CONNECTION_LOST";
- //else if (mqttclient.state() == -2) json["mqttstate"] = "CONNECT_FAILED";
- //else if (mqttclient.state() == -1) json["mqttstate"] = "DISCONNECTED";
- //else if (mqttclient.state() == 0) json["mqttstate"] = "CONNECTED";
- //else if (mqttclient.state() == 1) json["mqttstate"] = "CONNECT_BAD_PROTOCOL";
- //else if (mqttclient.state() == 2) json["mqttstate"] = "CONNECT_BAD_CLIENT_ID";
- //else if (mqttclient.state() == 3) json["mqttstate"] = "CONNECT_UNAVAILABLE";
- //else if (mqttclient.state() == 4) json["mqttstate"] = "CONNECT_BAD_CREDENTIALS";
- //else if (mqttclient.state() == 5) json["mqttstate"] = "CONNECT_UNAUTHORIZED";
- //if (mqttclient.state() == -4) json["mqttstate"] = PGMStr_MQTTStateM4;
- //else if (mqttclient.state() == -3) json["mqttstate"] = PGMStr_MQTTStateM3;
- //else if (mqttclient.state() == -2) json["mqttstate"] = PGMStr_MQTTStateM2;
- //else if (mqttclient.state() == -1) json["mqttstate"] = PGMStr_MQTTStateM1;
- //else if (mqttclient.state() == 0) json["mqttstate"] = PGMStr_MQTTState0;
- //else if (mqttclient.state() == 1) json["mqttstate"] = PGMStr_MQTTState1;
- //else if (mqttclient.state() == 2) json["mqttstate"] = PGMStr_MQTTState2;
- //else if (mqttclient.state() == 3) json["mqttstate"] = PGMStr_MQTTState3;
- //else if (mqttclient.state() == 4) json["mqttstate"] = PGMStr_MQTTState4;
- //else if (mqttclient.state() == 5) json["mqttstate"] = PGMStr_MQTTState5;
- json["mqtthost"] = confMqtt.mqtt_server;
- if (mqttReconnects < 1) json["mqttreconn"] = mqttReconnects;
- else json["mqttreconn"] = mqttReconnects - 1;
- json["setTemp"] = setTemp;
- json["currSetTemp"] = currSetTemp;
- json["temp"] = round1(currTemp);
- json["hum"] = int(currHum);
- json["heating"] = turnHeatingOn;
- json["mode"] = heatingMode;
- json["modeName"] = currentModeName;
- json["pset"] = preset;
- json["psetName"] = currentPresetName;
- json["psetName0"] = confAdv.psetName0;
- json["psetName1"] = confAdv.psetName1;
- json["psetName2"] = confAdv.psetName2;
- json["tempLow"] = setTempLow;
- json["tempLow2"] = setTempLow2;
- json["outTemp"] = round1(outTemp);
- json["outHum"] = outHum;
- char jsonchar[500];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /api
- //httpServer.on("/setTemp", []() {
- // if ( httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()) ) {
- // //Serial.println("web triggered setTemp");
- // sendLog(F("WEB: /setTemp"), LOGLEVEL_INFO);
- // if (httpServer.hasArg("value")) {
- // char bufVal[20];
- // httpServer.arg("value").toCharArray(bufVal, 20);
- // float valueFloat = round(atof(bufVal) * 2.0) / 2.0;
- // setTempTo(valueFloat);
- // httpSend200OK();
- // }
- // } //if
- // else httpSendUnauthorized();
- //});
- //httpServer.on("/setMode", []() {
- // if ( httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()) ) {
- // //Serial.println("web triggered setMode");
- // sendLog(F("WEB: /setMode"), LOGLEVEL_INFO);
- // if (httpServer.hasArg("value")) {
- // char bufVal[20];
- // httpServer.arg("value").toCharArray(bufVal, 20);
- // int valueInt = atoi(bufVal);
- // if (valueInt >= 0 && valueInt <= 1) setHeatingmodeTo(valueInt);
- // httpSend200OK();
- // }
- // } //if
- // else httpSendUnauthorized();
- //});
- //httpServer.on("/setPreset", []() {
- // if ( httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()) ) {
- // //Serial.println("web triggered setPreset");
- // sendLog(F("WEB: /setPreset"), LOGLEVEL_INFO);
- // if (httpServer.hasArg("value")) {
- // char bufVal[20];
- // httpServer.arg("value").toCharArray(bufVal, 20);
- // int valueInt = atoi(bufVal);
- // if (valueInt >= 0 && valueInt <= 2) setPresetTo(valueInt);
- // httpSend200OK();
- // }
- // } //if
- // else httpSendUnauthorized();
- //});
- httpServer.on("/confDataWeb", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //Serial.println("httpServer.on /confdata");
- //sendLog("WEB: /confDataWeb", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataWeb (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- StaticJsonDocument<1000> json;
- json["apiToken"] = confWeb.http_token;
- json["httpUA"] = confWeb.http_user;
- //json["httpPA"] = confWeb.http_pass;
- if(strlen(confWeb.http_pass) > 0) json["httpPA"] = "****";
- else json["httpPA"] = "";
- if (confWeb.http_user_auth) json["httpAuth"] = 1;
- else json["httpAuth"] = 0;
- json["httpU1"] = confWeb.http_user1;
- //json["httpP1"] = confWeb.http_pass1;
- if(strlen(confWeb.http_pass1) > 0) json["httpP1"] = "****";
- else json["httpP1"] = "";
- json["httpU2"] = confWeb.http_user2;
- //json["httpP2"] = confWeb.http_pass2;
- if(strlen(confWeb.http_pass2) > 0) json["httpP2"] = "****";
- else json["httpP2"] = "";
- if (confWeb.enableConsole) json["enableConsole"] = 1;
- else json["enableConsole"] = 0;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confdweb
- httpServer.on("/confDataMqtt", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /confDataMqtt", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataMqtt (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- StaticJsonDocument<1000> json;
- if (confMqtt.mqtt_enable) json["mqttEnable"] = 1;
- else json["mqttEnable"] = 0;
- json["mqttHost"] = confMqtt.mqtt_server;
- json["mqttPort"] = confMqtt.mqtt_port;
- json["mqttUser"] = confMqtt.mqtt_user;
-
- //json["mqttPass"] = confMqtt.mqtt_pass;
- if(strlen(confMqtt.mqtt_pass) > 0) json["mqttPass"] = "****";
- else json["mqttPass"] = "";
- json["inTop"] = confMqtt.mqtt_topic_in;
- json["outTop"] = confMqtt.mqtt_topic_out;
- if (confMqtt.mqtt_outRetain) json["outRet"] = 1;
- else json["outRet"] = 0;
- if (confMqtt.mqtt_outRetain_sensors) json["outRetSens"] = 1;
- else json["outRetSens"] = 0;
- json["outPubInt"] = confMqtt.mqtt_outPubInterval;
- json["outPubIntSens"] = confMqtt.mqtt_outPubInterval_sensors;
- json["willTop"] = confMqtt.mqtt_willTopic;
- json["willQos"] = confMqtt.mqtt_willQos;
- if (confMqtt.mqtt_willRetain) json["willRet"] = 1;
- else json["willRet"] = 0;
- json["willMsg"] = confMqtt.mqtt_willMsg;
- json["connMsg"] = confMqtt.mqtt_connMsg;
- if (confMqtt.mqtt_enable_heartbeat) json["hbEnable"] = 1;
- else json["hbEnable"] = 0;
- json["hbReconn"] = confMqtt.mqtt_heartbeat_maxage_reconnect / 60000;
- json["hbReboot"] = confMqtt.mqtt_heartbeat_maxage_reboot / 60000;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confdmqtt
- httpServer.on("/setConfWeb", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfWeb", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfWeb (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- bool httpPASet, httpP1Set, httpP2Set;
- httpPASet = false;
- httpP1Set = false;
- httpP2Set = false;
- if (httpServer.hasArg("httpPASet")) httpPASet = true;
- if (httpServer.hasArg("httpP1Set")) httpP1Set = true;
- if (httpServer.hasArg("httpP2Set")) httpP2Set = true;
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- if (strcmp(bufName, "httpUA") == 0 || strcmp(bufName, "httpPA") == 0) {
- if (httpPASet) setConfig(bufName, bufValue);
- }
- else if (strcmp(bufName, "httpU1") == 0 || strcmp(bufName, "httpP1") == 0) {
- if (httpP1Set) setConfig(bufName, bufValue);
- }
- else if (strcmp(bufName, "httpU2") == 0 || strcmp(bufName, "httpP2") == 0) {
- if (httpP2Set) setConfig(bufName, bufValue);
- }
- else if (strcmp(bufName, "httpPASet") != 0 && strcmp(bufName, "httpP1Set") != 0 && strcmp(bufName, "httpP2Set") != 0) setConfig(bufName, bufValue);
- //else setConfig(bufName, bufValue);
- }
- //saveConfigWebToFlash = true; // will be saved in next loop()
- //Serial.println("web triggered saveConfigWebToFlash");
- }
- yield();
- saveConfigWeb();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfWeb
- httpServer.on("/setConfMqtt", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //Serial.println("httpServer.on /setConfMqtt");
- //sendLog("WEB: /setConfMqtt", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfMqtt (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- bool mqttPassSet;
- mqttPassSet = false;
- if (httpServer.hasArg("mqttPassSet")) mqttPassSet = true;
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- if (strcmp(bufName, "mqttUser") == 0 || strcmp(bufName, "mqttPass") == 0) {
- if (mqttPassSet) setConfig(bufName, bufValue);
- }
- else setConfig(bufName, bufValue);
- }
- //saveConfigMqttToFlash = true; // will be saved in next loop()
- //Serial.println("web triggered saveConfigMqttToFlash");
- }
- yield();
- saveConfigMqtt();
- httpServerHandleConfSavedRestartPage();
- config_was_changed = true;
- restart();
- }
- }); //httpServer.on /setConfMqtt
- httpServer.on("/confDataDevWiFi", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataDevWiFi", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataDevWiFi (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfigToFlash = true; // will be saved in next loop()
- //Serial.println("web triggered saveConfigToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<800> json;
- json["devName"] = confDevWiFi.deviceName;
- json["hostName"] = confDevWiFi.hostName;
- json["SSID1"] = confDevWiFi.WiFiSSID1;
- //json["WPW1"] = confDevWiFi.WiFiPW1;
- if(strlen(confDevWiFi.WiFiPW1) > 0) json["WPW1"] = "****";
- else json["WPW1"] = "";
- json["SSID2"] = confDevWiFi.WiFiSSID2;
- //json["WPW2"] = confDevWiFi.WiFiPW2;
- if(strlen(confDevWiFi.WiFiPW2) > 0) json["WPW2"] = "****";
- else json["WPW2"] = "";
- json["SSIDAP"] = confDevWiFi.WiFiAPModeSSID;
- json["WPWAP"] = confDevWiFi.WiFiAPModePassword;
- json["WAPtout"] = confDevWiFi.WiFiAPModeTimeout;
- json["WConnCheck"] = confDevWiFi.WiFiConnCheckInterval;
- json["Wretry"] = confDevWiFi.WiFiRetryInterval;
- json["Wreboot"] = confDevWiFi.WiFiRebootOnNoConnect;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /getConf/DevWiFi
- httpServer.on("/setConfDevWiFi", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfDevWiFi", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfDevWiFi (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
-
- bool WPW1Set, WPW2Set, WPWAPSet;
- WPW1Set = false;
- WPW2Set = false;
- WPWAPSet = false;
- if (httpServer.hasArg("WPW1Set")) WPW1Set = true;
- if (httpServer.hasArg("WPW2Set")) WPW2Set = true;
- if (httpServer.hasArg("WPWAPSet")) WPWAPSet = true;
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- if (strcmp(bufName, "SSID1") == 0 || strcmp(bufName, "WPW1") == 0) {
- if (WPW1Set) setConfig(bufName, bufValue);
- }
- else if (strcmp(bufName, "SSID2") == 0 || strcmp(bufName, "WPW2") == 0) {
- if (WPW2Set) setConfig(bufName, bufValue);
- }
- else if (strcmp(bufName, "WPWAP") == 0) {
- if (WPWAPSet) setConfig(bufName, bufValue);
- }
- else setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigDevWiFi();
- httpServerHandleConfSavedRestartPage();
-
- config_was_changed = true;
- restart();
- }
- }); //httpServer.on /setConfDev
- httpServer.on("/setConfBas", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfBas", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfBas (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigBas();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // delay(10);
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfBas
- httpServer.on("/setConfAdv", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfAdv", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfAdv (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigAdv();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // delay(10);
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfAdv
- httpServer.on("/setConfAdd", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfAdd", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfAdd (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigAdd();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // delay(10);
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfAdd
- httpServer.on("/setConfTime", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfTime", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfTime (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigTime();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // delay(10);
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfTime
- httpServer.on("/setConfLog", []() {
- if (!httpIsAuthenticatedAdmin()) httpSendUnauthorized();
- else {
- //sendLog("WEB: /setConfLog", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /setConfLog (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- Serial.print("web update ");
- Serial.print(bufName);
- Serial.print(" = ");
- Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- }
- yield();
- saveConfigLog();
- httpServerHandleConfSavedPage();
- config_was_changed = true;
- // delay(10);
- // yield();
- // ESP.restart();
- }
- }); //httpServer.on /setConfLog
- httpServer.on("/confDataBas", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataBas", LOGLEVEL_INFO);
- //Serial.println("httpServer.on /confdata2");
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataBas (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfig2ToFlash = true;
- //Serial.println("web triggered saveConfig2ToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<500> json;
- if (confBas.autoSaveSetTemp) json["autoSaveTemp"] = 1;
- else json["autoSaveTemp"] = 0;
- if (confBas.autoSaveHeatingMode) json["autoSaveMode"] = 1;
- else json["autoSaveMode"] = 0;
- if (confBas.saveToMqttRetained) json["saveToMqttRet"] = 1;
- else json["saveToMqttRet"] = 0;
- json["tempMin"] = confBas.setTempMin;
- json["tempMax"] = confBas.setTempMax;
- json["measInt"] = confBas.measureInterval;
- json["dispInt"] = confBas.displayInterval;
- json["dispTout"] = confBas.displayTimeout;
- if (confBas.PIR_enablesDisplay) json["PIRenDisp"] = 1;
- else json["PIRenDisp"] = 0;
- if (confBas.PIR_enablesDisplay_preset0only) json["PIRenDispPs0"] = 1;
- else json["PIRenDispPs0"] = 0;
- if (confBas.togglingTempHumAIDisplay) json["togTHdisp"] = 1;
- else json["togTHdisp"] = 0;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confdbas
- httpServer.on("/confDataAdv", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataAdv", LOGLEVEL_INFO);
- //Serial.println("httpServer.on /confdata2");
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataAdv (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfig2ToFlash = true;
- //Serial.println("web triggered saveConfig2ToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<600> json;
- json["minOffTime"] = confAdv.heatingMinOffTime;
- json["tempDec"] = confAdv.setTempDecreaseVal;
- json["hyst"] = confAdv.hysteresis;
- json["tempCorr"] = confAdv.tempCorrVal;
- json["humCorr"] = confAdv.humCorrVal;
- json["offMsg"] = confAdv.offMessage;
- json["modeName0"] = confAdv.modeName0;
- json["modeName1"] = confAdv.modeName1;
- json["psetName0"] = confAdv.psetName0;
- json["psetName1"] = confAdv.psetName1;
- json["psetName2"] = confAdv.psetName2;
- json["iTempLab"] = confAdv.iTempLabel;
- json["oTempLab"] = confAdv.oTempLabel;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confdadv
- httpServer.on("/confDataAdd", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataAdd", LOGLEVEL_INFO);
- //Serial.println("httpServer.on /confdata2");
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataAdd (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfig2ToFlash = true;
- //Serial.println("web triggered saveConfig2ToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<1000> json;
- json["outTempTop"] = confAdd.outTemp_topic_in;
- json["outHumTop"] = confAdd.outHum_topic_in;
- json["PIRTop"] = confAdd.mqtt_topic_pir;
- json["PIROnPld"] = confAdd.mqtt_payload_pir_on;
- json["PIROffPld"] = confAdd.mqtt_payload_pir_off;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confdadd
- httpServer.on("/confDataTime", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataTime", LOGLEVEL_INFO);
- //Serial.println("httpServer.on /confdata2");
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataTime (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfig2ToFlash = true;
- //Serial.println("web triggered saveConfig2ToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<1000> json;
- if(confTime.ntpEnable) json["NTPEnable"] = 1;
- else json["NTPEnable"] = 0;
- json["NTPServer1"] = confTime.ntpServer1;
- json["NTPServer2"] = confTime.ntpServer2;
- json["TZStr"] = confTime.timeZoneStr;
- json["NTPSyncInt"] = confTime.ntpSyncInterval;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confDataTime
- httpServer.on("/confDataLog", []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confDataLog", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confDataLog (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- for (int i = 0; i < httpServer.args(); i++) {
- char bufName[20];
- char bufValue[101];
- httpServer.argName(i).toCharArray(bufName, 20);
- httpServer.arg(i).toCharArray(bufValue, 101);
- if (strlen(bufName) > 0) {
- //Serial.print("web update ");
- //Serial.print(bufName);
- //Serial.print(" = ");
- //Serial.println(bufValue);
- setConfig(bufName, bufValue);
- }
- saveConfig2ToFlash = true;
- //Serial.println("web triggered saveConfig2ToFlash");
- }
- yield();
- //build json object of program data
- StaticJsonDocument<1000> json;
- //if(confTime.ntpEnable) json["NTPEnable"] = 1;
- //else json["NTPEnable"] = 0;
- json["logLevSer"] = confLog.logLevelSerial;
- json["logLevWeb"] = confLog.logLevelWeb;
- json["logLevMqtt"] = confLog.logLevelMqtt;
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /confDataLog
- //get heap status, analog input value and all GPIO statuses in one json call
- httpServer.on("/sysinfo", HTTP_GET, []() {
- if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /sysinfo (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- StaticJsonDocument<600> json;
- json["Devname"] = confDevWiFi.deviceName;
- json["Ssid"] = WiFi.SSID();
- json["WiFiNum"] = persWM.getActiveWiFiNum();
- json["Uptime"] = uptimeStr;
- json["HeapFree"] = ESP.getFreeHeap();
- json["HeapFragment"] = ESP.getHeapFragmentation();
- json["HeapMaxBlock"] = ESP.getMaxFreeBlockSize();
- json["ResetReason"] = ESP.getResetReason();
- json["CoreVersion"] = ESP.getCoreVersion();
- json["SDKVersion"] = ESP.getSdkVersion();
- json["CPUfreq"] = ESP.getCpuFreqMHz();
- json["SketchSize"] = ESP.getSketchSize();
- json["FlashSize"] = ESP.getFlashChipRealSize();
- if(confTime.ntpEnable) {
- char buf[13];
- updateTime();
- strftime(buf, sizeof(buf), "%H:%M", <);
- json["time"] = buf;
- strftime(buf, sizeof(buf), "%d.%m.%Y", <);
- json["date"] = buf;
- }
-
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /sysinfo
- /*httpServer.on("/", []() {
- if ( WifiInApMode ) {
- httpServer.sendHeader("Location", "/wifi.htm", true);
- httpServer.send(302);
- }
- else {
- httpServer.sendHeader("Location", "/main", true);
- httpServer.send(302);
- }
- });*/
- httpServer.on("/", []() {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: / (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- if (httpServer.hasArg("restart")) {
- if (httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()) ) {
- sendLog("WEB: /?restart", LOGLEVEL_INFO);
- httpServerHandleRestartPage();
- restart();
- }
- else httpSendUnauthorized();
- }
- else if (httpServer.hasArg("mqttreconnect")) {
- if ( httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()) ) {
- //Serial.println("web triggered mqttreconnect");
- sendLog("WEB: /?mqttreconnect", LOGLEVEL_INFO);
- mqttReconnect();
- httpServer.sendHeader("Location", "/", true);
- httpServer.send(303);
- }
- else httpSendUnauthorized();
- }
- else if (httpServer.hasArg("clearconf")) {
- if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()) ) {
- sendLog("WEB: /?clearconf", LOGLEVEL_INFO);
- httpServerHandleClearconfPage();
- yield();
- delay(5);
- deleteConfig();
- }
- else httpSendUnauthorized();
- }
- else if (!httpIsAuthenticated()) return httpServer.requestAuthentication();
- else {
- sendLog("WEB: /", LOGLEVEL_INFO);
- httpServerHandleMainPage();
- }
- });
- httpServer.on("/conf", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /conf", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /conf (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfPage();
- }
- });
- httpServer.on("/confweb", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confweb", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confweb (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfWebPage();
- }
- });
- httpServer.on("/confmqtt", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confmqtt", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confmqtt (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfMqttPage();
- }
- });
- httpServer.on("/confdevwifi", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confdevwifi", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confdevwifi (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfDevWiFiPage();
- }
- });
- httpServer.on("/confbas", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confbas", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confbas (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfBasPage();
- }
- });
- httpServer.on("/confadv", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confadv", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confadv (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfAdvPage();
- }
- });
- httpServer.on("/confadd", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /confadd", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /confadd (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfAddPage();
- }
- });
- httpServer.on("/conftime", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /conftime", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /conftime (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfTimePage();
- }
- });
- httpServer.on("/conflog", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /conflog", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /conflog (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleConfLogPage();
- }
- });
- httpServer.on("/redTemps", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /redTemps", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /redTemps (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleRedTempsPage();
- }
- });
- if(confWeb.enableConsole) {
- httpServer.on("/console", []() {
- if (!httpIsAuthenticatedAdmin()) return httpServer.requestAuthentication();
- else {
- //sendLog("WEB: /console", LOGLEVEL_INFO);
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /console (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- wsValidSessionId = millis();
- char sidbuf[20];
- sprintf(sidbuf, "sessionId=%lu|", wsValidSessionId);
- httpServer.sendHeader("Set-Cookie",sidbuf);
- httpServerHandleConsolePage();
- }
- });
- }
- httpServer.onNotFound([]() {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: 404 (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- httpServerHandleNotFound();
- }); //httpServer.onNotFound
- // HTTP Updater at /update
- httpUpdater.setup(&httpServer, "/update", confWeb.http_user, confWeb.http_pass);
- httpServer.begin();
- }
|