Added relay control

master
David Zálešák 4 years ago
parent 1c4e8b18e7
commit 177c32fd0a

@ -75,13 +75,25 @@ void setup() {
//========== Web server setup ========== //========== Web server setup ==========
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ 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){ if(METRICS_EXPORT){
server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain; charset=utf-8", metrics); 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.onNotFound(notFound);
server.begin(); server.begin();

@ -3,5 +3,8 @@
#define DS18B20_PIN 0 #define DS18B20_PIN 0
#define RELAY_PIN 2 #define RELAY_PIN 2
#define METRICS_EXPORT 1 #define METRICS_EXPORT 1
#define THERMOSTAT 0
#define CORRECTION 0 #define CORRECTION 0