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

WiFi Thermostat







Current: ℃    %
Heating

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 *:

MQTT Server *:
MQTT Port *:
MQTT User *:
MQTT Password *:

In Topic *:
Out Topic:
Out Retain *:

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

Domoticz Out Topic *:

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

Extended configuration

Home


Domoticz

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

Outside Temp/Hum via MQTT

Temp In-Topic:
Hum In-Topic:

Auto-Save

setTemp:
Mode:

Thermostat / Heating

Min. Off-Time:
Min. Temp:
Max. Temp:
Reduction Mode Temp:
Hysteresis:
Temp Correction.:
Hum Correction:

Intervals / Timeouts

Measure Interval:
Display Interval:
Display Timeout:

)"; 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", []() { DEBUG_PRINT("httpServer.on /api"); if (httpServer.hasArg("plusBtn")) { plusButtonAction(); DEBUG_PRINT(P("web plusBtn")); } //if if (httpServer.hasArg("minusBtn")) { minusButtonAction(); DEBUG_PRINT(P("web minusBtn")); } //if if (httpServer.hasArg("modeBtn")) { modeButtonAction(); DEBUG_PRINT(P("web modeBtn")); } //if if (httpServer.hasArg("onoffBtn")) { modeButtonHoldAction(); DEBUG_PRINT(P("web onoffBtn")); } //if //build json object of program data StaticJsonBuffer<200> jsonBuffer; JsonObject &json = jsonBuffer.createObject(); json["devname"] = deviceName; json["ssid"] = WiFi.SSID(); json["setTemp"] = setTemp; json["temp"] = currTemp; json["hum"] = int(currHum); json["mode"] = heatingMode; json["heating"] = turnHeatingOn; char jsonchar[200]; json.printTo(jsonchar); //print to char array, takes more memory but sends in one piece httpServer.send(200, "application/json", jsonchar); }); //httpServer.on /api httpServer.on("/restart", []() { Serial.println("web triggered restart"); ESP.restart(); }); httpServer.on("/confdata", []() { boolean sendData = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); sendData = true; } else sendData = true; if (sendData) { 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["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["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); } }); //httpServer.on /confdata httpServer.on("/confdata2", []() { boolean sendData = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); sendData = true; } else sendData = true; if (sendData) { 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["domIdxPIR"] = domoticzIdx_PIR; json["outTempTop"] = outTemp_topic_in; json["outHumTop"] = outHum_topic_in; json["autoSaveTemp"] = autoSaveSetTemp; json["autoSaveMode"] = autoSaveHeatingMode; json["minOffTime"] = heatingMinOffTime; json["tempMin"] = setTempMin; json["tempMax"] = setTempMax; json["tempLow"] = setTempLow; json["hyst"] = hysteresis; json["tempCorr"] = tempCorrVal; json["humCorr"] = humCorrVal; json["measInt"] = measureInterval; json["dispInt"] = displayInterval; json["dispTout"] = displayTimeout; 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); } }); //httpServer.on /confdata2 //get heap status, analog input value and all GPIO statuses in one json call httpServer.on("/info", HTTP_GET, []() { boolean sendData = false; if (strlen(http_user) > 0 && strlen(http_pass) > 0) { if (!httpServer.authenticate(http_user, http_pass)) return httpServer.requestAuthentication(); sendData = true; } else sendData = true; if (sendData) { String json = " {"; json += "\"wifissid\":\"" + WiFi.SSID() + "\""; json += "\"heap\":" + String(ESP.getFreeHeap()); json += "}"; httpServer.send(200, "text/json", json); json = String(); } }); //httpServer.on /info httpServer.on("/", []() { httpServerHandleRoot(); }); httpServer.on("/conf", []() { httpServerHandleConfPage(); }); httpServer.on("/conf2", []() { httpServerHandleConf2Page(); }); httpServer.onNotFound([]() { httpServerHandleNotFound(); }); //httpServer.onNotFound // HTTP Updater at /update httpUpdater.setup(&httpServer); httpServer.begin(); }