Page 1 sur 1

retard a l'allumage

Publié : 30 avr. 2017, 14:34
par clod83
bonjour
petit problème de débutant sur nodemcu v2 board ... esp8266-12e

je ne comprend pas pourquoi si je fais le choix "clignote" le clignotement démarre avec une seconde environ de retard
suivant le mode précédant ça reste allumé ou éteint pendant environ une seconde puis ça marche correctement

alors que éteint ou allume est instantané

merci

Code : Tout sélectionner

#include "ESP8266WiFi.h" // WiFi Library
// constants won't change. Used here to set a pin number :
const int ledPin = D0;// the number of the LED pin

							   // Variables will change :
int ledState = LOW;             // ledState used to set the LED

								// Generally, you should use "unsigned long" for variables that hold time
								// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

										 // constants won't change :
const long interval = 200;           // interval at which to blink (milliseconds)

WiFiServer server(80); // Define Web Server Port
String etat = "";

void setup()
{
	Serial.begin(115200);
		delay(10);
		pinMode(D0, OUTPUT);
		digitalWrite(D0, LOW);
	
					  // Connect to WiFi network
		Serial.print("Connecting to ");
		Serial.println("Livebox-4F8A");
		WiFi.begin("Livebox-4F8A", "A7721E2105083");
	
		// Wait until connected to WiFi
		while (WiFi.status() != WL_CONNECTED) {
			delay(250);
			Serial.print(".");
		}
	
		// Confirmation that WiFi is connected
		Serial.println("");
		Serial.println("WiFi connected");
	
		// Start the Web Server
		server.begin();
		Serial.println("Web Server Started");
	
		// Display IP address
		Serial.print("You can connect to the Server here: ");
		Serial.print("http://");
		Serial.print(WiFi.localIP());
		Serial.println();
		Serial.println();

}

void loop() {
		// Check if someone is connected
	
		WiFiClient client = server.available();
		if (!client )
		{	// mettre ici tout ce qui n'est pas wifi
			if (etat == "/CLIGNOTE") clignote();
			if (etat == "") return;
		}
		else
		{ 
			
			String request = client.readStringUntil('\r');
	
			if (request.indexOf("/ETEINDRE") != -1) //-1 si pas trouvé
			{
				digitalWrite(D0, LOW);
				etat = "/ETEINDRE";
			}

			if (request.indexOf("/ALLUMER") != -1)
			{
				digitalWrite(D0, HIGH);
				etat = "/ALLUMER";
			}

			if (request.indexOf("/CLIGNOTE") != -1 )
			{
				etat = "/CLIGNOTE";
	//			clignote();
			}
			
			
				// Create Web Page

				client.println("HTTP/1.1 200 OK"); // HTML Header
				client.println("Content-Type: text/html");
				client.println("");
				client.println("<!DOCTYPE HTML>");

				client.println("<html>"); // Start of HTML

				client.println("<style>");
				client.println("body {background-color: #ACAEAD;}"); // Set Background Color
				client.println("</style>");


				client.println("<br><br>");
				client.println("<a href=\"/ALLUMER\"\"><button>allumer</button></a>");

				client.println("<a href=\"/ETEINDRE\"\"><button>eteindre</button></a><br />");
				client.println("<a href=\"/CLIGNOTE\"\"><button>clignoter</button></a><br />");
				client.println("</html>");
				delay(10);
				
			}//else

}

void clignote()
{
	unsigned long currentMillis = millis();

	if (currentMillis - previousMillis >= interval) {
		// save the last time you blinked the LED
		previousMillis = currentMillis;

		// if the LED is off turn it on and vice-versa:
		if (ledState == LOW) {
			ledState = HIGH;
		}
		else {
			ledState = LOW;
		}

		// set the LED with the ledState of the variable:
		digitalWrite(D0, ledState);
	}
}