/*************************************************************************************************************************************** LEA LIVE- NEXTION DISPLAY - HTTP SERVER NOTE : UART RX IO TX IO CTS RTS UART0 GPIO3 GPIO1 N/A N/A UART1 GPIO9 GPIO10 GPIO6 GPIO11 UART2 GPIO16 GPIO17 GPIO8 GPIO7 ****************************************************************************************************************************************/ #include #include #include "ESPAsyncWebServer.h" /* ------------------------- Wifi -------------------------*/ const char* ssid = "JJJJ"; // Enter SSID here const char* password = "nicolajean1975"; //Enter Password here AsyncWebServer server(80); /* ------------------------- Variables -------------------------*/ String numero = "0"; int count = 0; #define RXD2 16 #define TXD2 17 /* ------------------------- FONCTIONS -------------------------*/ void endNextionCommand() { Serial2.write(0xff); Serial2.write(0xff); Serial2.write(0xff); } String SendHTML(String numero){ String ptr = " \n"; ptr +="\n"; ptr +="\n"; ptr +="LEA LIVE\n"; ptr +="\n"; ptr +="\n"; ptr +="\n"; ptr +="
\n"; ptr +="

! LEA LIVE !

\n"; ptr +="
\n"; ptr +="
\n"; ptr +="\n"; ptr +="
\n"; ptr +="
Numéro Produit:
\n"; ptr +="
"; ptr +=numero; ptr +="
\n"; ptr +="
\n"; ptr +="
"; ptr +=" "; ptr +=" "; ptr +="

"; ptr +="
\n"; ptr +="\n"; ptr +="\n"; return ptr; } String IpAddress2String(const IPAddress& ipAddress) { return String(ipAddress[0]) + String(".") +\ String(ipAddress[1]) + String(".") +\ String(ipAddress[2]) + String(".") +\ String(ipAddress[3]) ; } /* ------------------------- SETUP -------------------------*/ void setup() { Serial.begin(9600); // debug Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); Serial.println("Serial Txd is on pin: "+String(TX)); Serial.println("Serial Rxd is on pin: "+String(RX)); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); //connect to your local wi-fi network while (WiFi.status() != WL_CONNECTED) //check wi-fi is connected to wi-fi network { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connecté..!"); Serial.print("Adresse IP: "); Serial.println(WiFi.localIP()); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ int paramsNr = request->params(); Serial.println(paramsNr); for(int i=0;igetParam(i); Serial.print("Param name: "); Serial.println(p->name()); Serial.print("Param value: "); Serial.println(p->value()); Serial.println("------"); numero = p->value(); // Affichage du numéro String command = "numero.txt=\"" + numero + "\""; Serial.println("Envoyé Ecran: " + numero); Serial2.print(command); endNextionCommand(); } request->send(200, "text/html", SendHTML(numero)); }); server.begin(); Serial.println("Serveur HTTP démarré"); } /* ------------------------- LOOP -------------------------*/ void loop() { delay(2000); count = count + 1; // Affichage de l'IP sur l'ecran Nextion if (count < 10) { String afficheIP = "ip.txt=\"" + IpAddress2String(WiFi.localIP()) + "\""; Serial2.print(afficheIP); endNextionCommand(); } else { String afficheIP = "ip.txt=\"LUNAECRAFT\""; Serial2.print(afficheIP); endNextionCommand(); } }