|
|
@ -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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(API){
|
|
|
|
request->send(200, "text/plain; charset=utf-8", repply);
|
|
|
|
server.on("/set", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
});
|
|
|
|
//nutno nastavit maxima a minima
|
|
|
|
server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
|
|
|
|
//nutno vyřešit dotazy na více parametrů najednou
|
|
|
|
String repply;
|
|
|
|
String repply;
|
|
|
|
|
|
|
|
|
|
|
|
if(THERMOSTAT){
|
|
|
|
if(request->hasParam("temp")) {
|
|
|
|
if (request->hasParam("increasereqtemp")) {
|
|
|
|
repply = temperature;
|
|
|
|
reqTemp += request->getParam("increasereqtemp")->value().toFloat();
|
|
|
|
}else if(request->hasParam("relay")){
|
|
|
|
repply = String(reqTemp);
|
|
|
|
repply = !digitalRead(RELAY_PIN);
|
|
|
|
}else if (request->hasParam("decreasereqtemp")) {
|
|
|
|
}else if(THERMOSTAT && request->hasParam("reqtemp")){
|
|
|
|
reqTemp -= request->getParam("decreasereqtemp")->value().toFloat();
|
|
|
|
repply = reqTemp;
|
|
|
|
repply = String(reqTemp);
|
|
|
|
}else if(THERMOSTAT && request->hasParam("offset")) {
|
|
|
|
}else if (request->hasParam("increaseoffset")) {
|
|
|
|
repply = offset;
|
|
|
|
offset += request->getParam("increaseoffset")->value().toFloat();
|
|
|
|
}else{
|
|
|
|
repply = String(offset);
|
|
|
|
repply = "unknown parameter";
|
|
|
|
}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";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(API && WEBAPP){
|
|
|
|
|
|
|
|
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|