* Demonstrate using an http server and an HTML form to control an LED.
* The http server runs on the ESP8266.
*
* Connect to "http://esp8266WebForm.local:8000" or "http://"
* to bring up an HTML form to control the LED connected GPIO#0. This works
* for the Adafruit ESP8266 HUZZAH but the LED may be on a different pin on
* other breakout boards.
*
* Imperatives to turn the LED on/off using a non-browser http client.
* For example, using wget.
* $ wget http://esp8266webform.local/ledon (liga relé direto)
* $ wget http://esp8266webform.local/ledoff (desliga relé direto)
* ADICIONEI UM RESET AUTOMATICO NO ESP8266 de 2 em 2 MINUTOS. SE NÃO QUISER TIRE O CONTADOR EM void loop (void)
*/
#include
#include
#include
#include
int contador=0;
// Fill in your WiFi router SSID and password
const char* ssid = "SEU SSID";
const char* password = "SUA SENHA WIFI";
MDNSResponder mdns;
ESP8266WebServer server(80);
const char INDEX_HTML[] =
""
""
""
""
"ESP8266 Web Form Demo"
""
""
""
"Controle Remoto_(192.xxx.xxx.xxx)
"
//"ARQUIVO:novo_programa_.115.V6_07junho17-cam_OK.ino
"
""
""
""
""
"";
// GPIO#0 is for Adafruit ESP8266 HUZZAH board.
//Passei para GPIO#2 para comodidade.
const int LEDPIN = 2;
void handleRoot()
{
if (server.hasArg("LED")) {
handleSubmit();
}
else {
server.send(200, "text/html", INDEX_HTML);
}
}
void returnFail(String msg)
{
server.sendHeader("Connection", "close");
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(500, "text/plain", msg + "\r\n");
}
void handleSubmit()
{
String LEDvalue;
if (!server.hasArg("LED")) return returnFail("BAD ARGS");
LEDvalue = server.arg("LED");
if (LEDvalue == "1") {
writeLED(true);
server.send(200, "text/html", INDEX_HTML);
}
else if (LEDvalue == "0") {
writeLED(false);
server.send(200, "text/html", INDEX_HTML);
}
else {
returnFail("Bad LED value");
}
}
void returnOK()
{
server.sendHeader("Connection", "close");
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, "text/plain", "OK-comando executado\r\n");
}
/*
* Imperative to turn the LED on using a non-browser http client.
* For example, using wget.
* $ wget http://esp8266webform/ledon
*/
void handleLEDon()
{
writeLED(true);
returnOK();
}
/*
* Imperative to turn the LED off using a non-browser http client.
* For example, using wget.
* $ wget http://esp8266webform/ledoff
*/
void handleLEDoff()
{
writeLED(false);
returnOK();
}
void handleNotFound()
{
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i120///
contador++;
Serial.println (contador);
delay(1000);
if (contador > 120) {
Serial.println("Reiniciando");
delay(3000);
ESP.reset();
//ESP.restart();
}
server.handleClient();
}