// Library
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
WiFiServer server(80);
int Circuit_1 = 12; // нога для подключения реле контура 1
int Circuit_2 = 13; // нога для подключения реле контура 2
int Circuit_3 = 14; // нога для подключения реле контура 3
void setup()
{
pinMode(Circuit_1, OUTPUT);
pinMode(Circuit_2, OUTPUT);
pinMode(Circuit_3, OUTPUT);
digitalWrite(Circuit_1, 0);
digitalWrite(Circuit_2, 0);
digitalWrite(Circuit_3, 0);
Serial.begin(115200);
delay(10);
//Включаем WiFiManager
WiFiManager wifiManager;
IPAddress _ip = IPAddress(192, 168, 1, 111);
IPAddress _gw = IPAddress(192, 168, 1, 1);
IPAddress _sn = IPAddress(255, 255, 255, 0);
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
//Если не удалось подключиться клиентом запускаем режим AP
// доступ к настройкам по адресу
http://192.168.4.1
wifiManager.autoConnect("Boiler_ServiceAP");
//если подключение к точке доступа произошло сообщаем
Serial.println("connected...yeey
");
delay(1000);
// Start the server
server.begin();
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(300);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
delay(300);
client.flush();
// Match the request
int val_1;
int val_2;
int val_3;
if (req.indexOf("/gpio_1/0") != -1)
{ val_1 = 0;
delay(300);}
else
if (req.indexOf("/gpio_1/1") != -1)
{ val_1 = 1;
delay(300);}
else
if (req.indexOf("/gpio_2/0") != -1)
{ val_2 = 0;
delay(300);}
else
if (req.indexOf("/gpio_2/1") != -1)
{ val_2 = 1;
delay(300);}
else
if (req.indexOf("/gpio_3/0") != -1)
{ val_3 = 0;
delay(300);}
else
if (req.indexOf("/gpio_3/1") != -1)
{ val_3 = 1;
delay(300);}
else {
Serial.println("invalid request");
client.stop();
return;
}
digitalWrite(Circuit_1, val_1);
digitalWrite(Circuit_2, val_2);
digitalWrite(Circuit_3, val_3);
client.flush();
// Prepare the response
String s_1 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s_1 += (val_1)?"high":"low";
s_1 += "</html>\n";
// Send the response to the client
client.print(s_1);
String s_2 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s_2 += (val_2)?"high":"low";
s_2 += "</html>\n";
// Send the response to the client
client.print(s_2);
String s_3 = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s_3 += (val_3)?"high":"low";
s_3 += "</html>\n";
// Send the response to the client
client.print(s_3);
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}