Close

nefunčkné millis v esp8266

Úvodní stránka Fórum Software Jazyky Jazyk Wiring nefunčkné millis v esp8266

Označeno štítky: 

Aktuálně je na stránce zobrazen 1 příspěvek (celkem z 1)
  • Autor
    Příspěvky
  • #8995
    jakub123
    Účastník

    chcem ovladat rele pomocou esp8266 a okrem moznosti vypnut/zapnut chcem mat aj
    zapnut na 15 minut ale aby pocas tejto doby to islo aj rucne vypnut ale po stlaceni po kliknuti na odkaz 15min sa rele zopne ale uz nevypne po 15 minutach
    vopred dakujem za pomoc
    kod:

    #include <ESP8266WiFi.h>
    long previousMillis = 0;       
    long interval = 900000;
     
    const char* ssid = "wifinet2";
    const char* password = "bf85246ab";
     
    int ledPin = 2;
    
    WiFiServer server(80);
    
     
    void setup() {
      Serial.begin(115200);
      delay(10);
     
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, HIGH);
    
      Serial.println();
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);
     
      WiFi.begin(ssid, password);
     
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
     
    
      server.begin();
      Serial.println("Server started");
     
    
      Serial.print("Use this URL to connect: ");
      Serial.print("http://");
      Serial.print(WiFi.localIP());
      Serial.println("/");
     
    }
     
    void loop() {
    unsigned long currentMillis = millis();
      WiFiClient client = server.available();
      if (!client) {
        return;
      }
     
    
      Serial.println("new client");
      while(!client.available()){
        delay(1);
      }
     
    
      String request = client.readStringUntil('\r');
      Serial.println(request);
      client.flush();
     
    
     
      int value = LOW;
      if (request.indexOf("/releoff") != -1)  {
        digitalWrite(ledPin, HIGH);
     
      }
      if (request.indexOf("/releon") != -1)  {
        digitalWrite(ledPin, LOW);
       
      }
    if (request.indexOf("/rele15") != -1) {
     
          
             if(currentMillis - previousMillis > interval) {
                previousMillis = millis();   
                digitalWrite(ledPin, LOW);
             }
         
          
          else {
             digitalWrite(ledPin, HIGH); 
          }
       }
        
    
    client.println("");
     client.println("<!DOCTYPE html>");
     client.println("<head>");
     client.println("</head>");
     client.println("<html>");
     client.println("<body>");
     client.println("<h1><span style=\"color: #00ff00;\"><em><strong>Ovladanie rele</strong></em></span></h1>");
     client.println("<table style=\"height: 300px; border-color: #ffbf00; background-color: #bfff00;\" border=\"6\" width=\"1000\">");
     client.println("<tbody>");
     client.println("<tr>");
     client.println("<td>");
     client.println("<h1><span style=\"color: #008000;\"><strong><a style=\"color: #008000;\" href=\"/releon\">On</a></strong></span></h1>");
     client.println("</td>");
     client.println("<td>");
     client.println("<h1><span style=\"color: #ff0000;\"><strong><a style=\"color: #ff0000;\" href=\"/releoff\">Off</a></strong></span></h1>");
     client.println("</td>");
     client.println("<td>");
     client.println("<h1><span style=\"color: #3366ff;\"><strong><a style=\"color: #3366ff;\" href=\"/rele15\">15min</a></strong></span></h1>");
     client.println("</td>");
     client.println("</tr>");
     client.println("</tbody>");
     client.println("</table>");
     client.println("<p>&nbsp;</p>");
     client.println("</html>");
     client.println("</body>");
     delay(1);
    
      Serial.println("Client disonnected");
      Serial.println("");
    }
     
    
Aktuálně je na stránce zobrazen 1 příspěvek (celkem z 1)
  • Pro reakci na toto téma se musíte přihlásit.