no way to compare when less than two revisions
Différences
Ci-dessous, les différences entre deux révisions de la page.
— | electronique:esp:esp32-commander-led-wifi [2022/03/25 19:52] (Version actuelle) – créée Cédric ABONNEL | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Commander une LED Wifi ====== | ||
+ | {{ : | ||
+ | Nous avons vu dans le chapitre [..] comment la carte ESP 8266 peut se connecter à un **point d' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Sur la carte de développement, | ||
+ | |||
+ | |||
+ | .. | ||
+ | |||
+ | Jusqu' | ||
+ | |||
+ | <code C> | ||
+ | #include < | ||
+ | |||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | |||
+ | int ledPin = 16; | ||
+ | |||
+ | // Déclaration du Server sur le port 80 | ||
+ | WiFiServer server(80); | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | // initialisation de la communication série | ||
+ | Serial.begin(115200); | ||
+ | | ||
+ | delay(100); | ||
+ | |||
+ | // initialisation de la sortie pour la LED | ||
+ | int valeurLED = HIGH; | ||
+ | pinMode(ledPin, | ||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | // Connexion wifi | ||
+ | Serial.println(); | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid); | ||
+ | | ||
+ | WiFi.begin(ssid, | ||
+ | |||
+ | // connexion | ||
+ | while (WiFi.status() != WL_CONNECTED) | ||
+ | { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | |||
+ | // Wifi connecter | ||
+ | Serial.println(" | ||
+ | |||
+ | // Démmarrage du serveur. | ||
+ | server.begin(); | ||
+ | Serial.println(" | ||
+ | |||
+ | // Affichage de l' | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(WiFi.localIP()); | ||
+ | Serial.println("/" | ||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | | ||
+ | // Attente de connexion d'un client | ||
+ | client = server.available(); | ||
+ | if (!client) | ||
+ | { | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // Attendre si le client envoie des données ... | ||
+ | Serial.println(" | ||
+ | while(!client.available()){ | ||
+ | delay(1); | ||
+ | } | ||
+ | |||
+ | String request = client.readStringUntil(' | ||
+ | Serial.println(request); | ||
+ | client.flush(); | ||
+ | |||
+ | if (request.indexOf("/ | ||
+ | valeurLED = LOW; | ||
+ | digitalWrite(ledPin, | ||
+ | } | ||
+ | if (request.indexOf("/ | ||
+ | valeurLED = HIGH; | ||
+ | digitalWrite(ledPin, | ||
+ | } | ||
+ | |||
+ | |||
+ | // Réponse | ||
+ | client.println(" | ||
+ | client.println(" | ||
+ | client.println("" | ||
+ | |||
+ | if(valeurLED == LOW) { | ||
+ | client.println(" | ||
+ | } else { | ||
+ | client.println(" | ||
+ | } | ||
+ | |||
+ | Serial.println(" | ||
+ | Serial.println("" | ||
+ | |||
+ | } | ||
+ | </ |