salut, j'ai un problème dans l'esp8266-01 quand j'ajoute 3 LEDs le programme fonction bien , apres j'ajoute le LED numéro 4 l'esp8266 reste clignote et l'operation ne termine pas,cette image avec 3 LEDs Nom : 001.JPG
Affichages : 291
Taille : 40,5 Ko
Nom : 002.JPG
Affichages : 251
Taille : 32,9 Ko et cette image quand je intégré le 4éme LED
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
 
char ssid[] = "**";            // your network SSID (name)
char pass[] = "****";        // your network password
int status = WL_IDLE_STATUS;
 
int Chambre1_LED = 2;                                                
int Chambre2_LED = 3;
int Salon_LED = 4; 
int Chambre3_LED = 5;
 
WiFiEspServer server(80);
 
// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(512);
 
void setup()
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(8, OUTPUT);
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(9600);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module
 
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }
 
  // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }
 
  Serial.println("You're connected to the network");
  printWifiStatus();
 
  // start the web server on port 80
  server.begin();
}
 
//------------------------------------------------------------------------------------------------
void loop()
{
 leds();
}
//------------------------------------------------------------------------------------------------
 
void leds ()
{
  WiFiEspClient client = server.available();  // listen for incoming clients
 
  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer
 
        // printing the stream to the serial monitor will slow down
        // the receiving of data from the ESP filling the serial buffer
        //Serial.write(c);
 
        // you got two newline characters in a row
        // that's the end of the HTTP request, so send a response
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }
          salon();
          chamb1();
          chamb2();
          chamb3();
      }
    }
    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}
//--------------------------------------------------------------------------------------------------
 
void chamb1()
{
        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /O1")) {
          Serial.println("Turn led ON");
 
          digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /F1")) {
          Serial.println("Turn led OFF");
 
          digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
        }
}
//------------------------------------------------------
void chamb2()
{
        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /O2")) {
          Serial.println("Turn led ON");
 
          digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /F2")) {
          Serial.println("Turn led OFF");
 
          digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
        }
}
//--------------------------------------------------
void salon()
{
 
        if (buf.endsWith("GET /O3")) {
          Serial.println("Turn led ON");
 
          digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /F3")) {
          Serial.println("Turn led OFF");
 
          digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
        }
}
//----------------------------------------------------------------
void chamb3()
{
 
        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /O4")) {
          Serial.println("Turn led ON");
 
          digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
        }
        else if (buf.endsWith("GET /F4")) {
          Serial.println("Turn led OFF");
 
          digitalWrite(5, LOW);    // turn the LED off by making the voltage LOW
        }
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void sendHttpResponse(WiFiEspClient client)
{
  // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
  // and a content-type so the client knows what's coming, then a blank line:
  client.println("HTTP/1.1 200 OK");
  client.println("Content-type:text/html");
  client.println();
 
  // the content of the HTTP response follows the header:
  client.print("The LED is ");
  client.print(5);
  client.println("<br>");
  client.println("<br>");
 
  /*client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
  client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");*/
 
  // The HTTP response ends with another blank line:
  client.println();
}
//--------------------------------------------------------------------------------------------------
void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
 
  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
  Serial.println();
}