Pridani prepinacu funkci

master
David Zálešák 2 years ago
parent 809282ecd9
commit 83d53f328c

@ -79,68 +79,72 @@ void setup() {
//========== Web server setup ========== //========== Web server setup ==========
if(METRICS_EXPORT){ if(METRICS_EXPORT || API){
server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){ if(METRICS_EXPORT){
request->send(200, "text/plain; charset=utf-8", metrics); server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){
}); request->send(200, "text/plain; charset=utf-8", metrics);
} });
server.on("/set", HTTP_GET, [](AsyncWebServerRequest *request){ }
//nutno nastavit maxima a minima if(API){
server.on("/set", HTTP_GET, [](AsyncWebServerRequest *request){
String repply; //nutno nastavit maxima a minima
String repply;
if(THERMOSTAT){
if (request->hasParam("increasereqtemp")) {
reqTemp += request->getParam("increasereqtemp")->value().toFloat();
repply = String(reqTemp);
}else if (request->hasParam("decreasereqtemp")) {
reqTemp -= request->getParam("decreasereqtemp")->value().toFloat();
repply = String(reqTemp);
}else if (request->hasParam("increaseoffset")) {
offset += request->getParam("increaseoffset")->value().toFloat();
repply = String(offset);
}else if (request->hasParam("decreaseoffset")) {
offset -= request->getParam("decreaseoffset")->value().toFloat();
repply = String(offset);
}else{
repply = "unknown parameter";
}
}else{
if (request->hasParam("relay")) {
boolean state = request->getParam("relay")->value() == "0";
digitalWrite(RELAY_PIN, state);
repply = "success";
}else{
repply = "unknown parameter";
}
}
if(THERMOSTAT){ request->send(200, "text/plain; charset=utf-8", repply);
if (request->hasParam("increasereqtemp")) { });
reqTemp += request->getParam("increasereqtemp")->value().toFloat(); server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request){
repply = String(reqTemp); //nutno vyřešit dotazy na více parametrů najednou
}else if (request->hasParam("decreasereqtemp")) { String repply;
reqTemp -= request->getParam("decreasereqtemp")->value().toFloat();
repply = String(reqTemp); if(request->hasParam("temp")) {
}else if (request->hasParam("increaseoffset")) { repply = temperature;
offset += request->getParam("increaseoffset")->value().toFloat(); }else if(request->hasParam("relay")){
repply = String(offset); repply = !digitalRead(RELAY_PIN);
}else if (request->hasParam("decreaseoffset")) { }else if(THERMOSTAT && request->hasParam("reqtemp")){
offset -= request->getParam("decreaseoffset")->value().toFloat(); repply = reqTemp;
repply = String(offset); }else if(THERMOSTAT && request->hasParam("offset")) {
}else{ repply = offset;
repply = "unknown parameter"; }else{
} repply = "unknown parameter";
}else{ }
if (request->hasParam("relay")) {
boolean state = request->getParam("relay")->value() == "0"; request->send(200, "text/plain; charset=utf-8", repply);
digitalWrite(RELAY_PIN, state); });
repply = "success";
}else{
repply = "unknown parameter";
}
} }
if(API && WEBAPP){
request->send(200, "text/plain; charset=utf-8", repply); server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
});
server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request){
//nutno vyřešit dotazy na více parametrů najednou
String repply;
if(request->hasParam("temp")) {
repply = temperature;
}else if(request->hasParam("relay")){
repply = !digitalRead(RELAY_PIN);
}else if(THERMOSTAT && request->hasParam("reqtemp")){
repply = reqTemp;
}else if(THERMOSTAT && request->hasParam("offset")) {
repply = offset;
}else{
repply = "unknown parameter";
} }
request->send(200, "text/plain; charset=utf-8", repply); server.onNotFound(notFound);
}); server.begin();
}
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
server.onNotFound(notFound);
server.begin();
//================================= //=================================
} }
@ -168,8 +172,8 @@ void readSensor() {
// read the actual temperature after it's been converted // read the actual temperature after it's been converted
temperature = sensor.getTempCByIndex(0) + CORRECTION; temperature = sensor.getTempCByIndex(0) + CORRECTION;
// do what you need with the temperature here // do what you need with the temperature here
metrics = "temp "; metrics = "temp ";
metrics += temperature; metrics += temperature;
} }
void startConversion() { void startConversion() {

@ -2,9 +2,13 @@
#define STAPSK "heslo" #define STAPSK "heslo"
#define DS18B20_PIN 0 #define DS18B20_PIN 0
//jak zacházet s více čidly?
#define CORRECTION 0
#define RELAY_PIN 2 #define RELAY_PIN 2
#define METRICS_EXPORT 1 #define METRICS_EXPORT 1
#define THERMOSTAT 0 #define API 1
#define WEBAPP 1
#define CORRECTION 0 #define THERMOSTAT 1