12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904 |
- #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_sysinfo.h"
- #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
- #include "html_console_ws.h"
- #endif
- #ifdef ENABLE_FEATURE_WEB_CONSOLE
- #include "html_console.h"
- #endif
- 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);
- #ifdef ENABLE_FEATURE_WEB_CONSOLE
- if (confWeb.wConsole)
- httpServer.sendContent_P(html_main_body_adminonly_console);
- #endif
- #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
- if (confWeb.wsConsole)
- httpServer.sendContent_P(html_main_body_adminonly_wsconsole);
- #endif
- }
- 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);
- #ifdef ENABLE_FEATURE_WEB_CONSOLE
- if (confWeb.wConsole)
- httpServer.sendContent_P(html_conf_body_console);
- #endif
- #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
- if (confWeb.wsConsole)
- httpServer.sendContent_P(html_conf_body_wsconsole);
- #endif
- 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();
- }
- #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
- void httpServerHandleWSConsolePage()
- {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_wsconsole_body);
- httpServerSendHtmlFooterChunked();
- }
- #endif
- 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);
- configChangedRestartRequired = false;
- 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 httpServerHandleSysInfoPage()
- {
- httpServerSendHtmlHeadChunked();
- httpServer.sendContent_P(html_sysinfo_script);
- httpServer.sendContent_P(html_head_end);
- httpServer.sendContent_P(html_bodytag_jsinit);
- httpServerSendHtmlBodyPageheadChunked();
- httpServer.sendContent_P(html_sysinfo_body);
- httpServerSendHtmlFooterChunked();
- }
- void httpServerSendHtmlHeadChunked()
- {
- httpServer.setContentLength(CONTENT_LENGTH_UNKNOWN); //Enable Chunked Transfer
- httpServer.send(200, "text/html", html_head_part1);
- httpServer.sendContent_P(PGMStr_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_P(PGMStr_FIRMWARE_NAME);
- httpServer.sendContent(" - ");
- httpServer.sendContent(confDevWiFi.deviceName);
- httpServer.sendContent_P(html_body_pagehead_part2);
- if (configChangedRestartRequired)
- httpServer.sendContent_P(html_body_pagehead_confchangednote);
- }
- void httpServerSendHtmlFooterChunked()
- {
- httpServer.sendContent_P(html_footer1);
- httpServer.sendContent_P(html_footer_a1);
- httpServer.sendContent_P(PGMStr_FIRMWARE_URL);
- httpServer.sendContent_P(html_footer_a2);
- httpServer.sendContent_P(PGMStr_FIRMWARE_NAME);
- httpServer.sendContent_P(html_footer_ae);
- httpServer.sendContent(" ");
- httpServer.sendContent_P(PGMStr_FIRMWARE_VERSION);
- #ifdef DEBUGMODE
- httpServer.sendContent(" <span style='color:red;font-weight:bold;'>DEBUG</span>");
- #endif
- httpServer.sendContent(" by ");
- httpServer.sendContent_P(html_footer_a1);
- httpServer.sendContent_P(PGMStr_FIRMWARE_COPYRIGHT_URL);
- httpServer.sendContent_P(html_footer_a2);
- httpServer.sendContent_P(PGMStr_FIRMWARE_COPYRIGHT);
- httpServer.sendContent_P(html_footer_ae);
- httpServer.sendContent_P(html_footer2);
- httpServer.sendContent("");
- httpServer.client().stop();
- }
- boolean httpIsAuthenticated()
- {
- if (WifiInApMode && strlen(confDevWiFi.WiFiAPModePassword) >= 8)
- return true;
- if (confWeb.http_user_auth)
- {
- boolean useAuth = false;
- boolean isAuthenticated = false;
- // user authentication enabled - only allow access without authentication if no admin password is set
- // or if user1 credentials are empty (access in "user mode")
- if (strlen(confWeb.http_pass) > 0 || strlen(confWeb.http_pass1) > 0 || strlen(confWeb.http_pass2) > 0)
- useAuth = true;
- if (strlen(confWeb.http_pass) == 0)
- {
- return true; // no admin password set - in this case authentication is off
- }
- 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 password is empty and user-authentication is enabled
- if (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 password is set
- else
- {
- if (strlen(confWeb.http_pass) > 0)
- {
- if (httpServer.authenticate(confWeb.http_user, confWeb.http_pass))
- return true;
- else
- return false;
- }
- else
- return true;
- }
- }
- boolean httpIsAuthenticatedAdmin()
- {
- if (WifiInApMode && strlen(confDevWiFi.WiFiAPModePassword) >= 8)
- return true;
- 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("/api", []() {
- if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- if (confLog.logWebRequests || httpServer.args() > 0)
- {
- 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: BtnPlus"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnMinus"))
- {
- setTempStepDown();
- sendLog(F("WEB: BtnMinus"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset0"))
- {
- setPresetTo(0);
- sendLog(F("WEB: BtnPset0"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset1"))
- {
- setPresetTo(1);
- sendLog(F("WEB: BtnPset1"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnPset2"))
- {
- setPresetTo(2);
- sendLog(F("WEB: BtnPset2"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnOn"))
- {
- setHeatingmodeTo(1);
- sendLog(F("WEB: BtnOn"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnOff"))
- {
- setHeatingmodeTo(0);
- sendLog(F("WEB: BtnOff"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL1Plus"))
- {
- setTempLowStepUp();
- sendLog(F("WEB: BtnL1Plus"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL1Minus"))
- {
- setTempLowStepDown();
- sendLog(F("WEB: BtnL1Minus"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL2Plus"))
- {
- setTempLow2StepUp();
- sendLog(F("WEB: BtnL2Plus"), LOGLEVEL_INFO);
- } //if
- if (httpServer.hasArg("BtnL2Minus"))
- {
- setTempLow2StepDown();
- sendLog(F("WEB: BtnL2Minus"), 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"] = getUptimeStr();
- #ifdef ENABLE_FEATURE_NTP_TIME
- if (confTime.ntpEnable)
- {
- char buf[13];
- updateTime();
- if (lt.tm_year > 70)
- {
- strftime(buf, sizeof(buf), "%H:%M", <);
- json["time"] = buf;
- strftime(buf, sizeof(buf), "%d.%m.%Y", <);
- json["date"] = buf;
- }
- }
- #endif
- json["freeheap"] = ESP.getFreeHeap();
- mqtt_updateCurrentStateName();
- json["mqttstate"] = mqttCurrentStateName;
- 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("/confDataWeb", []() {
- if (!httpIsAuthenticatedAdmin())
- httpSendUnauthorized();
- else
- {
- //Serial.println("httpServer.on /confdata");
- //sendLog("WEB: /confDataWeb", LOGLEVEL_INFO);
- if (confLog.logWebRequests)
- {
- 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.wConsole)
- json["wConsole"] = 1;
- else
- json["wConsole"] = 0;
-
- if (confWeb.wsConsole)
- json["wsConsole"] = 1;
- else
- json["wsConsole"] = 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);
- if (confLog.logWebRequests)
- {
- 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);
- }
- }
- yield();
- saveConfigWeb();
- yield();
- loadConfigWeb();
- httpServerHandleConfSavedPage();
- // 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();
- yield();
- loadConfigMqtt();
- //httpServerHandleConfSavedRestartPage();
- httpServerHandleConfSavedPage();
- //restart();
- }
- }); //httpServer.on /setConfMqtt
- httpServer.on("/confDataDevWiFi", []() {
- if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- //sendLog("WEB: /confDataDevWiFi", LOGLEVEL_INFO);
- if (confLog.logWebRequests)
- {
- 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 /confDataDevWiFi
- 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();
- yield();
- loadConfigDevWiFi();
- //httpServerHandleConfSavedRestartPage();
- httpServerHandleConfSavedPage();
- //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();
- yield();
- loadConfigBas();
- httpServerHandleConfSavedPage();
- }
- }); //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();
- yield();
- loadConfigAdv();
- httpServerHandleConfSavedPage();
- }
- }); //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();
- yield();
- loadConfigAdd();
- httpServerHandleConfSavedPage();
- }
- }); //httpServer.on /setConfAdd
- #ifdef ENABLE_FEATURE_NTP_TIME
- 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();
- yield();
- loadConfigTime();
- httpServerHandleConfSavedPage();
- }
- }); //httpServer.on /setConfTime
- #endif
- 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();
- yield();
- loadConfigLog();
- httpServerHandleConfSavedPage();
- }
- }); //httpServer.on /setConfLog
- httpServer.on("/confDataBas", []() {
- if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- //sendLog("WEB: /confDataBas", LOGLEVEL_INFO);
- //Serial.println("httpServer.on /confdata2");
- if (confLog.logWebRequests)
- {
- 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");
- if (confLog.logWebRequests)
- {
- 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");
- if (confLog.logWebRequests)
- {
- 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");
- if (confLog.logWebRequests)
- {
- 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 / 60;
- 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);
- if (confLog.logWebRequests)
- {
- 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;
- if (confLog.logWebRequests)
- json["logWebRequests"] = 1;
- else
- json["logWebRequests"] = 0;
- 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("/sysinfod", HTTP_GET, []() {
- if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /sysinfod (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- char buf[40];
- byte mac[6];
- WiFi.macAddress(mac);
- StaticJsonDocument<1000> json;
- json["DevName"] = confDevWiFi.deviceName;
- json["HostName"] = confDevWiFi.hostName;
- sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (uint8_t)mac[0], (uint8_t)mac[1], (uint8_t)mac[2], (uint8_t)mac[3], (uint8_t)mac[4], (uint8_t)mac[5]);
- json["MAC"] = buf;
- //sprintf(buf, "%s", WiFi.localIP().toString().c_str());
- //json["IP"] = buf;
-
- //sprintf(buf, "%s", WiFi.gatewayIP().toString().c_str());
- //json["Gateway"] = buf;
- json["IP"] = WiFi.localIP().toString();
- json["GW"] = WiFi.gatewayIP().toString();
- json["DNS"] = WiFi.dnsIP().toString();
- json["SSID"] = WiFi.SSID();
- json["WiFiConf"] = persWM.getActiveWiFiNum();
- json["UpTime"] = getUptimeStr();
- 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();
- sprintf(buf, "%s", PGMStr_FIRMWARE_NAME);
- json["FWName"] = buf;
- sprintf(buf, "%s", PGMStr_FIRMWARE_VERSION);
- json["FWVer"] = buf;
- sprintf(buf, "%s", PGMStr_FIRMWARE_COPYRIGHT);
- json["FWCr"] = buf;
- sprintf(buf, "%s", compile_date);
- json["FWBuilt"] = buf;
- #ifdef DEBUGMODE
- json["FWDebug"] = "yes";
- #else
- json["FWDebug"] = "no";
- #endif
- #ifdef ENABLE_FEATURE_NTP_TIME
- if (confTime.ntpEnable)
- {
- char buf[13];
- updateTime();
- if(lt.tm_year > 70) {
- strftime(buf, sizeof(buf), "%H:%M", <);
- json["Time"] = buf;
- strftime(buf, sizeof(buf), "%d.%m.%Y", <);
- json["Date"] = buf;
- }
- }
- #endif
- yield();
- char jsonchar[1000];
- serializeJson(json, jsonchar);
- httpServer.send(200, "application/json", jsonchar);
- }
- }); //httpServer.on /sysinfod
- httpServer.on("/sysinfo", HTTP_GET, []() {
- if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /sysinfo (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- httpServerHandleSysInfoPage();
- }
- });
- /*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();
- if (confLog.logWebRequests || httpServer.args() > 0)
- {
- 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 (httpServer.hasArg("clearwifi"))
- {
- if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()))
- {
- sendLog("WEB: /?clearwifi", LOGLEVEL_INFO);
- httpServerHandleClearconfPage();
- yield();
- delay(5);
- confClearWiFiCredentials();
- }
- else
- httpSendUnauthorized();
- }
- else if (httpServer.hasArg("clearcreds"))
- {
- if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()))
- {
- sendLog("WEB: /?clearcreds", LOGLEVEL_INFO);
- httpServerHandleClearconfPage();
- yield();
- delay(5);
- confClearCredentials();
- }
- else
- httpSendUnauthorized();
- }
- else if (!httpIsAuthenticated())
- return httpServer.requestAuthentication();
- else
- {
- if (confLog.logWebRequests)
- sendLog("WEB: /", LOGLEVEL_INFO);
- httpServerHandleMainPage();
- }
- });
- httpServer.on("/conf", []() {
- if (!httpIsAuthenticatedAdmin())
- return httpServer.requestAuthentication();
- else
- {
- //sendLog("WEB: /conf", LOGLEVEL_INFO);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- 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);
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /redTemps (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- httpServerHandleRedTempsPage();
- }
- });
- #ifdef ENABLE_FEATURE_WEB_CONSOLE_WEBSOCKETS
- if (confWeb.wsConsole)
- {
- httpServer.on("/wsconsole", []() {
- if (!httpIsAuthenticatedAdmin())
- return httpServer.requestAuthentication();
- else
- {
- //sendLog("WEB: /wsconsole", LOGLEVEL_INFO);
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /wsconsole (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- wsValidSessionId = millis();
- char sidbuf[20];
- sprintf(sidbuf, "sessionId=%lu|", wsValidSessionId);
- httpServer.sendHeader("Set-Cookie", sidbuf);
- httpServerHandleWSConsolePage();
- }
- });
- httpServer.on("/wsapp.js", []() {
- httpServer.sendHeader("cache-control", "max-age=86400", false);
- httpServer.send_P(200, "text/javascript", js_wsapp);
- });
- }
- #endif
- httpServer.onNotFound([]() {
- String addr = httpServer.client().remoteIP().toString();
- if (confLog.logWebRequests)
- {
- char buf[40];
- sprintf(buf, "WEB: 404 (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- httpServerHandleNotFound();
- }); //httpServer.onNotFound
- #ifdef ENABLE_FEATURE_WEB_CONSOLE
- if (confWeb.wConsole)
- {
- httpServer.on("/console", []() {
- if (!httpIsAuthenticatedAdmin())
- return httpServer.requestAuthentication();
- else
- {
- //sendLog("WEB: /console", LOGLEVEL_INFO);
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /console (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- httpServerHandleConsolePage();
- }
- });
- httpServer.on("/webcsapi", []() {
- if (!httpIsAuthenticatedAdmin())
- return httpServer.requestAuthentication();
- else
- {
- if (httpServer.hasArg("cmd"))
- {
- char buf[101];
- httpServer.arg("cmd").toCharArray(buf, 100);
- strlcpy(cmdPayload, buf, sizeof(cmdPayload));
- cmdInQueue = true;
- evalCmd();
- }
- if (confLog.logWebRequests)
- {
- String addr = httpServer.client().remoteIP().toString();
- char buf[40];
- sprintf(buf, "WEB: /conflog (from %s)", addr.c_str());
- sendLog(buf, LOGLEVEL_INFO);
- }
- httpServer.send(200, "text/plain", webLogBuffer);
- }
- });
- httpServer.on("/csapp.js", []() {
- httpServer.sendHeader("cache-control", "max-age=86400", false);
- httpServer.send_P(200, "text/javascript", js_csapp);
- });
- }
- #endif
- // HTTP Updater at /update
- #ifdef ENABLE_FEATURE_HTTP_UPDATER
- httpUpdater.setup(&httpServer, "/update", confWeb.http_user, confWeb.http_pass);
- #endif
- httpServer.begin();
- }
|