[RESOLU] Ethernet + erreur avec Google Chrome (GET favicon.ico)

Bonjour, j'ai un petit soucis avec ce code:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
/*
Gestion Carte 4 Relais
avec un serveur Web Arduino
Materiel:
* Arduino UNO
* Arduino Ethernet shield
* Carte 4 Relais
*/
byte mac[] = { xxxx, xxxx, xxxx, xxxx, xxxx, xxxx }; //Adresse MAC
byte ip[] = { 192, 168, x, xx }; // Adresse IP
EthernetServer server(xx); //Port du serveur
int ledPin1 = 3; // LED pin
int ledPin2 = 2; // LED pin
int ledPin3 = 5; // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON1 = false; //Pin status flag
boolean LEDON2 = false; //Pin status flag
boolean LEDON3 = false; //Pin status flag

void setup(){
//start Ethernet
Ethernet.begin(mac, ip);
//Configurer les 3 Pins de sorties
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
//Activer la liaison de données Serie
Serial.begin(9600); }

void loop(){
//Créer la connection Client
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString += c; }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
//lets check if LED should be lighted
//Controle Prise 1
if(readString.indexOf("L=1")>0) {
//Pin mise a ON
digitalWrite(ledPin1, LOW); // Mettre la Pin a ON
LEDON1 = true;
}else if(readString.indexOf("L=1")<0){
//Pin mise a OFF
digitalWrite(ledPin1, HIGH); /// Mettre la Pin a OFF
LEDON1 = false; }
//Controle Prise 2
if(readString.indexOf("L1=2")>0) {
//Pin mise a ON
digitalWrite(ledPin2, LOW); // Mettre la Pin a ON
LEDON2 = true;
}else if(readString.indexOf("L1=2")<0){
//Pin mise a OFF
digitalWrite(ledPin2, HIGH); // Mettre la Pin a OFF
LEDON2 = false; }
//Controle Prise 3
if(readString.indexOf("L2=3")>0) {
//Pin mise a ON
digitalWrite(ledPin3, LOW); // Mettre la Pin a ON
LEDON3 = true;
}else if(readString.indexOf("L2=3")<0){
//Pin mise a OFF
digitalWrite(ledPin3, HIGH); // Mettre la Pin a OFF
LEDON3 = false; }
// now output HTML data starting with standart header
client.println("HTTP/1.0 200 OK");
client.println("Content-Type: text/html");
client.println();
//Controle Relais par checkbox
client.println("<h1>Gestion des prises</h1>");
client.println("<form method=get name=Prise><input type=CHECKBOX name=L value=1>Prise 1
");
client.println("
");
client.println("<input type=CHECKBOX name=L1 value=2>Prise 2
");
client.println("
");
client.println("<input type=CHECKBOX name=L2 value=3>Prise 3
<input type=submit value=submit></form>");
client.println("
");
//Afficher statut prise 1
client.print("Prise1: ");
if (LEDON1)
client.println("ON
");
else
client.println("OFF
");
client.println("</body></html>");
//Afficher statut prise 2
client.print("Prise2: ");
if (LEDON2)
client.println("ON
");
else
client.println("OFF
");
client.println("</body></html>");
//Afficher statut prise 3
client.print("Prise3: ");
if (LEDON3)
client.println("ON
");
else
client.println("OFF
");
client.println("</body></html>");
//Effacer la chaine pour lecture suivante
readString="";
//Arreter le client
client.stop();
}}}}}

Quand je le fais tourner avec IE ça fonctionne, mais quand je le fais tourner avec Chrome, cela ne fonctionne pas.

Chrome me demande le favicon.ico, ce qui fait bugger le programme et ne me met pas mes sorties dans le bon état.

Les conditions If sont scratchées et du coup le programme ne fait pas ce que je lui demande.

J'ai essayé de rajouter cette condition qui normalement doit fonctionner:

 //dirty skip of "GET /favicon.ico HTTP/1.1"
          if (readString.indexOf("?") <0)
          {
            //skip everything
          }
          else

Ce qui donne un code final :

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
/*
Gestion Carte 4 Relais
avec un serveur Web Arduino
Materiel:
* Arduino UNO
* Arduino Ethernet shield
* Carte 4 Relais
*/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB5, 0x42 }; //Adresse MAC
byte ip[] = { 192, 168, 1, 12 }; // Adresse IP
EthernetServer server(80); //Port du serveur
int ledPin1 = 3; // LED pin
int ledPin2 = 2; // LED pin
int ledPin3 = 5; // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON1 = false; //Pin status flag
boolean LEDON2 = false; //Pin status flag
boolean LEDON3 = false; //Pin status flag

void setup(){
//start Ethernet
Ethernet.begin(mac, ip);
//Configurer les 3 Pins de sorties
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
//Activer la liaison de données Serie
Serial.begin(9600); }

void loop(){
  
//Créer la connection Client
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString += c; }
//output chars to serial port
Serial.print(c);

//if HTTP request has ended
if (c == '\n') {
  
         //dirty skip of "GET /favicon.ico HTTP/1.1"
          if (readString.indexOf("?") <0)
          {
            //skip everything
          }
          else
        
          //lets check if LED should be lighted
              //Controle Prise 1
              if(readString.indexOf("L=1")>0) {
              //Pin mise a ON
              digitalWrite(ledPin1, LOW); // Mettre la Pin a ON
              LEDON1 = true;
              }else if(readString.indexOf("L=1")<0){
              //Pin mise a OFF
              digitalWrite(ledPin1, HIGH); /// Mettre la Pin a OFF
              LEDON1 = false; }
              //Controle Prise 2
              if(readString.indexOf("L1=2")>0) {
              //Pin mise a ON
              digitalWrite(ledPin2, LOW); // Mettre la Pin a ON
              LEDON2 = true;
              }else if(readString.indexOf("L1=2")<0){
              //Pin mise a OFF
              digitalWrite(ledPin2, HIGH); // Mettre la Pin a OFF
              LEDON2 = false; }
              //Controle Prise 3
              if(readString.indexOf("L2=3")>0) {
              //Pin mise a ON
              digitalWrite(ledPin3, LOW); // Mettre la Pin a ON
              LEDON3 = true;
              }else if(readString.indexOf("L2=3")<0){
              //Pin mise a OFF
              digitalWrite(ledPin3, HIGH); // Mettre la Pin a OFF
              LEDON3 = false; }
              
              
          // now output HTML data starting with standart header
                      client.println("HTTP/1.0 200 OK");
                      client.println("Content-Type: text/html");
                      client.println();
                      //Controle Relais par checkbox
                      client.println("<h1>Gestion des prises</h1>");
                      client.println("<form method=get name=Prise><input type=CHECKBOX name=L value=1>Prise 1
");
                      client.println("
");
                      client.println("<input type=CHECKBOX name=L1 value=2>Prise 2
");
                      client.println("
");
                      client.println("<input type=CHECKBOX name=L2 value=3>Prise 3
<input type=submit value=submit></form>");
                      client.println("
");
                      //Afficher statut prise 1
                      client.print("Prise1: ");
                      if (LEDON1)
                      client.println("ON
");
                      else
                      client.println("OFF
");
                      client.println("</body></html>");
                      //Afficher statut prise 2
                      client.print("Prise2: ");
                      if (LEDON2)
                      client.println("ON
");
                      else
                      client.println("OFF
");
                      client.println("</body></html>");
                      //Afficher statut prise 3
                      client.print("Prise3: ");
                      if (LEDON3)
                      client.println("ON
");
                      else
                      client.println("OFF
");
                      client.println("</body></html>");
                      
        //Effacer la chaine pour lecture suivante
        readString="";
        //Arreter le client
        client.stop();
}}}}}

Mais j'ai toujours le même problème...

Le code que je souhaite faire marché est en fait issu de ce site:
http://can59-3-82-233-175-232.fbx.proxad.net/~aurelien/drupal7/?q=node/28

bonjour,
je vois pas la balise dans ton code.
le content type doit être dans le

je crois qu'il y a un debugger dans chrome.

J'ai changé sans succès, c'est même pire car le navigateur m'affiche maintenant "HTTP/1.0 200 OK Content-Type: text/html" en haut de page...

si tu mets pas dans une balise META, c'est normal.

Ok, je pense avoir trouvé,

J'ai oublié de mettre des {} après le else de la condition:
//dirty skip of "GET /favicon.ico HTTP/1.1"
if (readString.indexOf("?")<0)
{}

Du coup mon programme zappait bien le favicon, mais prenait de suite après le If pour la LED ON 2.

Du coup, ce code a l'air de fonctionner:

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
/*
Gestion Carte 4 Relais
avec un serveur Web Arduino
Materiel:
* Arduino UNO
* Arduino Ethernet shield
* Carte 4 Relais
*/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB5, 0x42 }; //Adresse MAC
byte ip[] = { 192, 168, 1, 12 }; // Adresse IP
EthernetServer server(80); //Port du serveur
int ledPin1 = 3; // LED pin
int ledPin2 = 2; // LED pin
int ledPin3 = 5; // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON1 = false; //Pin status flag
boolean LEDON2 = false; //Pin status flag
boolean LEDON3 = false; //Pin status flag

void setup(){
//start Ethernet
Ethernet.begin(mac, ip);
//Configurer les 3 Pins de sorties
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
//Activer la liaison de données Serie
Serial.begin(9600); }

void loop(){
  
//Créer la connection Client
EthernetClient client = server.available();
    if (client) {
    while (client.connected())
    {
          if (client.available()) 
          {
              char c = client.read();
              
              //read char by char HTTP request
              if (readString.length() < 30) {
                  //store characters to string
                  readString += c; }
                  //output chars to serial port
                  Serial.print(c);
                  
              //if HTTP request has ended
              if (c == '\n') {
                      
                      Serial.println("START");
                      
                       //dirty skip of "GET /favicon.ico HTTP/1.1"
                        if (readString.indexOf("?")<0)
                        {
                          Serial.print("skip favicon reading value is:");//skip everything
                          Serial.println(readString.indexOf("?"));
                          
                        }
                        else
                        {
                        //lets check if LED should be lighted
                            //Controle Prise 1
                            if(readString.indexOf("L=1")>0) {
                            //Pin mise a ON
                            Serial.print("Led 1 ON read:");
                            Serial.println(readString.indexOf("L=1"));
                            digitalWrite(ledPin1, LOW); // Mettre la Pin a ON
                            LEDON1 = true;
                            }
                            else if(readString.indexOf("L=1")<0){
                            //Pin mise a OFF
                            Serial.print("Led 1 OFF read:");
                            Serial.println(readString.indexOf("L=1"));
                            digitalWrite(ledPin1, HIGH); /// Mettre la Pin a OFF
                            LEDON1 = false; }
                            
                            
                            //Controle Prise 2
                            if(readString.indexOf("L1=2")>0) {
                            //Pin mise a ON
                            Serial.print("Led 2 ON read:");
                            Serial.println(readString.indexOf("L1=2"));                         
                            digitalWrite(ledPin2, LOW); // Mettre la Pin a ON
                            LEDON2 = true;
                            }
                            else if(readString.indexOf("L1=2")<0){
                            //Pin mise a OFF
                            Serial.print("Led 2 OFF read:");
                            Serial.println(readString.indexOf("L1=2"));
                            digitalWrite(ledPin2, HIGH); // Mettre la Pin a OFF
                            LEDON2 = false; }
                            
                            
                            //Controle Prise 3
                            if(readString.indexOf("L2=3")>0) {
                            //Pin mise a ON
                            Serial.print("Led 3 ON read:");
                            Serial.println(readString.indexOf("L2=3"));
                            digitalWrite(ledPin3, LOW); // Mettre la Pin a ON
                            LEDON3 = true;
                            }else if(readString.indexOf("L2=3")<0){
                            //Pin mise a OFF
                            Serial.print("Led 3 OFF read:");
                            Serial.println(readString.indexOf("L2=3"));
                           
                            digitalWrite(ledPin3, HIGH); // Mettre la Pin a OFF
                            LEDON3 = false; }
                        }  
                            
                        // now output HTML data starting with standard header
                                    
                                    client.println("HTTP/1.0 200 OK");
                                    client.println("<HTML>");
                                    client.println("<BODY>");
                                    client.println("<HEAD>");
                                    client.println("Content-Type: text/html");
                                    client.println("</HEAD>");
                                    client.println();
                                    //Controle Relais par checkbox
                                    client.println("<h1>Gestion des prises</h1>");
                                    client.println("<form method=get name=Prise><input type=CHECKBOX name=L value=1>Prise 1
");
                                    client.println("
");
                                    client.println("<input type=CHECKBOX name=L1 value=2>Prise 2
");
                                    client.println("
");
                                    client.println("<input type=CHECKBOX name=L2 value=3>Prise 3
<input type=submit value=submit></form>");
                                    client.println("
");
                                    //Afficher statut prise 1
                                    client.print("Prise1: ");
                                    if (LEDON1)
                                    client.println("ON
");
                                    else
                                    client.println("OFF
");
                                    client.println("</BODY>");
                                    client.println("</HTML>");
                                    //Afficher statut prise 2
                                    client.print("Prise2: ");
                                    if (LEDON2)
                                    client.println("ON
");
                                    else
                                    client.println("OFF
");
                                    client.println("</BODY>");
                                    client.println("</HTML>");
                                    //Afficher statut prise 3
                                    client.print("Prise3: ");
                                    if (LEDON3)
                                    client.println("ON
");
                                    else
                                    client.println("OFF
");
                                    
                                    client.println("</BODY>");
                                    client.println("</HTML>");
                      //Effacer la chaine pour lecture suivante
                      readString="";
                      //Arreter le client
                      Serial.println("STOP");
                      client.stop();
                      }
             }
         }
    }
}

Je vais en profiter également pour corriger correctement le HTML mais ce n'était pas ce qui causait problème.

Merci infobarquee
:grin:

de rien :wink:
pense a éditer ton premier post pour le mettre en [résolu]