|
|
|
@ -79,68 +79,72 @@ void setup() {
|
|
|
|
|
|
|
|
|
|
//========== Web server setup ==========
|
|
|
|
|
|
|
|
|
|
if(METRICS_EXPORT){
|
|
|
|
|
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(METRICS_EXPORT || API){
|
|
|
|
|
if(METRICS_EXPORT){
|
|
|
|
|
server.on("/metrics", HTTP_GET, [](AsyncWebServerRequest *request){
|
|
|
|
|
request->send(200, "text/plain; charset=utf-8", metrics);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if(API){
|
|
|
|
|
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(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";
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
if(API && WEBAPP){
|
|
|
|
|
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request->send(200, "text/plain; charset=utf-8", repply);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
|
|
|
|
|
|
|
|
|
server.onNotFound(notFound);
|
|
|
|
|
server.begin();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.onNotFound(notFound);
|
|
|
|
|
server.begin();
|
|
|
|
|
}
|
|
|
|
|
//=================================
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -168,8 +172,8 @@ void readSensor() {
|
|
|
|
|
// read the actual temperature after it's been converted
|
|
|
|
|
temperature = sensor.getTempCByIndex(0) + CORRECTION;
|
|
|
|
|
// do what you need with the temperature here
|
|
|
|
|
metrics = "temp ";
|
|
|
|
|
metrics += temperature;
|
|
|
|
|
metrics = "temp ";
|
|
|
|
|
metrics += temperature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startConversion() {
|
|
|
|
|