From 177c32fd0affe6ab9274a584db58c3c9cc7c7042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Fri, 23 Apr 2021 01:41:46 +0200 Subject: [PATCH] Added relay control --- ESPtermostat.ino | 14 +++++++++++++- config.h.example | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ESPtermostat.ino b/ESPtermostat.ino index 7eb014b..e092502 100644 --- a/ESPtermostat.ino +++ b/ESPtermostat.ino @@ -75,13 +75,25 @@ void setup() { //========== Web server setup ========== server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(200, "text/plain", "ESP termostat, tady se bude posílat aplikace z flash paměti"); + request->send(200, "text/plain; charset=utf-8", "ESP termostat, tady se bude posílat aplikace z flash paměti"); }); if(METRICS_EXPORT){ server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain; charset=utf-8", metrics); }); } + if(METRICS_EXPORT && !THERMOSTAT){ + server.on("/relay", HTTP_GET, [](AsyncWebServerRequest *request){ + boolean state; + if (request->hasParam("set")) { + state = request->getParam("set")->value() == "1"; + digitalWrite(RELAY_PIN, state); + request->send(200, "text/plain; charset=utf-8", "success"); + }else{ + request->send(200, "text/plain; charset=utf-8", String(digitalRead(RELAY_PIN))); + } + }); + } server.onNotFound(notFound); server.begin(); diff --git a/config.h.example b/config.h.example index ad53426..c821bb1 100644 --- a/config.h.example +++ b/config.h.example @@ -3,5 +3,8 @@ #define DS18B20_PIN 0 #define RELAY_PIN 2 + #define METRICS_EXPORT 1 +#define THERMOSTAT 0 + #define CORRECTION 0