diff --git a/ESPtermostat.ino b/ESPtermostat.ino index 172710c..8d7a27c 100644 --- a/ESPtermostat.ino +++ b/ESPtermostat.ino @@ -83,31 +83,39 @@ void setup() { } server.on("/set", HTTP_GET, [](AsyncWebServerRequest *request){ //nutno nastavit maxima a minima + + String repply; + if(THERMOSTAT){ if (request->hasParam("increasereqtemp")) { reqTemp += request->getParam("increasereqtemp")->value().toFloat(); - request->send(200, "text/plain; charset=utf-8", String(reqTemp)); + repply = String(reqTemp); }else if (request->hasParam("decreasereqtemp")) { reqTemp -= request->getParam("decreasereqtemp")->value().toFloat(); - request->send(200, "text/plain; charset=utf-8", String(reqTemp)); + repply = String(reqTemp); }else if (request->hasParam("increaseoffset")) { offset += request->getParam("increaseoffset")->value().toFloat(); - request->send(200, "text/plain; charset=utf-8", String(offset)); + repply = String(offset); }else if (request->hasParam("decreaseoffset")) { offset -= request->getParam("decreaseoffset")->value().toFloat(); - request->send(200, "text/plain; charset=utf-8", String(offset)); + repply = String(offset); }else{ - request->send(200, "text/plain; charset=utf-8", "no known parameter"); + repply = "no known parameter"; } }else{ if (request->hasParam("relay")) { boolean state = request->getParam("relay")->value() == "1"; digitalWrite(RELAY_PIN, state); - request->send(200, "text/plain; charset=utf-8", "success"); + repply = "success"; }else{ - request->send(200, "text/plain; charset=utf-8", "no known parameter"); + repply = "no known parameter"; } } + + AsyncWebServerResponse *response = request->beginResponse(200, "text/plain; charset=utf-8", repply); + response->addHeader("Access-Control-Allow-Origin", "*"); + request->send(response); + //request->send(200, "text/plain; charset=utf-8", repply); }); server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request){ //nutno vyřešit dotazy na více parametrů najednou @@ -124,8 +132,11 @@ void setup() { }else{ repply = "no known parameter"; } - - request->send(200, "text/plain; charset=utf-8", repply); + + AsyncWebServerResponse *response = request->beginResponse(200, "text/plain; charset=utf-8", repply); + response->addHeader("Access-Control-Allow-Origin", "*"); + request->send(response); + //request->send(200, "text/plain; charset=utf-8", repply); }); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain; charset=utf-8", "ESP termostat, tady se bude posílat aplikace z flash paměti"); diff --git a/jsapp/img/topi.svg b/jsapp/img/topi.svg new file mode 100644 index 0000000..01b0f03 --- /dev/null +++ b/jsapp/img/topi.svg @@ -0,0 +1,60 @@ + + diff --git a/jsapp/index.html b/jsapp/index.html index 7b8292a..1290a3e 100644 --- a/jsapp/index.html +++ b/jsapp/index.html @@ -19,30 +19,105 @@