Код: Выделить всё
/*
Modul Algoritm
part of Arduino Mega Server project
*/
/* значение по которому ведется регулирование
в примере это значени будет задаваться вручную с web
*/
// mode режим
// 0 - ручной
// 1 - по значению датчика
// 2 - по времени
// 3 - not defined and not contXstatus
byte rele1mode = 0;
/* значения максимальных и минимальых значений для включения
и выключения RELE1
*/
int value_on = 100;
int value_off = 0;
int value_web = 0;
/* время включения по умолчанию /часы, минуты/
* при необходимости можно добавить секунды
*/
int r1hour_on = 19; int r1minute_on = 00;
int r1hour_off = 19; int r1minute_off = 15;
void Regul(){
if (rele1state == 0&&rele1mode == 0&&value_web == 1){
timeStamp();
rele1state = 1;
MessText = "Выход D32. Включение с Веб";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command ON to Web");
// #endif
} else{};
if (rele1state == 1&&rele1mode == 0&&value_web == 0){
timeStamp();
rele1state = 0;
MessText = "Выход D32. Отключение с Веб";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command ON to Web");
// #endif
} else{};
if (rele1state == 0&&rele1mode == 2&&r1hour_on == int (hour())&&r1minute_on == int (minute())){
timeStamp();
rele1state = 1;
MessText = "Выход D32. Включение по времени";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command ON to time");
// #endif
} else{};
if (rele1state == 1&&rele1mode == 2&&r1hour_off == int (hour())&&r1minute_off == int (minute())){
timeStamp();
rele1state = 0;
MessText = "Выход D32. Отключение по времени";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command OFF to time");
// #endif
} else {};
//if (!rele1state && rele1mode == 1 && dht11_h >= value_on){
//if (!rele1state && rele1mode == 1 && dht.readHumidity() > value_on){
if (!rele1state == 1 && rele1mode == 1 && analogRead(A0) > value_on){
digitalWrite(rele1pin, HIGH);
timeStamp();
rele1state = 1;
MessText = "Выход D32. Включение по датчику влажности";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command ON to HUM ");
// #endif
} //if
//if (rele1state && rele1mode == 1 && dht11_h < value_off){
//if (!rele1state && rele1mode == 1 && dht.readHumidity() < value_off){
if (rele1state == 1 && rele1mode == 1 && analogRead(A0) < value_off){
digitalWrite(rele1pin, LOW);
timeStamp();
rele1state = 0;
MessText = "Выход D32. Выключение по датчику влажности";
MessLoger(String (MessText), String (Info));
// #ifdef SERIAL_PRINT
Serial.println("Out D32. command OFF to HUM ");
// #endif
} // if
} // void regul
Код: Выделить всё
else if (StrContains(HTTP_req, "request_regulset")){sendXmlAnswer(cl); setRegul(); responseRegulset(cl);}
else if (StrContains(HTTP_req, "request_regulval")){sendXmlAnswer(cl); valRegul(); responseRegulval(cl);}
Код: Выделить всё
// Make Response
void valRegul(){
if (StrContains(HTTP_req, "RELE1=1")){value_web = 1;}
else if (StrContains(HTTP_req, "RELE1=0")){value_web = 0;}
}
void setRegul(){
byte pos1;
float pos2;
String commandStr;
if (StrContains(HTTP_req, "r1mode=")) {
pos1 = request.indexOf("r1mode=") + 7;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
rele1mode = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1hon=")) {
pos1 = request.indexOf("r1hon=") + 6;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
r1hour_on = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1mon=")) {
pos1 = request.indexOf("r1mon=") + 6;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
r1minute_on = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1hoff=")) {
pos1 = request.indexOf("r1hoff=") + 7;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
r1hour_off = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1moff=")) {
pos1 = request.indexOf("r1moff=") + 7;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
r1minute_off = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1valon=")) {
pos1 = request.indexOf("r1valon=") + 8;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
value_on = commandStr.toFloat();}
if (StrContains(HTTP_req, "r1valoff=")) {
pos1 = request.indexOf("r1valoff=") + 9;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
value_off = commandStr.toFloat();}
if (StrContains(HTTP_req, "value=")) {
pos1 = request.indexOf("value=") + 6;
pos2 = request.indexOf("&", pos1);
commandStr = request.substring(pos1, pos2);
dht11_h = commandStr.toFloat();}
}
void responseRegulset(EthernetClient cl) {
String s = tagXmlVersion();
s += openInputs();
s += makeTag("r1mode", "", String(rele1mode));
s += makeTag("D", String(rele1pin), String(rele1state));
s += makeTag("r1hon", "", String(r1hour_on));
s += makeTag("r1mon", "", String(r1minute_on));
s += makeTag("r1hoff", "", String(r1hour_off));
s += makeTag("r1moff", "", String(r1minute_off));
s += makeTag("r1valon", "", String(value_on));
s += makeTag("r1valoff", "", String(value_off));
s += makeTag("value", "", String(dht.readHumidity())); // Тут привязка по датчику DHT11
s += closeInputs();
cl.println(s);
}
void responseRegulval(EthernetClient cl) {
String s = tagXmlVersion();
s += openInputs();
s += makeTag("r1mode", "", String(rele1mode));
s += makeTag("D", String(rele1pin), String(rele1state));
s += makeTag("value", "", String(dht11_h));
s += closeInputs();
cl.println(s);
}