webserver.ino 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  1. #ifdef LANG_DE
  2. #include "html_DE.h"
  3. #include "html_main_DE.h"
  4. #else
  5. #include "html.h"
  6. #include "html_main.h"
  7. #endif
  8. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  9. //#ifdef LANG_DE
  10. // #include "html_main_thermostat_DE.h"
  11. // #include "html_thermostat_redTemps_DE.h"
  12. // #include "html_confTherm_DE.h"
  13. //#else
  14. #include "html_main_thermostat.h"
  15. #include "html_thermostat_redTemps.h"
  16. #include "html_confTherm.h"
  17. //#endif
  18. #elif FIRMWARE_VARIANT_HEATCONTROL
  19. #ifdef LANG_DE
  20. #include "html_main_heatcontrol_DE.h"
  21. #include "html_confHeatcontrol_DE.h"
  22. #else
  23. #include "html_main_heatcontrol.h"
  24. #include "html_confHeatcontrol.h"
  25. #endif
  26. #else
  27. //#ifdef LANG_DE
  28. // #include "html_main_minimal_DE.h"
  29. //#else
  30. #include "html_main_minimal.h"
  31. //#endif
  32. #endif
  33. #include "html_js_confpages.h"
  34. #ifdef LANG_DE
  35. #include "html_conf_DE.h"
  36. #include "html_confAdd_DE.h"
  37. #include "html_confDevWiFi_DE.h"
  38. #include "html_confMqtt.h"
  39. #include "html_confWeb.h"
  40. #include "html_confTime.h"
  41. #include "html_confLog.h"
  42. #include "html_sysinfo_DE.h"
  43. #else
  44. #include "html_conf.h"
  45. #include "html_confAdd.h"
  46. #include "html_confDevWiFi.h"
  47. #include "html_confMqtt.h"
  48. #include "html_confWeb.h"
  49. #include "html_confTime.h"
  50. #include "html_confLog.h"
  51. #include "html_sysinfo.h"
  52. #endif
  53. #ifdef ENABLE_FEATURE_FILESYSTEM_BROWSER
  54. //#ifdef LANG_DE
  55. // #include "html_fsbrowser_DE.h"
  56. //#else
  57. #include "html_fsbrowser.h"
  58. //#endif
  59. #endif
  60. #ifdef ENABLE_FEATURE_WEB_CONSOLE
  61. //#ifdef LANG_DE
  62. // #include "html_console_DE.h"
  63. //#else
  64. #include "html_console.h"
  65. //#endif
  66. #endif
  67. #if defined(ENABLE_FEATURE_WSCONSOLE) || defined(ENABLE_FEATURE_WSCONSOLE_UART)
  68. #include "html_console_wsapp.js.h"
  69. #endif
  70. #ifdef ENABLE_FEATURE_WSCONSOLE
  71. #include "html_console_ws.h"
  72. #endif
  73. void httpServerSendHtmlHeadChunked()
  74. {
  75. httpServer.setContentLength(CONTENT_LENGTH_UNKNOWN); //Enable Chunked Transfer
  76. httpServer.send(200, "text/html", html_head_part1);
  77. httpServer.sendContent_P(PGMStr_FIRMWARE_NAME);
  78. httpServer.sendContent(" - ");
  79. httpServer.sendContent(confDevWiFi.deviceName);
  80. httpServer.sendContent_P(html_head_part2);
  81. }
  82. void httpServerSendHtmlBodyPageheadChunked()
  83. {
  84. httpServer.sendContent_P(html_body_pagehead_part1);
  85. httpServer.sendContent_P(PGMStr_FIRMWARE_NAME);
  86. httpServer.sendContent(" - ");
  87. httpServer.sendContent(confDevWiFi.deviceName);
  88. httpServer.sendContent_P(html_body_pagehead_part2);
  89. if (configChangedRestartRequired)
  90. httpServer.sendContent_P(html_body_pagehead_confchangednote);
  91. }
  92. void httpServerSendHtmlFooterChunked()
  93. {
  94. httpServer.sendContent_P(html_footer1);
  95. httpServer.sendContent_P(html_footer_a1);
  96. httpServer.sendContent_P(PGMStr_FIRMWARE_URL);
  97. httpServer.sendContent_P(html_footer_a2);
  98. httpServer.sendContent_P(PGMStr_FIRMWARE_NAME);
  99. httpServer.sendContent_P(html_footer_ae);
  100. httpServer.sendContent(" ");
  101. httpServer.sendContent_P(PGMStr_FIRMWARE_VERSION);
  102. #ifdef DEBUGMODE
  103. httpServer.sendContent_P(PGMStr_WEB_DEBUGBUILD);
  104. #endif
  105. httpServer.sendContent(" by ");
  106. httpServer.sendContent_P(html_footer_a1);
  107. httpServer.sendContent_P(PGMStr_FIRMWARE_COPYRIGHT_URL);
  108. httpServer.sendContent_P(html_footer_a2);
  109. httpServer.sendContent_P(PGMStr_FIRMWARE_COPYRIGHT);
  110. httpServer.sendContent_P(html_footer_ae);
  111. httpServer.sendContent_P(html_footer2);
  112. httpServer.sendContent("");
  113. httpServer.client().stop();
  114. }
  115. void httpServer_logWebRequest() {
  116. String _addr = httpServer.client().remoteIP().toString();
  117. String _method = (httpServer.method() == HTTP_GET) ? "GET" : "POST";
  118. if(httpServer.args() > 0) {
  119. String _args = "";
  120. for (uint8_t _i = 0; _i < httpServer.args(); _i++) {
  121. if(_i > 0) _args += ", ";
  122. _args += httpServer.argName(_i) + "=" + httpServer.arg(_i);
  123. }
  124. snprintf(logBuf, LOG_BUFFER_SIZE, "WEB: %s %s - %s (from %s)", _method.c_str(), httpServer.uri().c_str(), _args.c_str(), _addr.c_str());
  125. }
  126. else {
  127. snprintf(logBuf, LOG_BUFFER_SIZE, "WEB: %s %s (from %s)", _method.c_str(), httpServer.uri().c_str(), _addr.c_str());
  128. }
  129. sendLog(logBuf, LOGLEVEL_INFO);
  130. }
  131. bool httpIsAuthenticated()
  132. {
  133. if (WifiInApMode && strlen(confSecrets.WiFiAPModePassword) >= 8)
  134. return true;
  135. if (confWeb.http_user_auth)
  136. {
  137. boolean useAuth = false;
  138. boolean isAuthenticated = false;
  139. // user authentication enabled - only allow access without authentication if no admin password is set
  140. // or if user1 credentials are empty (access in "user mode")
  141. if (strlen(confSecrets.http_pass) > 0 || strlen(confSecrets.http_pass1) > 0 || strlen(confSecrets.http_pass2) > 0)
  142. useAuth = true;
  143. if (strlen(confSecrets.http_pass) == 0)
  144. {
  145. return true; // no admin password set - in this case authentication is off
  146. }
  147. if (useAuth)
  148. {
  149. // allow access if one set of valid credentials are given
  150. if ((strlen(confSecrets.http_user) > 0 && strlen(confSecrets.http_pass) > 0))
  151. {
  152. if (httpServer.authenticate(confSecrets.http_user, confSecrets.http_pass))
  153. isAuthenticated = true;
  154. }
  155. if ((strlen(confSecrets.http_user1) > 0 && strlen(confSecrets.http_pass1) > 0))
  156. {
  157. if (httpServer.authenticate(confSecrets.http_user1, confSecrets.http_pass1))
  158. isAuthenticated = true;
  159. }
  160. if ((strlen(confSecrets.http_user2) > 0 && strlen(confSecrets.http_pass2) > 0))
  161. {
  162. if (httpServer.authenticate(confSecrets.http_user2, confSecrets.http_pass2))
  163. isAuthenticated = true;
  164. }
  165. // also allow access if admin credentials are set but user1 password is empty and user-authentication is enabled
  166. if (strlen(confSecrets.http_pass1) == 0)
  167. {
  168. isAuthenticated = true;
  169. }
  170. return isAuthenticated;
  171. }
  172. // allow access if all credentials are empty
  173. else
  174. return true;
  175. }
  176. // user authentication disabled - only allow access without password if no admin password is set
  177. else
  178. {
  179. if (strlen(confSecrets.http_pass) > 0)
  180. {
  181. if (httpServer.authenticate(confSecrets.http_user, confSecrets.http_pass))
  182. return true;
  183. else
  184. return false;
  185. }
  186. else
  187. return true;
  188. }
  189. }
  190. bool httpIsAuthenticatedAdmin()
  191. {
  192. if (WifiInApMode && strlen(confSecrets.WiFiAPModePassword) >= 8)
  193. return true;
  194. boolean auth = false;
  195. if ((strlen(confSecrets.http_user) > 0 && strlen(confSecrets.http_pass) > 0))
  196. auth = true;
  197. if (auth)
  198. {
  199. if (!httpServer.authenticate(confSecrets.http_user, confSecrets.http_pass))
  200. return false;
  201. else
  202. return true;
  203. }
  204. else
  205. return true;
  206. }
  207. void httpServerHandleNotFound()
  208. {
  209. String message = "File Not Found\n\n";
  210. message += "URI: ";
  211. message += httpServer.uri();
  212. message += "\nMethod: ";
  213. message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
  214. message += "\nArguments: ";
  215. message += httpServer.args();
  216. message += "\n";
  217. for (uint8_t i = 0; i < httpServer.args(); i++) {
  218. message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
  219. }
  220. if (confLog.logWebRequests) {
  221. snprintf(logBuf, LOG_BUFFER_SIZE, "WEB: 404 - %s %s (from %s)", (httpServer.method() == HTTP_GET) ? "GET" : "POST", httpServer.uri().c_str(), httpServer.client().remoteIP().toString().c_str());
  222. sendLog(logBuf, LOGLEVEL_INFO);
  223. }
  224. httpServer.send(404, "text/plain", message);
  225. //httpServer.send(404, "text/plain", "404 NOT FOUND");
  226. }
  227. void httpSendUnauthorized()
  228. {
  229. httpServer.send(401, "text/plain", "UNAUTHORIZED");
  230. }
  231. void httpSend200OK()
  232. {
  233. httpServer.send(200, "text/plain", "OK");
  234. }
  235. bool httpCheckToken()
  236. {
  237. if (confSecrets.http_token[0] != '\0')
  238. { // dont accept empty token
  239. if (httpServer.hasArg("token"))
  240. {
  241. char buf[20];
  242. httpServer.arg("token").toCharArray(buf, 20);
  243. if (strcmp(buf, confSecrets.http_token) == 0)
  244. return true;
  245. else
  246. return false;
  247. }
  248. else
  249. return false;
  250. }
  251. else
  252. return false;
  253. }
  254. void httpServerInit()
  255. {
  256. httpServer.on("/style.css", []() {
  257. httpServer.sendHeader("cache-control", "max-age=86400", false);
  258. httpServer.send_P(200, "text/css", html_stylesheet);
  259. });
  260. httpServer.on("/favicon.ico", []() {
  261. httpServer.send(404, "text/plain", "404 NOT FOUND"); // send 404 without logging it
  262. });
  263. httpServer.on("/fdl", []() {
  264. if (!httpIsAuthenticatedAdmin())
  265. httpSendUnauthorized();
  266. else {
  267. char _bufVal[31];
  268. char _buf[51];
  269. if (httpServer.hasArg("f")) {
  270. httpServer.arg("f").toCharArray(_bufVal, 30);
  271. if (!LittleFS.exists(_bufVal))
  272. {
  273. sprintf(_buf, "404 - file %s not found", _bufVal);
  274. httpServer.send(404, "text/plain", _buf);
  275. }
  276. else {
  277. FS_downloadFile(_bufVal, false);
  278. }
  279. }
  280. else {
  281. httpServer.send(404, "text/plain", "400: bad request");
  282. }
  283. }
  284. });
  285. //httpServer.on("/fs/del", []() {
  286. httpServer.on("/fdel", HTTP_POST, []() {
  287. if (!httpIsAuthenticatedAdmin())
  288. httpSendUnauthorized();
  289. else
  290. {
  291. char _returnPage[31];
  292. if (httpServer.hasArg("rt")) {
  293. httpServer.arg("rt").toCharArray(_returnPage, 30);
  294. }
  295. else {
  296. strcpy(_returnPage, "/avrflash");
  297. }
  298. char _bufVal[31];
  299. char _buf[51];
  300. if (httpServer.hasArg("f")) {
  301. httpServer.arg("f").toCharArray(_bufVal, 30);
  302. if (FS_deleteFile(_bufVal))
  303. {
  304. //sprintf(_buf, "file %s deleted successfully.", _bufVal);
  305. //httpServer.send(200, "text/plain", _buf);
  306. httpServer.sendHeader("Location", _returnPage); // Redirect the client to the success page
  307. httpServer.send(303);
  308. }
  309. else {
  310. sprintf(_buf, "404 - file %s not found", _bufVal);
  311. httpServer.send(404, "text/plain", _buf);
  312. }
  313. }
  314. else {
  315. httpServer.send(400, "text/plain", "400: bad request");
  316. }
  317. }
  318. });
  319. httpServer.on("/fupl", HTTP_POST, // if the client posts to the upload page
  320. [](){
  321. if (!httpIsAuthenticatedAdmin())
  322. httpSendUnauthorized();
  323. else httpServer.send(200); }, // Send status 200 (OK) to tell the client we are ready to receive
  324. FS_handleFileUpload // Receive and save the file
  325. );
  326. httpServer.on("/api", []() {
  327. if (!httpIsAuthenticated())
  328. return httpServer.requestAuthentication();
  329. else
  330. {
  331. //if (confLog.logWebRequests || httpServer.args() > 0) httpServer_logWebRequest();
  332. if (confLog.logWebRequests) httpServer_logWebRequest();
  333. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  334. if (httpServer.hasArg("BtnPlus"))
  335. {
  336. thermostat_setTempStepUp();
  337. sendLog(F("WEB: BtnPlus"), LOGLEVEL_INFO);
  338. }
  339. if (httpServer.hasArg("BtnMinus"))
  340. {
  341. thermostat_setTempStepDown();
  342. sendLog(F("WEB: BtnMinus"), LOGLEVEL_INFO);
  343. }
  344. if (httpServer.hasArg("BtnPset0"))
  345. {
  346. thermostat_setPresetTo(0);
  347. sendLog(F("WEB: BtnPset0"), LOGLEVEL_INFO);
  348. }
  349. if (httpServer.hasArg("BtnPset1"))
  350. {
  351. thermostat_setPresetTo(1);
  352. sendLog(F("WEB: BtnPset1"), LOGLEVEL_INFO);
  353. }
  354. if (httpServer.hasArg("BtnPset2"))
  355. {
  356. thermostat_setPresetTo(2);
  357. sendLog(F("WEB: BtnPset2"), LOGLEVEL_INFO);
  358. }
  359. if (httpServer.hasArg("BtnOn"))
  360. {
  361. thermostat_setHeatingmodeTo(1);
  362. sendLog(F("WEB: BtnOn"), LOGLEVEL_INFO);
  363. }
  364. if (httpServer.hasArg("BtnOff"))
  365. {
  366. thermostat_setHeatingmodeTo(0);
  367. sendLog(F("WEB: BtnOff"), LOGLEVEL_INFO);
  368. }
  369. if (httpServer.hasArg("BtnL1Plus"))
  370. {
  371. thermostat_setTempLowStepUp();
  372. sendLog(F("WEB: BtnL1Plus"), LOGLEVEL_INFO);
  373. }
  374. if (httpServer.hasArg("BtnL1Minus"))
  375. {
  376. thermostat_setTempLowStepDown();
  377. sendLog(F("WEB: BtnL1Minus"), LOGLEVEL_INFO);
  378. }
  379. if (httpServer.hasArg("BtnL2Plus"))
  380. {
  381. thermostat_setTempLow2StepUp();
  382. sendLog(F("WEB: BtnL2Plus"), LOGLEVEL_INFO);
  383. }
  384. if (httpServer.hasArg("BtnL2Minus"))
  385. {
  386. thermostat_setTempLow2StepDown();
  387. sendLog(F("WEB: BtnL2Minus"), LOGLEVEL_INFO);
  388. }
  389. if (httpServer.hasArg("setTemp"))
  390. {
  391. sendLog(F("WEB: /api?setTemp"), LOGLEVEL_INFO);
  392. char _bufVal[20];
  393. httpServer.arg("setTemp").toCharArray(_bufVal, 20);
  394. float _valueFloat = round(atof(_bufVal) * 2.0) / 2.0;
  395. thermostat_setTempTo(_valueFloat);
  396. }
  397. if (httpServer.hasArg("setPause"))
  398. {
  399. sendLog(F("WEB: /api?setPause"), LOGLEVEL_INFO);
  400. char _bufVal[20];
  401. httpServer.arg("setPause").toCharArray(_bufVal, 20);
  402. int _valueInt = atoi(_bufVal);
  403. thermostat_setHeatingPause(_valueInt);
  404. }
  405. if (httpServer.hasArg("setMode"))
  406. {
  407. sendLog(F("WEB: /api?setMode"), LOGLEVEL_INFO);
  408. char _bufVal[20];
  409. httpServer.arg("setMode").toCharArray(_bufVal, 20);
  410. int _valueInt = atoi(_bufVal);
  411. if (_valueInt >= 0 && _valueInt <= 1)
  412. thermostat_setHeatingmodeTo(_valueInt);
  413. }
  414. if (httpServer.hasArg("setPreset"))
  415. {
  416. sendLog(F("WEB: /api?setPreset"), LOGLEVEL_INFO);
  417. char _bufVal[20];
  418. httpServer.arg("setPreset").toCharArray(_bufVal, 20);
  419. int _valueInt = atoi(_bufVal);
  420. if (_valueInt >= 0 && _valueInt <= 2)
  421. thermostat_setPresetTo(_valueInt);
  422. }
  423. #endif // FIRMWARE_VARIANT_THERMOSTAT
  424. //char ch_currTemp[6];
  425. //char ch_currSetTemp[6];
  426. //dtostrf(sensor_DHT_currTemp, 1, 1, ch_currTemp );
  427. //dtostrf(setTemp, 1, 1, ch_currSetTemp );
  428. //build json object of program data
  429. StaticJsonDocument<850> json;
  430. json["devname"] = confDevWiFi.deviceName;
  431. json["ssid"] = WiFi.SSID();
  432. json["WiFiNum"] = persWM.getActiveWiFiNum();
  433. //json["uptime"] = uptimeStr;
  434. json["uptime"] = getUptimeStr();
  435. #ifdef ENABLE_FEATURE_NTP_TIME
  436. if (confTime.ntpEnable)
  437. {
  438. char _buf[13];
  439. updateTime();
  440. if (lt.tm_year > 70) // check if time has been synced
  441. {
  442. strftime(_buf, sizeof(_buf), "%H:%M", &lt);
  443. json["time"] = _buf;
  444. strftime(_buf, sizeof(_buf), "%d.%m.%Y", &lt);
  445. json["date"] = _buf;
  446. }
  447. }
  448. #endif
  449. json["freeheap"] = ESP.getFreeHeap();
  450. mqtt_updateCurrentStateName();
  451. json["mqttstate"] = mqttCurrentStateName;
  452. json["mqtthost"] = confMqtt.mqtt_server;
  453. if (mqtt_reconnects < 1) json["mqttreconn"] = mqtt_reconnects;
  454. else json["mqttreconn"] = mqtt_reconnects - 1;
  455. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  456. if (owTemp_feed > -50.0) json["tempFeed"] = round1(owTemp_feed);
  457. else json["tempFeed"] = "-.-";
  458. if (owTemp_return > -50.0) json["tempReturn"] = round1(owTemp_return);
  459. else json["tempReturn"] = "-.-";
  460. if (owTemp_out > -50.0) json["tempOut"] = round1(owTemp_out);
  461. else json["tempOut"] = "-.-";
  462. if (heatcontrol_in_heat_request) json["heatReq"] = 1;
  463. else json["heatReq"] = 0;
  464. if (heatcontrol_in_heat_active) json["statHeat"] = 1;
  465. else json["statHeat"] = 0;
  466. if (heatcontrol_out_heat) json["outHeat"] = 1;
  467. else json["outHeat"] = 0;
  468. if (heatcontrol_out_pump) json["outPump"] = 1;
  469. else json["outPump"] = 0;
  470. //if (heatcontrol_state_testmode_active) json["statTest"] = 1;
  471. //else json["statTest"] = 0;
  472. json["statTest"] = heatcontrol_testMode_getRemainingMins();
  473. //if (heatcontrol_state_pumpBacklash_active) json["pumpNL"] = 1;
  474. //else json["pumpNL"] = 0;
  475. json["pumpNL"] = heatcontrol_pumpBacklash_getRemainingMins();
  476. if (heatcontrol_in_sw_disableControl_heating) json["cDisHeat"] = 1;
  477. else json["cDisHeat"] = 0;
  478. if (heatcontrol_in_sw_disableControl_pump) json["cDisPump"] = 1;
  479. else json["cDisPump"] = 0;
  480. json["useHeatC"] = confHeatc.useHeatCurve;
  481. json["currHeatC"] = heatcontrol_currentHeatCurveValue;
  482. json["currHeatCOff"] = heatcontrol_currentHeatCurveValue + confHeatc.hystereseOff;
  483. json["currHeatCOn"] = heatcontrol_currentHeatCurveValue - confHeatc.hystereseOn ;
  484. json["statLockTime"] = heatcontrol_lockTime_getRemainingMins();
  485. if (heatcontrol_getLockActive()) json["statLock"] = 1;
  486. else json["statLock"] = 0;
  487. if (heatcontrol_getLockActive() && heatcontrol_lockTime_getRemainingMins() == 0) {
  488. json["lockUntilTFeed"] = heatcontrol_currentHeatCurveValue - confHeatc.hystereseOn;
  489. }
  490. else {
  491. json["lockUntilTFeed"] = "-";
  492. }
  493. #endif // FIRMWARE_VARIANT_HEATCONTROL
  494. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  495. json["setTemp"] = thermostat_setTemp;
  496. json["currSetTemp"] = thermostat_currSetTemp;
  497. json["actSetTemp"] = thermostat_currActualSetTemp;
  498. uint8_t _heatingState;
  499. if(thermostat_turnHeatingOn) _heatingState = 1;
  500. else if(thermostat_heatingLockTime > 0) _heatingState = 2;
  501. else _heatingState = 0;
  502. json["heating"] = _heatingState;
  503. json["heatingLockTime"] = thermostat_heatingLockTime;
  504. json["heatingPause"] = thermostat_heatingPause;
  505. json["mode"] = thermostat_heatingMode;
  506. json["modeName"] = thermostat_currentModeName;
  507. json["pset"] = thermostat_preset;
  508. json["psetName"] = thermostat_currentPresetName;
  509. json["psetName0"] = confTherm.psetName0;
  510. json["psetName1"] = confTherm.psetName1;
  511. json["psetName2"] = confTherm.psetName2;
  512. json["tempLow"] = thermostat_setTempLow;
  513. json["tempLow2"] = thermostat_setTempLow2;
  514. #endif // FIRMWARE_VARIANT_THERMOSTAT
  515. #ifdef ENABLE_OUTSIDE_TEMP_MQTT
  516. json["outTemp"] = round1(outTemp);
  517. json["outHum"] = outHum;
  518. #endif
  519. #ifdef ENABLE_SENSOR_DHT22
  520. if (confSens.DHT_enable) {
  521. json["temp"] = round1(sensor_DHT_currTemp);
  522. json["hum"] = int(sensor_DHT_currHum);
  523. }
  524. #endif
  525. char jsonchar[750];
  526. serializeJson(json, jsonchar);
  527. httpServer.send(200, "application/json", jsonchar);
  528. }
  529. }); //httpServer.on /api
  530. httpServer.on("/confDataWeb", []() {
  531. if (!httpIsAuthenticatedAdmin())
  532. httpSendUnauthorized();
  533. else
  534. {
  535. if (confLog.logWebRequests) httpServer_logWebRequest();
  536. StaticJsonDocument<1000> json;
  537. json["apiToken"] = confSecrets.http_token;
  538. json["httpUA"] = confSecrets.http_user;
  539. //json["httpPA"] = confWeb.http_pass;
  540. if (strlen(confSecrets.http_pass) > 0)
  541. json["httpPA"] = "****";
  542. else
  543. json["httpPA"] = "";
  544. if (confWeb.http_user_auth)
  545. json["httpAuth"] = 1;
  546. else
  547. json["httpAuth"] = 0;
  548. json["httpU1"] = confSecrets.http_user1;
  549. //json["httpP1"] = confSecrets.http_pass1;
  550. if (strlen(confSecrets.http_pass1) > 0)
  551. json["httpP1"] = "****";
  552. else
  553. json["httpP1"] = "";
  554. json["httpU2"] = confSecrets.http_user2;
  555. //json["httpP2"] = confSecrets.http_pass2;
  556. if (strlen(confSecrets.http_pass2) > 0)
  557. json["httpP2"] = "****";
  558. else
  559. json["httpP2"] = "";
  560. if (confWeb.wConsole)
  561. json["wConsole"] = 1;
  562. else
  563. json["wConsole"] = 0;
  564. if (confWeb.wsConsole)
  565. json["wsConsole"] = 1;
  566. else
  567. json["wsConsole"] = 0;
  568. if (confWeb.enableOTA) json["enableOTA"] = 1;
  569. else json["enableOTA"] = 0;
  570. if (confWeb.FSbrowser) json["FSbrowser"] = 1;
  571. else json["FSbrowser"] = 0;
  572. yield();
  573. char jsonchar[1000];
  574. serializeJson(json, jsonchar);
  575. httpServer.send(200, "application/json", jsonchar);
  576. }
  577. }); //httpServer.on /confdweb
  578. httpServer.on("/confDataSens", []() {
  579. if (!httpIsAuthenticatedAdmin())
  580. httpSendUnauthorized();
  581. else
  582. {
  583. if (confLog.logWebRequests) httpServer_logWebRequest();
  584. StaticJsonDocument<1000> json;
  585. json["measInt"] = confSens.measureInterval;
  586. #ifdef ENABLE_SENSORS_ONEWIRE
  587. JsonArray jsonArr_sensAddr = json.createNestedArray("sensAddr");
  588. JsonArray jsonArr_sensVal = json.createNestedArray("sensVal");
  589. JsonArray jsonArr_sensAss = json.createNestedArray("sensAss");
  590. for (uint8_t i=0; i < oneWireSensors.getDeviceCount(); i++) {
  591. char devAddr[25];
  592. char jsonDatasetName[15];
  593. float tempC;
  594. tempC = oneWireSensors.getTempC(oneWireSensors_IndexToAddress[i]);
  595. sprintf(devAddr, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", oneWireSensors_IndexToAddress[i][0], \
  596. oneWireSensors_IndexToAddress[i][1], \
  597. oneWireSensors_IndexToAddress[i][2], \
  598. oneWireSensors_IndexToAddress[i][3], \
  599. oneWireSensors_IndexToAddress[i][4], \
  600. oneWireSensors_IndexToAddress[i][5], \
  601. oneWireSensors_IndexToAddress[i][6], \
  602. oneWireSensors_IndexToAddress[i][7]);
  603. jsonArr_sensAddr.add(devAddr);
  604. jsonArr_sensVal.add(tempC);
  605. uint8_t _assignSens = 255;
  606. if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_FEED] == i) {
  607. jsonArr_sensAss.add("FEED");
  608. _assignSens = ONEWIRE_SENSOR_INDEX_FEED;
  609. }
  610. else if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_RETURN] == i) {
  611. jsonArr_sensAss.add("RETURN");
  612. _assignSens = ONEWIRE_SENSOR_INDEX_RETURN;
  613. }
  614. else if(oneWireSensor_assignedDevToIndex[ONEWIRE_SENSOR_INDEX_OUT] == i) {
  615. jsonArr_sensAss.add("OUT");
  616. _assignSens = ONEWIRE_SENSOR_INDEX_OUT;
  617. }
  618. else jsonArr_sensAss.add("");
  619. sprintf(jsonDatasetName, "assignSens_%d", i);
  620. json[jsonDatasetName] = _assignSens;
  621. }
  622. yield();
  623. #endif
  624. #ifdef ENABLE_SENSOR_DHT22
  625. json["DHT_tempCorr"] = confSens.DHT_tempCorrVal;
  626. json["DHT_humCorr"] = confSens.DHT_humCorrVal;
  627. json["DHT_enable"] = confSens.DHT_enable;
  628. #endif
  629. char jsonchar[1000];
  630. serializeJson(json, jsonchar);
  631. httpServer.send(200, "application/json", jsonchar);
  632. }
  633. }); //httpServer.on /confDataSens
  634. httpServer.on("/confDataMqtt", []() {
  635. if (!httpIsAuthenticatedAdmin())
  636. httpSendUnauthorized();
  637. else
  638. {
  639. if (confLog.logWebRequests) httpServer_logWebRequest();
  640. StaticJsonDocument<1000> json;
  641. if (confMqtt.mqtt_enable)
  642. json["mqttEnable"] = 1;
  643. else
  644. json["mqttEnable"] = 0;
  645. json["mqttHost"] = confMqtt.mqtt_server;
  646. json["mqttPort"] = confMqtt.mqtt_port;
  647. json["mqttUser"] = confSecrets.mqtt_user;
  648. //json["mqttPass"] = confMqtt.mqtt_pass;
  649. if (strlen(confSecrets.mqtt_pass) > 0)
  650. json["mqttPass"] = "****";
  651. else
  652. json["mqttPass"] = "";
  653. json["inTop"] = confMqtt.mqtt_topic_in;
  654. json["outTop"] = confMqtt.mqtt_topic_out;
  655. if (confMqtt.mqtt_outRetain)
  656. json["outRet"] = 1;
  657. else
  658. json["outRet"] = 0;
  659. if (confMqtt.mqtt_outRetain_sensors)
  660. json["outRetSens"] = 1;
  661. else
  662. json["outRetSens"] = 0;
  663. json["outPubInt"] = confMqtt.mqtt_outPubInterval;
  664. json["outPubIntSens"] = confMqtt.mqtt_outPubInterval_sensors;
  665. json["willTop"] = confMqtt.mqtt_willTopic;
  666. json["willQos"] = confMqtt.mqtt_willQos;
  667. if (confMqtt.mqtt_willRetain)
  668. json["willRet"] = 1;
  669. else
  670. json["willRet"] = 0;
  671. json["willMsg"] = confMqtt.mqtt_willMsg;
  672. json["connMsg"] = confMqtt.mqtt_connMsg;
  673. if (confMqtt.mqtt_enable_heartbeat)
  674. json["hbEnable"] = 1;
  675. else
  676. json["hbEnable"] = 0;
  677. json["hbReconn"] = confMqtt.mqtt_heartbeat_maxage_reconnect;
  678. json["hbReboot"] = confMqtt.mqtt_heartbeat_maxage_reboot;
  679. if (confMqtt.mqtt_reconnect_silent)
  680. json["reconSilent"] = 1;
  681. else
  682. json["reconSilent"] = 0;
  683. yield();
  684. char jsonchar[1000];
  685. serializeJson(json, jsonchar);
  686. httpServer.send(200, "application/json", jsonchar);
  687. }
  688. }); //httpServer.on /confDataMqtt
  689. httpServer.on("/setConfWeb", []() {
  690. if (!httpIsAuthenticatedAdmin())
  691. httpSendUnauthorized();
  692. else
  693. {
  694. if (confLog.logWebRequests) httpServer_logWebRequest();
  695. bool httpPASet, httpP1Set, httpP2Set;
  696. httpPASet = false;
  697. httpP1Set = false;
  698. httpP2Set = false;
  699. if (httpServer.hasArg("httpPASet"))
  700. httpPASet = true;
  701. if (httpServer.hasArg("httpP1Set"))
  702. httpP1Set = true;
  703. if (httpServer.hasArg("httpP2Set"))
  704. httpP2Set = true;
  705. for (int i = 0; i < httpServer.args(); i++)
  706. {
  707. char bufName[21];
  708. char bufValue[101];
  709. httpServer.argName(i).toCharArray(bufName, 20);
  710. httpServer.arg(i).toCharArray(bufValue, 100);
  711. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  712. {
  713. if(debug>0) {
  714. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  715. sendLog(logBuf);
  716. }
  717. if (strcmp(bufName, "httpUA") == 0 || strcmp(bufName, "httpPA") == 0)
  718. {
  719. if (httpPASet)
  720. setConfig(bufName, bufValue);
  721. }
  722. else if (strcmp(bufName, "httpU1") == 0 || strcmp(bufName, "httpP1") == 0)
  723. {
  724. if (httpP1Set)
  725. setConfig(bufName, bufValue);
  726. }
  727. else if (strcmp(bufName, "httpU2") == 0 || strcmp(bufName, "httpP2") == 0)
  728. {
  729. if (httpP2Set)
  730. setConfig(bufName, bufValue);
  731. }
  732. else if (strcmp(bufName, "httpPASet") != 0 && strcmp(bufName, "httpP1Set") != 0 && strcmp(bufName, "httpP2Set") != 0) {
  733. setConfig(bufName, bufValue);
  734. }
  735. else {
  736. setConfig(bufName, bufValue);
  737. }
  738. }
  739. }
  740. yield();
  741. saveConf_Web();
  742. saveConf_Secrets();
  743. yield();
  744. loadConf_Web();
  745. loadConf_Secrets();
  746. yield();
  747. httpServerHandlePage_confSaved();
  748. }
  749. }); //httpServer.on /setConfWeb
  750. httpServer.on("/setConfMqtt", []() {
  751. if (!httpIsAuthenticatedAdmin())
  752. httpSendUnauthorized();
  753. else
  754. {
  755. if (confLog.logWebRequests) httpServer_logWebRequest();
  756. bool mqttPassSet;
  757. mqttPassSet = false;
  758. if (httpServer.hasArg("mqttPassSet"))
  759. mqttPassSet = true;
  760. for (int i = 0; i < httpServer.args(); i++)
  761. {
  762. char bufName[21];
  763. char bufValue[101];
  764. httpServer.argName(i).toCharArray(bufName, 20);
  765. httpServer.arg(i).toCharArray(bufValue, 100);
  766. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  767. {
  768. if(debug>0) {
  769. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  770. sendLog(logBuf);
  771. }
  772. if (strcmp(bufName, "mqttUser") == 0 || strcmp(bufName, "mqttPass") == 0)
  773. {
  774. if (mqttPassSet)
  775. setConfig(bufName, bufValue);
  776. }
  777. else
  778. setConfig(bufName, bufValue);
  779. }
  780. }
  781. yield();
  782. saveConf_Mqtt();
  783. saveConf_Secrets();
  784. yield();
  785. loadConf_Mqtt();
  786. loadConf_Secrets();
  787. //httpServerHandleConfSavedRestartPage();
  788. httpServerHandlePage_confSaved();
  789. }
  790. }); //httpServer.on /setConfMqtt
  791. httpServer.on("/confDataDevWiFi", []() {
  792. if (!httpIsAuthenticated())
  793. return httpServer.requestAuthentication();
  794. else
  795. {
  796. if (confLog.logWebRequests) httpServer_logWebRequest();
  797. StaticJsonDocument<800> json;
  798. json["devName"] = confDevWiFi.deviceName;
  799. json["hostName"] = confDevWiFi.hostName;
  800. json["SSID1"] = confDevWiFi.WiFiSSID1;
  801. //json["WPW1"] = confDevWiFi.WiFiPW1;
  802. if (strlen(confSecrets.WiFiPW1) > 0)
  803. json["WPW1"] = "****";
  804. else
  805. json["WPW1"] = "";
  806. json["SSID2"] = confDevWiFi.WiFiSSID2;
  807. //json["WPW2"] = confDevWiFi.WiFiPW2;
  808. if (strlen(confSecrets.WiFiPW2) > 0)
  809. json["WPW2"] = "****";
  810. else
  811. json["WPW2"] = "";
  812. json["SSIDAP"] = confDevWiFi.WiFiAPModeSSID;
  813. json["WPWAP"] = confSecrets.WiFiAPModePassword;
  814. json["WAPtout"] = confDevWiFi.WiFiAPModeTimeout;
  815. json["WConnCheck"] = confDevWiFi.WiFiConnCheckInterval;
  816. json["Wretry"] = confDevWiFi.WiFiRetryInterval;
  817. json["Wreboot"] = confDevWiFi.WiFiRebootOnNoConnect;
  818. if(confDevWiFi.enableArduinoOTA) json["ArdOTA"] = 1;
  819. else json["ArdOTA"] = 0;
  820. yield();
  821. char jsonchar[1000];
  822. serializeJson(json, jsonchar);
  823. httpServer.send(200, "application/json", jsonchar);
  824. }
  825. }); //httpServer.on /confDataDevWiFi
  826. httpServer.on("/setConfDevWiFi", []() {
  827. if (!httpIsAuthenticatedAdmin())
  828. httpSendUnauthorized();
  829. else
  830. {
  831. if (confLog.logWebRequests) httpServer_logWebRequest();
  832. bool WPW1Set, WPW2Set, WPWAPSet;
  833. WPW1Set = false;
  834. WPW2Set = false;
  835. WPWAPSet = false;
  836. if (httpServer.hasArg("WPW1Set"))
  837. WPW1Set = true;
  838. if (httpServer.hasArg("WPW2Set"))
  839. WPW2Set = true;
  840. if (httpServer.hasArg("WPWAPSet"))
  841. WPWAPSet = true;
  842. for (int i = 0; i < httpServer.args(); i++)
  843. {
  844. char bufName[21];
  845. char bufValue[101];
  846. httpServer.argName(i).toCharArray(bufName, 20);
  847. httpServer.arg(i).toCharArray(bufValue, 100);
  848. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  849. {
  850. if(debug>0) {
  851. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  852. sendLog(logBuf);
  853. }
  854. if (strcmp(bufName, "SSID1") == 0 || strcmp(bufName, "WPW1") == 0)
  855. {
  856. if (WPW1Set)
  857. setConfig(bufName, bufValue);
  858. }
  859. else if (strcmp(bufName, "SSID2") == 0 || strcmp(bufName, "WPW2") == 0)
  860. {
  861. if (WPW2Set)
  862. setConfig(bufName, bufValue);
  863. }
  864. else if (strcmp(bufName, "WPWAP") == 0)
  865. {
  866. if (WPWAPSet)
  867. setConfig(bufName, bufValue);
  868. }
  869. else
  870. setConfig(bufName, bufValue);
  871. }
  872. }
  873. yield();
  874. saveConf_DevWiFi();
  875. saveConf_Secrets();
  876. yield();
  877. loadConf_DevWiFi();
  878. loadConf_Secrets();
  879. //httpServerHandleConfSavedRestartPage();
  880. httpServerHandlePage_confSaved();
  881. }
  882. }); //httpServer.on /setConfDevWiFi
  883. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  884. httpServer.on("/setConfTherm", []() {
  885. if (!httpIsAuthenticatedAdmin())
  886. httpSendUnauthorized();
  887. else
  888. {
  889. if (confLog.logWebRequests) httpServer_logWebRequest();
  890. for (int i = 0; i < httpServer.args(); i++)
  891. {
  892. char bufName[21];
  893. char bufValue[101];
  894. httpServer.argName(i).toCharArray(bufName, 20);
  895. httpServer.arg(i).toCharArray(bufValue, 100);
  896. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  897. {
  898. if(debug>0) {
  899. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  900. sendLog(logBuf);
  901. }
  902. setConfig(bufName, bufValue);
  903. }
  904. }
  905. yield();
  906. saveConf_Therm();
  907. yield();
  908. loadConf_Therm();
  909. httpServerHandlePage_confSaved();
  910. }
  911. }); //httpServer.on /setConfTherm
  912. #endif // FIRMWARE_VARIANT_THERMOSTAT
  913. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  914. httpServer.on("/setConfHeatc", []() {
  915. if (!httpIsAuthenticatedAdmin())
  916. httpSendUnauthorized();
  917. else
  918. {
  919. if (confLog.logWebRequests) httpServer_logWebRequest();
  920. for (int i = 0; i < httpServer.args(); i++)
  921. {
  922. char bufName[21];
  923. char bufValue[101];
  924. httpServer.argName(i).toCharArray(bufName, 20);
  925. httpServer.arg(i).toCharArray(bufValue, 100);
  926. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  927. {
  928. if(debug>0) {
  929. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  930. sendLog(logBuf);
  931. }
  932. setConfig(bufName, bufValue);
  933. }
  934. }
  935. yield();
  936. saveConf_Heatc();
  937. yield();
  938. loadConf_Heatc();
  939. httpServerHandlePage_confSaved();
  940. }
  941. }); //httpServer.on /setConfHeatc
  942. #endif // FIRMWARE_VARIANT_HEATCONTROL
  943. httpServer.on("/setConfAdd", []() {
  944. if (!httpIsAuthenticatedAdmin())
  945. httpSendUnauthorized();
  946. else
  947. {
  948. if (confLog.logWebRequests) httpServer_logWebRequest();
  949. for (int i = 0; i < httpServer.args(); i++)
  950. {
  951. char bufName[21];
  952. char bufValue[101];
  953. httpServer.argName(i).toCharArray(bufName, 20);
  954. httpServer.arg(i).toCharArray(bufValue, 100);
  955. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  956. {
  957. if(debug>0) {
  958. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  959. sendLog(logBuf);
  960. }
  961. setConfig(bufName, bufValue);
  962. }
  963. }
  964. yield();
  965. saveConf_Add();
  966. yield();
  967. loadConf_Add();
  968. httpServerHandlePage_confSaved();
  969. }
  970. }); //httpServer.on /setConfAdd
  971. #ifdef ENABLE_FEATURE_NTP_TIME
  972. httpServer.on("/setConfTime", []() {
  973. if (!httpIsAuthenticatedAdmin())
  974. httpSendUnauthorized();
  975. else
  976. {
  977. if (confLog.logWebRequests) httpServer_logWebRequest();
  978. for (int i = 0; i < httpServer.args(); i++)
  979. {
  980. char bufName[21];
  981. char bufValue[101];
  982. httpServer.argName(i).toCharArray(bufName, 20);
  983. httpServer.arg(i).toCharArray(bufValue, 100);
  984. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  985. {
  986. if(debug>0) {
  987. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  988. sendLog(logBuf);
  989. }
  990. setConfig(bufName, bufValue);
  991. }
  992. }
  993. yield();
  994. saveConf_Time();
  995. yield();
  996. loadConf_Time();
  997. httpServerHandlePage_confSaved();
  998. }
  999. }); //httpServer.on /setConfTime
  1000. #endif
  1001. httpServer.on("/setConfLog", []() {
  1002. if (!httpIsAuthenticatedAdmin())
  1003. httpSendUnauthorized();
  1004. else
  1005. {
  1006. if (confLog.logWebRequests) httpServer_logWebRequest();
  1007. for (int i = 0; i < httpServer.args(); i++)
  1008. {
  1009. char bufName[21];
  1010. char bufValue[101];
  1011. httpServer.argName(i).toCharArray(bufName, 20);
  1012. httpServer.arg(i).toCharArray(bufValue, 100);
  1013. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  1014. {
  1015. if(debug>0) {
  1016. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  1017. sendLog(logBuf);
  1018. }
  1019. setConfig(bufName, bufValue);
  1020. }
  1021. }
  1022. yield();
  1023. saveConf_Log();
  1024. yield();
  1025. loadConf_Log();
  1026. httpServerHandlePage_confSaved();
  1027. }
  1028. }); //httpServer.on /setConfLog
  1029. httpServer.on("/setConfSens", []() {
  1030. if (!httpIsAuthenticatedAdmin())
  1031. httpSendUnauthorized();
  1032. else
  1033. {
  1034. if (confLog.logWebRequests) httpServer_logWebRequest();
  1035. for (int i = 0; i < httpServer.args(); i++)
  1036. {
  1037. char bufName[21];
  1038. char bufValue[101];
  1039. httpServer.argName(i).toCharArray(bufName, 20);
  1040. httpServer.arg(i).toCharArray(bufValue, 100);
  1041. if (strlen(bufName) > 0 && strcmp(bufName, "plain") != 0) // filter arg "plain" as it sometimes shows up containing ALL arguments
  1042. {
  1043. if(debug>0) {
  1044. snprintf_P(logBuf, LOG_BUFFER_SIZE, PGMStr_web_setConf, bufName, bufValue);
  1045. sendLog(logBuf);
  1046. }
  1047. setConfig(bufName, bufValue);
  1048. }
  1049. }
  1050. yield();
  1051. saveConf_Sens();
  1052. yield();
  1053. loadConf_Sens();
  1054. httpServerHandlePage_confSaved();
  1055. }
  1056. }); //httpServer.on /setConfLog
  1057. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  1058. httpServer.on("/confDataTherm", []() {
  1059. if (!httpIsAuthenticated())
  1060. return httpServer.requestAuthentication();
  1061. else
  1062. {
  1063. if (confLog.logWebRequests) httpServer_logWebRequest();
  1064. StaticJsonDocument<500> json;
  1065. if (confTherm.autoSaveSetTemp)
  1066. json["autoSaveTemp"] = 1;
  1067. else
  1068. json["autoSaveTemp"] = 0;
  1069. if (confTherm.autoSaveHeatingMode)
  1070. json["autoSaveMode"] = 1;
  1071. else
  1072. json["autoSaveMode"] = 0;
  1073. if (confTherm.saveToMqttRetained)
  1074. json["saveToMqttRet"] = 1;
  1075. else
  1076. json["saveToMqttRet"] = 0;
  1077. json["tempMin"] = confTherm.setTempMin;
  1078. json["tempMax"] = confTherm.setTempMax;
  1079. //json["measInt"] = confTherm.measureInterval;
  1080. //json["dispInt"] = confTherm.displayInterval;
  1081. //json["dispTout"] = confTherm.displayTimeout;
  1082. //if (confTherm.PIR_enablesDisplay)
  1083. // json["PIRenDisp"] = 1;
  1084. //else
  1085. // json["PIRenDisp"] = 0;
  1086. if (confTherm.PIRenablesDisplay_preset0only)
  1087. json["PIRenDispPs0"] = 1;
  1088. else
  1089. json["PIRenDispPs0"] = 0;
  1090. if (confTherm.togglingTempHumAIDisplay)
  1091. json["togTHdisp"] = 1;
  1092. else
  1093. json["togTHdisp"] = 0;
  1094. json["minOffTime"] = confTherm.heatingMinOffTime;
  1095. json["tempDec"] = confTherm.setTempDecreaseVal;
  1096. json["hyst"] = confTherm.hysteresis;
  1097. json["offMsg"] = confTherm.offMessage;
  1098. json["modeName0"] = confTherm.modeName0;
  1099. json["modeName1"] = confTherm.modeName1;
  1100. json["psetName0"] = confTherm.psetName0;
  1101. json["psetName1"] = confTherm.psetName1;
  1102. json["psetName2"] = confTherm.psetName2;
  1103. json["iTempLab"] = confTherm.iTempLabel;
  1104. json["oTempLab"] = confTherm.oTempLabel;
  1105. json["pauseTout"] = confTherm.pauseTout;
  1106. yield();
  1107. char jsonchar[1000];
  1108. serializeJson(json, jsonchar);
  1109. httpServer.send(200, "application/json", jsonchar);
  1110. }
  1111. }); //httpServer.on /confDataTherm
  1112. #endif // FIRMWARE_VARIANT_THERMOSTAT
  1113. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  1114. httpServer.on("/confDataHeatc", []() {
  1115. if (!httpIsAuthenticated())
  1116. return httpServer.requestAuthentication();
  1117. else
  1118. {
  1119. if (confLog.logWebRequests) httpServer_logWebRequest();
  1120. StaticJsonDocument<500> json;
  1121. json["heatcm20"] = confHeatc.heatCurve[0];
  1122. json["heatcm15"] = confHeatc.heatCurve[1];
  1123. json["heatcm10"] = confHeatc.heatCurve[2];
  1124. json["heatcm5"] = confHeatc.heatCurve[3];
  1125. json["heatc0"] = confHeatc.heatCurve[4];
  1126. json["heatc5"] = confHeatc.heatCurve[5];
  1127. json["heatc10"] = confHeatc.heatCurve[6];
  1128. json["heatc15"] = confHeatc.heatCurve[7];
  1129. json["heatc20"] = confHeatc.heatCurve[8];
  1130. json["heatlm20"] = confHeatc.heatLocktime[0];
  1131. json["heatlm15"] = confHeatc.heatLocktime[1];
  1132. json["heatlm10"] = confHeatc.heatLocktime[2];
  1133. json["heatlm5"] = confHeatc.heatLocktime[3];
  1134. json["heatl0"] = confHeatc.heatLocktime[4];
  1135. json["heatl5"] = confHeatc.heatLocktime[5];
  1136. json["heatl10"] = confHeatc.heatLocktime[6];
  1137. json["heatl15"] = confHeatc.heatLocktime[7];
  1138. json["heatl20"] = confHeatc.heatLocktime[8];
  1139. json["heatCvHy0"] = confHeatc.hystereseOff;
  1140. json["heatCvHy1"] = confHeatc.hystereseOn;
  1141. json["heatOutTDis"] = confHeatc.disableAboveTOut;
  1142. json["heatTempFeedLimit"] = confHeatc.tempFeedLimit;
  1143. if (confHeatc.useHeatCurve) json["heatUseHC"] = 1;
  1144. else json["heatUseHC"] = 0;
  1145. if (confHeatc.forceHeatCurve) json["heatForceHC"] = 1;
  1146. else json["heatForceHC"] = 0;
  1147. if (confHeatc.forceHeatCurveAlsoForSwitchOn) json["heatForceHCAlsoOn"] = 1;
  1148. else json["heatForceHCAlsoOn"] = 0;
  1149. json["pumpnl"] = confHeatc.pumpBacklash;
  1150. json["pumpForceInt"] = confHeatc.pump_forceRunInterval;
  1151. json["pumpForceTime"] = confHeatc.pumpTime_forceRun;
  1152. json["pumpForceBegin"] = confHeatc.pump_forceRunTimeBegin;
  1153. json["pumpForceEnd"] = confHeatc.pump_forceRunTimeEnd;
  1154. yield();
  1155. char jsonchar[1000];
  1156. serializeJson(json, jsonchar);
  1157. httpServer.send(200, "application/json", jsonchar);
  1158. }
  1159. }); //httpServer.on /confDataHeatc
  1160. #endif // FIRMWARE_VARIANT_HEATCONTROL
  1161. httpServer.on("/confDataAdd", []() {
  1162. if (!httpIsAuthenticated())
  1163. return httpServer.requestAuthentication();
  1164. else
  1165. {
  1166. if (confLog.logWebRequests) httpServer_logWebRequest();
  1167. StaticJsonDocument<1000> json;
  1168. json["outTempTop"] = confAdd.outTemp_topic_in;
  1169. json["outHumTop"] = confAdd.outHum_topic_in;
  1170. json["PIRTop"] = confAdd.mqtt_topic_pir;
  1171. json["PIROnPld"] = confAdd.mqtt_payload_pir_on;
  1172. json["PIROffPld"] = confAdd.mqtt_payload_pir_off;
  1173. yield();
  1174. char jsonchar[1000];
  1175. serializeJson(json, jsonchar);
  1176. httpServer.send(200, "application/json", jsonchar);
  1177. }
  1178. }); //httpServer.on /confDataAdd
  1179. httpServer.on("/confDataTime", []() {
  1180. if (!httpIsAuthenticated())
  1181. return httpServer.requestAuthentication();
  1182. else
  1183. {
  1184. if (confLog.logWebRequests) httpServer_logWebRequest();
  1185. StaticJsonDocument<1000> json;
  1186. if (confTime.ntpEnable)
  1187. json["NTPEnable"] = 1;
  1188. else
  1189. json["NTPEnable"] = 0;
  1190. json["NTPServer1"] = confTime.ntpServer1;
  1191. json["NTPServer2"] = confTime.ntpServer2;
  1192. json["TZStr"] = confTime.timeZoneStr;
  1193. json["NTPSyncInt"] = confTime.ntpSyncInterval / 60;
  1194. yield();
  1195. char jsonchar[1000];
  1196. serializeJson(json, jsonchar);
  1197. httpServer.send(200, "application/json", jsonchar);
  1198. }
  1199. }); //httpServer.on /confDataTime
  1200. httpServer.on("/confDataLog", []() {
  1201. if (!httpIsAuthenticated())
  1202. return httpServer.requestAuthentication();
  1203. else
  1204. {
  1205. if (confLog.logWebRequests) httpServer_logWebRequest();
  1206. StaticJsonDocument<1000> json;
  1207. json["logLevSer"] = confLog.logLevelSerial;
  1208. json["logLevWeb"] = confLog.logLevelWeb;
  1209. json["logLevMqtt"] = confLog.logLevelMqtt;
  1210. if (confLog.logWebRequests)
  1211. json["logWebRequests"] = 1;
  1212. else
  1213. json["logWebRequests"] = 0;
  1214. yield();
  1215. char jsonchar[1000];
  1216. serializeJson(json, jsonchar);
  1217. httpServer.send(200, "application/json", jsonchar);
  1218. }
  1219. }); //httpServer.on /confDataLog
  1220. //get heap status, analog input value and all GPIO statuses in one json call
  1221. httpServer.on("/sysinfod", HTTP_GET, []() {
  1222. if (!httpIsAuthenticated())
  1223. return httpServer.requestAuthentication();
  1224. else
  1225. {
  1226. if (confLog.logWebRequests) httpServer_logWebRequest();
  1227. char buf[40];
  1228. byte mac[6];
  1229. WiFi.macAddress(mac);
  1230. StaticJsonDocument<1000> json;
  1231. json["DevName"] = confDevWiFi.deviceName;
  1232. json["HostName"] = confDevWiFi.hostName;
  1233. 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]);
  1234. json["MAC"] = buf;
  1235. json["IP"] = WiFi.localIP().toString();
  1236. json["GW"] = WiFi.gatewayIP().toString();
  1237. json["DNS"] = WiFi.dnsIP().toString();
  1238. json["SSID"] = WiFi.SSID();
  1239. json["WiFiConf"] = persWM.getActiveWiFiNum();
  1240. json["UpTime"] = getUptimeStr();
  1241. json["HeapFree"] = ESP.getFreeHeap();
  1242. json["HeapFragment"] = ESP.getHeapFragmentation();
  1243. json["HeapMaxBlock"] = ESP.getMaxFreeBlockSize();
  1244. json["ResetReason"] = ESP.getResetReason();
  1245. json["CoreVersion"] = ESP.getCoreVersion();
  1246. json["SDKVersion"] = ESP.getSdkVersion();
  1247. json["CPUfreq"] = ESP.getCpuFreqMHz();
  1248. json["SketchSize"] = ESP.getSketchSize();
  1249. json["FlashSize"] = ESP.getFlashChipRealSize();
  1250. mqtt_updateCurrentStateName();
  1251. json["mqtthost"] = confMqtt.mqtt_server;
  1252. json["mqttstate"] = mqttCurrentStateName;
  1253. json["mqttstatN"] = mqttclient.state();
  1254. if (mqtt_reconnects < 1) json["mqttreconn"] = mqtt_reconnects;
  1255. else json["mqttreconn"] = mqtt_reconnects - 1;
  1256. json["mqttTopIn"] = confMqtt.mqtt_topic_in;
  1257. json["mqttTopLog"] = mqtt_topic_log;
  1258. json["mqttTopOut"] = confMqtt.mqtt_topic_out;
  1259. sprintf(buf, "%s", PGMStr_FIRMWARE_NAME);
  1260. json["FWName"] = buf;
  1261. sprintf(buf, "%s", PGMStr_FIRMWARE_VERSION);
  1262. json["FWVer"] = buf;
  1263. sprintf(buf, "%s", PGMStr_FIRMWARE_COPYRIGHT);
  1264. json["FWCr"] = buf;
  1265. sprintf(buf, "%s", compile_date);
  1266. json["FWBuilt"] = buf;
  1267. #ifdef DEBUGMODE
  1268. json["FWDebug"] = "yes";
  1269. #else
  1270. json["FWDebug"] = "no";
  1271. #endif
  1272. #ifdef ENABLE_FEATURE_NTP_TIME
  1273. if (confTime.ntpEnable)
  1274. {
  1275. char buf[13];
  1276. updateTime();
  1277. if(lt.tm_year > 70) {
  1278. strftime(buf, sizeof(buf), "%H:%M", &lt);
  1279. json["Time"] = buf;
  1280. strftime(buf, sizeof(buf), "%d.%m.%Y", &lt);
  1281. json["Date"] = buf;
  1282. }
  1283. }
  1284. #endif
  1285. yield();
  1286. char jsonchar[1000];
  1287. serializeJson(json, jsonchar);
  1288. httpServer.send(200, "application/json", jsonchar);
  1289. }
  1290. }); //httpServer.on /sysinfod
  1291. httpServer.on("/sysinfo", HTTP_GET, []() {
  1292. if (!httpIsAuthenticated())
  1293. return httpServer.requestAuthentication();
  1294. else
  1295. {
  1296. if (confLog.logWebRequests) httpServer_logWebRequest();
  1297. httpServerHandlePage_sysInfo();
  1298. }
  1299. });
  1300. #ifdef ENABLE_FEATURE_FILESYSTEM_BROWSER
  1301. httpServer.on("/fs", HTTP_GET, []() {
  1302. if(confWeb.FSbrowser) {
  1303. if (!httpIsAuthenticatedAdmin())
  1304. return httpServer.requestAuthentication();
  1305. else
  1306. {
  1307. if (confLog.logWebRequests) httpServer_logWebRequest();
  1308. strcpy(httpServer_returnPage, "/fs"); // save return page to global var as couldnt get it to work via http header when using file upload
  1309. httpServerHandlePage_fsbrowser();
  1310. }
  1311. }
  1312. });
  1313. #endif
  1314. httpServer.on("/", []() {
  1315. String addr = httpServer.client().remoteIP().toString();
  1316. if (confLog.logWebRequests) httpServer_logWebRequest();
  1317. if (httpServer.hasArg("restart"))
  1318. {
  1319. if (httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()))
  1320. {
  1321. sendLog(F("WEB: /?restart"), LOGLEVEL_INFO);
  1322. httpServerHandlePage_restart();
  1323. //restart();
  1324. restart_delayed(2);
  1325. }
  1326. else
  1327. httpSendUnauthorized();
  1328. }
  1329. else if (httpServer.hasArg("mqttreconnect"))
  1330. {
  1331. if (httpIsAuthenticated() || (!httpIsAuthenticated() && httpCheckToken()))
  1332. {
  1333. sendLog(F("WEB: /?mqttreconnect"), LOGLEVEL_INFO);
  1334. mqttReconnect();
  1335. httpServer.sendHeader("Location", "/", true);
  1336. httpServer.send(303);
  1337. }
  1338. else
  1339. httpSendUnauthorized();
  1340. }
  1341. else if (httpServer.hasArg("clearconf"))
  1342. {
  1343. if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()))
  1344. {
  1345. sendLog(F("WEB: /?clearconf"), LOGLEVEL_INFO);
  1346. httpServerHandlePage_clearConf();
  1347. yield();
  1348. delay(5);
  1349. deleteConfig();
  1350. }
  1351. else
  1352. httpSendUnauthorized();
  1353. }
  1354. else if (httpServer.hasArg("clearwifi"))
  1355. {
  1356. if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()))
  1357. {
  1358. sendLog(F("WEB: /?clearwifi"), LOGLEVEL_INFO);
  1359. httpServerHandlePage_clearConf();
  1360. yield();
  1361. delay(5);
  1362. confClearWiFiCredentials();
  1363. }
  1364. else
  1365. httpSendUnauthorized();
  1366. }
  1367. else if (httpServer.hasArg("clearcreds"))
  1368. {
  1369. if (httpIsAuthenticatedAdmin() || (!httpIsAuthenticatedAdmin() && httpCheckToken()))
  1370. {
  1371. sendLog(F("WEB: /?clearcreds"), LOGLEVEL_INFO);
  1372. httpServerHandlePage_clearConf();
  1373. yield();
  1374. delay(5);
  1375. confClearCredentials();
  1376. }
  1377. else
  1378. httpSendUnauthorized();
  1379. }
  1380. else if (!httpIsAuthenticated())
  1381. return httpServer.requestAuthentication();
  1382. else
  1383. {
  1384. httpServerHandlePage_main();
  1385. }
  1386. });
  1387. httpServer.on("/conf", []() {
  1388. if (!httpIsAuthenticatedAdmin())
  1389. return httpServer.requestAuthentication();
  1390. else
  1391. {
  1392. if (confLog.logWebRequests) httpServer_logWebRequest();
  1393. httpServerHandlePage_admin();
  1394. }
  1395. });
  1396. httpServer.on("/confweb", []() {
  1397. if (!httpIsAuthenticatedAdmin())
  1398. return httpServer.requestAuthentication();
  1399. else
  1400. {
  1401. if (confLog.logWebRequests) httpServer_logWebRequest();
  1402. httpServerHandlePage_confWeb();
  1403. }
  1404. });
  1405. httpServer.on("/confMqtt", []() {
  1406. if (!httpIsAuthenticatedAdmin())
  1407. return httpServer.requestAuthentication();
  1408. else
  1409. {
  1410. if (confLog.logWebRequests) httpServer_logWebRequest();
  1411. httpServerHandlePage_confMqtt();
  1412. }
  1413. });
  1414. httpServer.on("/confDevWiFi", []() {
  1415. if (!httpIsAuthenticatedAdmin())
  1416. return httpServer.requestAuthentication();
  1417. else
  1418. {
  1419. if (confLog.logWebRequests) httpServer_logWebRequest();
  1420. httpServerHandlePage_confDevWiFi();
  1421. }
  1422. });
  1423. httpServer.on("/confSens", []() {
  1424. if (!httpIsAuthenticatedAdmin())
  1425. return httpServer.requestAuthentication();
  1426. else
  1427. {
  1428. if (confLog.logWebRequests) httpServer_logWebRequest();
  1429. httpServerHandlePage_confSens();
  1430. }
  1431. });
  1432. #ifdef FIRMWARE_VARIANT_THERMOSTAT
  1433. httpServer.on("/confTherm", []() {
  1434. if (!httpIsAuthenticatedAdmin())
  1435. return httpServer.requestAuthentication();
  1436. else
  1437. {
  1438. if (confLog.logWebRequests) httpServer_logWebRequest();
  1439. httpServerHandlePage_confTherm();
  1440. }
  1441. });
  1442. httpServer.on("/ThermRedTemps", []() {
  1443. if (!httpIsAuthenticatedAdmin())
  1444. return httpServer.requestAuthentication();
  1445. else
  1446. {
  1447. if (confLog.logWebRequests) httpServer_logWebRequest();
  1448. httpServerHandlePage_ThermRedTemps();
  1449. }
  1450. });
  1451. #endif
  1452. #ifdef FIRMWARE_VARIANT_HEATCONTROL
  1453. httpServer.on("/confHeatc", []() {
  1454. if (!httpIsAuthenticatedAdmin())
  1455. return httpServer.requestAuthentication();
  1456. else
  1457. {
  1458. if (confLog.logWebRequests) httpServer_logWebRequest();
  1459. httpServerHandlePage_confHeatc();
  1460. }
  1461. });
  1462. #endif
  1463. httpServer.on("/confAdd", []() {
  1464. if (!httpIsAuthenticatedAdmin())
  1465. return httpServer.requestAuthentication();
  1466. else
  1467. {
  1468. if (confLog.logWebRequests) httpServer_logWebRequest();
  1469. httpServerHandlePage_confAdd();
  1470. }
  1471. });
  1472. #ifdef ENABLE_FEATURE_NTP_TIME
  1473. httpServer.on("/confTime", []() {
  1474. if (!httpIsAuthenticatedAdmin())
  1475. return httpServer.requestAuthentication();
  1476. else
  1477. {
  1478. if (confLog.logWebRequests) httpServer_logWebRequest();
  1479. httpServerHandlePage_confTime();
  1480. }
  1481. });
  1482. #endif
  1483. httpServer.on("/confLog", []() {
  1484. if (!httpIsAuthenticatedAdmin())
  1485. return httpServer.requestAuthentication();
  1486. else
  1487. {
  1488. if (confLog.logWebRequests) httpServer_logWebRequest();
  1489. httpServerHandlePage_confLog();
  1490. }
  1491. });
  1492. #ifdef ENABLE_FEATURE_WSCONSOLE
  1493. if (confWeb.wsConsole)
  1494. {
  1495. httpServer.on("/wsconsole", []() {
  1496. if (!httpIsAuthenticatedAdmin())
  1497. return httpServer.requestAuthentication();
  1498. else
  1499. {
  1500. if (confLog.logWebRequests) httpServer_logWebRequest();
  1501. wsValidSessionId = millis();
  1502. char sidbuf[20];
  1503. sprintf(sidbuf, "sessionId=%lu|", wsValidSessionId);
  1504. httpServer.sendHeader("Set-Cookie", sidbuf);
  1505. httpServerHandlePage_WSConsole();
  1506. }
  1507. });
  1508. //httpServer.on("/wsapp.js", []() {
  1509. // httpServer.sendHeader("cache-control", "max-age=86400", false);
  1510. // httpServer.send_P(200, "text/javascript", js_wsapp);
  1511. //});
  1512. }
  1513. #endif
  1514. httpServer.onNotFound([]() {
  1515. String addr = httpServer.client().remoteIP().toString();
  1516. httpServerHandleNotFound();
  1517. }); //httpServer.onNotFound
  1518. #ifdef ENABLE_FEATURE_WEB_CONSOLE
  1519. if (confWeb.wConsole)
  1520. {
  1521. httpServer.on("/console", []() {
  1522. if (!httpIsAuthenticatedAdmin())
  1523. return httpServer.requestAuthentication();
  1524. else
  1525. {
  1526. if (confLog.logWebRequests) httpServer_logWebRequest();
  1527. httpServerHandlePage_console();
  1528. }
  1529. });
  1530. httpServer.on("/webcsapi", []() {
  1531. if (!httpIsAuthenticatedAdmin())
  1532. return httpServer.requestAuthentication();
  1533. else
  1534. {
  1535. if (httpServer.hasArg("cmd"))
  1536. {
  1537. char buf[101];
  1538. httpServer.arg("cmd").toCharArray(buf, 100);
  1539. strlcpy(cmdPayload, buf, sizeof(cmdPayload));
  1540. cmdInQueue = true;
  1541. evalCmd();
  1542. }
  1543. if (confLog.logWebRequests) httpServer_logWebRequest();
  1544. httpServer.send(200, "text/plain", webLogBuffer);
  1545. }
  1546. });
  1547. httpServer.on("/csapp.js", []() {
  1548. if (confLog.logWebRequests) httpServer_logWebRequest();
  1549. httpServer.sendHeader("cache-control", "max-age=86400", false);
  1550. httpServer.send_P(200, "text/javascript", js_csapp);
  1551. });
  1552. }
  1553. #endif
  1554. // HTTP Updater at /update
  1555. #ifdef ENABLE_FEATURE_HTTP_UPDATER
  1556. httpUpdater.setup(&httpServer, "/update", confSecrets.http_user, confSecrets.http_pass);
  1557. #endif
  1558. httpServer.begin();
  1559. } // httpServerInit()