Bonjour a tous
Je reviens vers vous sur un ancien de mes programmes, je remet le nez dedans mais je n'arrive pas a faire ce que je souhaite. j'ai systématiquement des erreurs des que je touche a une phrase
Le programme permet d'activer 4 sorties via un nodeMCU en mode point d’accès jusque la, tout fonctionne.
J'ai besoin de crée les conditions suivantes mais je n'y arrive pas et j'aurai besoins d'un coup de patte.
Led 1: ne peux être activée et désactivée que si Led2 et Led 3 sont éteinte
Led 2: ne peux etre activée que si Led 1 est active et Led 3 désactivée
Led 3: ne peux etre activée que si Led 1 est active et Led 2 desactivée
Led 4 ne peux etre activée et désactivée que si Led 1 est desactivée
merci pour votre aide, bonne soirée ou journée
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
/* Put your SSID & Password */
const char* ssid = "NodeMCU"; // Enter SSID here
const char* password = "12345678"; //Enter Password here
/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
ESP8266WebServer server(80);
uint8_t LED1pin = 13;
bool LED1status = LOW;
uint8_t LED2pin = 12;
bool LED2status = LOW;
uint8_t LED3pin = 5;
bool LED3status = LOW;
uint8_t LED4pin = 4;
bool LED4status = LOW;
void setup() {
Serial.begin(115200);
pinMode(LED1pin, OUTPUT);
pinMode(LED2pin, OUTPUT);
pinMode(LED3pin, OUTPUT);
pinMode(LED4pin, OUTPUT);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);
server.on("/", handle_OnConnect);
server.on("/led1on", handle_led1on);
server.on("/led1off", handle_led1off);
server.on("/led2on", handle_led2on);
server.on("/led2off", handle_led2off);
server.on("/led3on", handle_led3on);
server.on("/led3off", handle_led3off);
server.on("/led4on", handle_led4on);
server.on("/led4off", handle_led4off);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop () {
server.handleClient();
}
void handle_OnConnect() {
LED1status = LOW;
LED2status = LOW;
LED3status = LOW;
LED4status = LOW;
Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF | GPIO4 Status: OFF | GPIO5 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led1on() {
LED1status = HIGH;
digitalWrite(LED1pin, LED1status) ;
Serial.println("GPIO7 Status: ON");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led1off() {
LED1status = LOW;
digitalWrite(LED1pin, LED1status) ;
Serial.println("GPIO7 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led2on() {
LED2status = HIGH;
digitalWrite(LED2pin, LED2status);
Serial.println("GPIO6 Status: ON");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led2off() {
LED2status = LOW;
digitalWrite(LED2pin, LED2status);
Serial.println("GPIO6 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led3on() {
LED3status = HIGH;
digitalWrite(LED3pin, LED3status);
Serial.println("GPIO4 Status: ON");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led3off() {
LED3status = LOW;
digitalWrite(LED3pin, LED3status);
Serial.println("GPIO4 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led4on() {
LED4status = HIGH;
digitalWrite(LED4pin, LED4status) ;
Serial.println("GPIO5 Status: ON");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_led4off() {
LED4status = LOW;
digitalWrite(LED4pin, LED4status);
Serial.println("GPIO5 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status,LED3status,LED4status));
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
String SendHTML(uint8_t led1stat,uint8_t led2stat,uint8_t led3stat,uint8_t led4stat){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>LED Control</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: #1abc9c;}\n";
ptr +=".button-on:active {background-color: #16a085;}\n";
ptr +=".button-off {background-color: #34495e;}\n";
ptr +=".button-off:active {background-color: #2c3e50;}\n";
ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<h1>ESP8266 Web Server</h1>\n";
ptr +="<h3>Using Access Point(AP) Mode</h3>\n";
if(led1stat)
{ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
else
{ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}
if(led2stat)
{ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
else
{ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}
if(led3stat)
{ptr +="<p>LED3 Status: ON</p><a class=\"button button-off\" href=\"/led3off\">OFF</a>\n";}
else
{ptr +="<p>LED3 Status: OFF</p><a class=\"button button-on\" href=\"/led3on\">ON</a>\n";}
if(led4stat)
{ptr +="<p>LED4 Status: ON</p><a class=\"button button-off\" href=\"/led4off\">OFF</a>\n";}
else
{ptr +="<p>LED4 Status: OFF</p><a class=\"button button-on\" href=\"/led4on\">ON</a>\n";}
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}