Код:
void setup(void){
pinMode(HeaterPin, OUTPUT); // выход управления нагрузкой
t.begin();
t.setResolution(10); // 10 бит
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
while(WiFi.status() != WL_CONNECTED){delay(500); Serial.print(".");}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", [](){web();});
server.on("/obn", [](){web();});
//server.on("/update", [](){web_upd();});
server.on("/reg+", [](){reg_t++;web();});
server.on("/reg-", [](){reg_t--;web();});
server.on("/reg+10", [](){reg_t=reg_t+10;web();});
server.on("/reg-10", [](){reg_t=reg_t-10;web();});
httpUpdater.setup(&server);
server.begin();
Serial.println("HTTP server started");
}
//------------------------------------------------------------------------
void loop(void){
server.handleClient();
t.requestTemperatures();
temper = t.getTempCByIndex(0);
if(reg_t<=0) {reg_t=0;}
if(reg_t>=125){reg_t=125;}
if(reg_t >= temper + gis){digitalWrite(HeaterPin,HIGH);ind="ВКЛ"; OUT=true;}
if(reg_t <= temper - gis){digitalWrite(HeaterPin,LOW); ind="ВЫКЛ";OUT=false;}
yield();
}
//------------------------------------------------------------------------
void web(){
String webPage = "<!DOCTYPE HTML><html>";
webPage += "<meta charset='utf-8'><meta name='viewport' content='width=540, user-scalable=no' />";
webPage += "<style>table {background-color:#F5F5F5;border-radius: 5px;}</style>";
webPage += "<TABLE align='center' width='520' BORDER='1' cellspacing='0' cellpadding='5'><tr><td colspan='3' bgcolor='#006400' align='center'>";
webPage += "<font color='#FFFFFF'><h2>Терморегулятор 0...125 °C</font></td></tr></h2>";
webPage += "<meta http-equiv='Refresh' content='5; URL=/obn' />"; // автоматическое обновление страницы каждые 5 секунд
webPage += "<tr><td>Температура</td><td align='center'><a href=\"obn\"><button>Обновить</button></a></td><td bgcolor='#FFFFFF' align='center'><big><b>";
webPage += temper;
webPage += " °C</b></big></td></tr>";
webPage += "<tr><td>Регулировка температуры</td><td align='center'><a href=\"reg+\"><button>+1 </button>";
webPage += "</a><a href=\"reg-\"><button>-1 </button></a><br><a href=\"reg+10\"><button>+10</button></a>";
webPage += "<a href=\"reg-10\"><button>-10</button></a></td><td bgcolor='#FFFFFF' align='center'><big><b>";
webPage += reg_t;
webPage += " °C</b></big></td></tr>";
webPage += "<tr><td colspan='2'>Нагрев</td>";
if(OUT){webPage +="<td align='center' bgcolor='#50FF50'><big><b>";}
else {webPage +="<td align='center' bgcolor='#FF5050'><big><b>";}
webPage += ind;
webPage += "</b></big></td></tr></html>";
webPage += "<tr><td align='center'>Обновление прошивки</td><td align='center'colspan='2'><a href=\"update\"><button>Обновить</button></a></td></tr></html>";
server.send(200, "text/html", webPage);
delay(300);
}
//-----------------------------------------------------
//void web_upd(){
// if(!UPDATE){
// httpUpdater.setup(&server);
// Serial.print("WiFi.localIP: ");
// Serial.println(WiFi.localIP());
// Serial.println("HTTP UpdateServer started");
// yield();
// UPDATE = true;}
//}