//extern ESP8266WebServer httpServer; static const char httpRoot[] PROGMEM = R"(

WiFi Thermostat



Curr.setTemp:

Preset:


Mode:


Current Temp/Hum: ℃    %

heating currently

WiFi connected to .
Last update seconds ago.

WiFi settings
Base configuration
Extended configuration
Firmware update
Restart )"; static const char httpConfPage[] PROGMEM = R"(

Base configuration

Home



Device Name:

HTTP User *:
HTTP Password *:

HTTP set token:
MQTT Server *:
MQTT Port *:
MQTT User *:
MQTT Password *:

In Topic *:
Out Topic:
Out Retain *:

LastWill Topic *:
LastWill Qos *:
LastWill Retain *:
LastWill Message *:

Connect Message *:

Domoticz Out Topic *:

)"; static const char httpConf2Page[] PROGMEM = R"(

Extended configuration

Home


Domoticz

Idx setTemp:
Idx mode:
Idx TempHum Sensor:
Idx Heating:
Idx PIR:

Outside Temp/Hum via MQTT

Temp In-Topic:
Hum In-Topic:

Additional MQTT publish topics

PIR sensor:

Auto-Save

setTemp:
mode/preset:

Thermostat / Heating

Min. Off-Time:
Min. Temp:
Max. Temp:
Reduction Mode Temp:
Reduction Mode 2 Temp:
set temp decrease value:
Hysteresis:
Temp Correction.:
Hum Correction:

Intervals / Timeouts

Measure Interval:
Display Interval:
Display Timeout:

Names

used in MQTT status/commands and HTTP interface
max. 13 chars!
Off-Message:
Temp Labels
Inside:
Outside:
* 1 char
Mode
Off:
On:

Presets:
Normal*:
Reduction 1:
Reduction 2:
* will always send/receive "none" as hardcoded in Home Assistant.

Misc

PIR enables Display:
toggling I/A-Temp and Hum display*:
* otherwise fixed I/A-Temp


)"; void httpServerHandleRoot() { httpServer.send_P(200, "text/html", httpRoot); } void httpServerHandleConfPage() { httpServer.send_P(200, "text/html", httpConfPage); } void httpServerHandleConf2Page() { httpServer.send_P(200, "text/html", httpConf2Page); } //void httpServerHandleNotFound() { // String message = "File Not Found\n\n"; // message += "URI: "; // message += httpServer.uri(); // message += "\nMethod: "; // message += (httpServer.method() == HTTP_GET) ? "GET" : "POST"; // message += "\nArguments: "; // message += httpServer.args(); // message += "\n"; // for (uint8_t i = 0; i < httpServer.args(); i++) { // message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n"; // } // httpServer.send(404, "text / plain", message); //} void httpServerHandleNotFound() { // if (strlen(http_user) > 0 && strlen(http_pass) > 0) { // if (!httpServer.authenticate(http_user, http_pass)) // return httpServer.requestAuthentication(); httpServer.send(404, "text/plain", ""); //} } void httpServerInit() { httpServer.on("/delconf", []() { Serial.println("httpServer.on /delconf"); if (httpServer.hasArg("token")) { char buf[20]; httpServer.arg("token").toCharArray(buf, 20); if (strcmp(buf, CLEARCONF_TOKEN) == 0) { // httpServer.send(200, "text / plain", "Token OK - deleting config"); deleteConfig(); } } //if // else { // httpServer.send(200, "text / plain", "not allowed"); // } }); httpServer.on("/api", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { DEBUG_PRINT("httpServer.on /api"); if (httpServer.hasArg("plusBtn")) { setTempStepUp(); DEBUG_PRINT(P("web plusBtn")); } //if if (httpServer.hasArg("minusBtn")) { setTempStepDown(); DEBUG_PRINT(P("web minusBtn")); } //if if (httpServer.hasArg("pset0Btn")) { setPresetTo(0); DEBUG_PRINT(P("web pset0Btn")); } //if if (httpServer.hasArg("pset1Btn")) { setPresetTo(1); DEBUG_PRINT(P("web pset1Btn")); } //if if (httpServer.hasArg("pset2Btn")) { setPresetTo(2); DEBUG_PRINT(P("web pset2Btn")); } //if if (httpServer.hasArg("onBtn")) { setHeatingmodeTo(1); DEBUG_PRINT(P("web onBtn")); } //if if (httpServer.hasArg("offBtn")) { setHeatingmodeTo(0); DEBUG_PRINT(P("web offBtn")); } //if //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 StaticJsonBuffer<400> jsonBuffer; JsonObject &json = jsonBuffer.createObject(); json["devname"] = deviceName; json["ssid"] = WiFi.SSID(); json["setTemp"] = setTemp; json["currSetTemp"] = currSetTemp; json["temp"] = currTemp; json["hum"] = int(currHum); json["heating"] = turnHeatingOn; json["mode"] = heatingMode; json["modeName"] = currentModeName; json["pset"] = preset; json["psetName"] = currentPresetName; json["psetName0"] = psetname0; json["psetName1"] = psetname1; json["psetName2"] = psetname2; char jsonchar[400]; json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece httpServer.send(200, "application/json", jsonchar); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); //httpServer.on /api httpServer.on("/restart", []() { if (httpServer.hasArg("token")) { Serial.println("web triggered restart"); ESP.restart(); } else { httpServer.send (403, "text/plain", "FORBIDDEN"); } }); httpServer.on("/mqttReconnect", []() { if (httpServer.hasArg("token")) { Serial.println("web triggered mqttReconnect"); mqttReconnect(); httpServer.sendHeader("Location", String("/"), true); httpServer.send (302, "text/plain", "OK"); } else { httpServer.send (403, "text/plain", "FORBIDDEN"); } }); httpServer.on("/setPoint", []() { if (httpServer.hasArg("token")) { char buf[20]; httpServer.arg("token").toCharArray(buf, 20); if (strcmp(buf, http_token) == 0) { Serial.println("web triggered setPoint"); if (httpServer.hasArg("value")) { char bufVal[20]; httpServer.arg("value").toCharArray(bufVal, 20); float valueFloat = round(atof(bufVal) * 2.0) / 2.0; setTempTo(valueFloat); httpServer.send (200, "text/plain", "OK"); } } } //if else { httpServer.send (403, "text/plain", "FORBIDDEN"); } }); httpServer.on("/setMode", []() { if (httpServer.hasArg("token")) { char buf[20]; httpServer.arg("token").toCharArray(buf, 20); if (strcmp(buf, http_token) == 0) { Serial.println("web triggered setMode"); if (httpServer.hasArg("value")) { char bufVal[20]; httpServer.arg("value").toCharArray(bufVal, 20); int valueInt = atoi(bufVal); if (valueInt >= 0 && valueInt <= 1) setHeatingmodeTo(valueInt); httpServer.send (200, "text/plain", "OK"); } } } //if else { httpServer.send (403, "text/plain", "FORBIDDEN"); } }); httpServer.on("/setPreset", []() { if (httpServer.hasArg("token")) { char buf[20]; httpServer.arg("token").toCharArray(buf, 20); if (strcmp(buf, http_token) == 0) { Serial.println("web triggered setPreset"); if (httpServer.hasArg("value")) { char bufVal[20]; httpServer.arg("value").toCharArray(bufVal, 20); int valueInt = atoi(bufVal); if (valueInt >= 0 && valueInt <= 2) setPresetTo(valueInt); httpServer.send (200, "text/plain", "OK"); } } } //if else { httpServer.send (403, "text/plain", "FORBIDDEN"); } }); httpServer.on("/confdata", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { Serial.println("httpServer.on /confdata"); 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 StaticJsonBuffer<1000> jsonBuffer; JsonObject &json = jsonBuffer.createObject(); json["devName"] = deviceName; json["httpUser"] = http_user; json["httpPass"] = http_pass; json["httpToken"] = http_token; json["mqttHost"] = mqtt_server; json["mqttPort"] = mqtt_port; json["mqttUser"] = mqtt_user; json["mqttPass"] = mqtt_pass; json["inTop"] = mqtt_topic_in; json["outTop"] = mqtt_topic_out; json["outRet"] = mqtt_outRetain; json["willTop"] = mqtt_willTopic; json["willQos"] = mqtt_willQos; json["willRet"] = mqtt_willRetain; json["willMsg"] = mqtt_willMsg; json["connMsg"] = mqtt_connMsg; json["domOutTop"] = domoticz_out_topic; yield(); char jsonchar[1000]; json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece httpServer.send(200, "application/json", jsonchar); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); //httpServer.on /confdata httpServer.on("/confdata2", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { Serial.println("httpServer.on /confdata2"); 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 StaticJsonBuffer<1000> jsonBuffer; JsonObject &json = jsonBuffer.createObject(); json["domIdxTherm"] = domoticzIdx_Thermostat; json["domIdxMode"] = domoticzIdx_ThermostatMode; json["domIdxTempHum"] = domoticzIdx_TempHumSensor; json["domIdxHeating"] = domoticzIdx_Heating; json["domIdxPIR"] = domoticzIdx_PIR; json["outTempTop"] = outTemp_topic_in; json["outHumTop"] = outHum_topic_in; json["PIRTop"] = mqtt_topic_pir; json["autoSaveTemp"] = autoSaveSetTemp; json["autoSaveMode"] = autoSaveHeatingMode; json["minOffTime"] = heatingMinOffTime; json["tempMin"] = setTempMin; json["tempMax"] = setTempMax; json["tempLow"] = setTempLow; json["tempLow2"] = setTempLow2; json["tempDec"] = setTempDecreaseVal; json["hyst"] = hysteresis; json["tempCorr"] = tempCorrVal; json["humCorr"] = humCorrVal; json["measInt"] = measureInterval; json["dispInt"] = displayInterval; json["dispTout"] = displayTimeout; json["offMsg"] = offMessage; json["modename0"] = modename0; json["modename1"] = modename1; json["psetname0"] = psetname0; json["psetname1"] = psetname1; json["psetname2"] = psetname2; json["itemplab"] = itemplab; json["otemplab"] = otemplab; json["PIRenDisp"] = PIR_enablesDisplay; json["togTHdisp"] = togglingTempHumAIDisplay; yield(); char jsonchar[1000]; json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece httpServer.send(200, "application/json", jsonchar); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); //httpServer.on /confdata2 //get heap status, analog input value and all GPIO statuses in one json call httpServer.on("/info", HTTP_GET, []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { String json = " {"; json += "\"wifissid\":\"" + WiFi.SSID() + "\""; json += "\"heap\":" + String(ESP.getFreeHeap()); json += "}"; httpServer.send(200, "text/json", json); json = String(); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); //httpServer.on /info httpServer.on("/", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { httpServerHandleRoot(); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); httpServer.on("/conf", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { httpServerHandleConfPage(); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); httpServer.on("/conf2", []() { boolean isAuthenticated = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); isAuthenticated = true; } else isAuthenticated = true; if (isAuthenticated) { httpServerHandleConf2Page(); } else { httpServer.send (401, "text/plain", "UNAUTHORIZED"); } }); httpServer.onNotFound([]() { httpServerHandleNotFound(); }); //httpServer.onNotFound // HTTP Updater at /update httpUpdater.setup(&httpServer); httpServer.begin(); }