Arduino Forum

International => EspaƱol => Software => Topic started by: Raul_Montiel on May 23, 2019, 12:51 am

Title: Modificar delay desde pagina web de nodemcu
Post by: Raul_Montiel on May 23, 2019, 12:51 am
Ayuda deseo modificar desde la pagina el dalay de un led desde la pagina poder modificarlo y que se quede guardado, solo puedo por ahora encender led pero busco como modificar el dalay de encendido del led.

Code: [Select]
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

/* Put your SSID & Password */
const char* ssid = "MIRED";  // Enter SSID here
const char* password = "12345678";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,2,1);
IPAddress gateway(192,168,2,1);
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

uint8_t LEDpin = D5;
bool LEDstatus = LOW;

void setup() {
  pinMode(LEDpin, OUTPUT);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  server.on("/", handle_OnConnect);
  server.on("/ledon", handle_ledon);
  server.on("/ledoff", handle_ledoff);

  Serial.println("HTTP server started");
void loop() {
  digitalWrite(LEDpin, HIGH);
  digitalWrite(LEDpin, LOW);

void handle_OnConnect() {
  LEDstatus = LOW;
  server.send(200, "text/html", SendHTML(false));

void handle_ledon() {
  LEDstatus = HIGH;
  server.send(200, "text/html", SendHTML(true));
   delay(4000); //aqui  se desea que desde la web cambie el dalay
  LEDstatus = LOW;

void handle_ledoff() {
  LEDstatus = LOW;
  server.send(200, "text/html", SendHTML(false));

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");

String SendHTML(uint8_t led){
  String ptr = "<!DOCTYPE html>\n";
  ptr +="<html>\n";
  ptr +="<head>\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>LED</h1>\n";
  ptr +="<p>Click to switch LED on and off.</p>\n";
  ptr +="<form method=\"get\">\n";
  ptr +="<input type=\"button\" value=\"LED OFF\" onclick=\"window.location.href='/ledoff'\">\n";
  ptr +="<input type=\"button\" value=\"LED ON\" onclick=\"window.location.href='/ledon'\">\n";
  ptr +="</form>\n";
  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;