[Programmation] Page Web générée via ESP8266 et Arduino : problème !
Répondre à la discussion
Affichage des résultats 1 à 3 sur 3

Page Web générée via ESP8266 et Arduino : problème !



  1. #1
    kilouxa

    Page Web générée via ESP8266 et Arduino : problème !


    ------

    Bonjour, depuis ce matin je n'arrive pas a envoyer depuis l'arduino et l'esp8266 une page HTML.
    Je voudrais savoir ou est l'erreur dans mon code :

    Code:
    #include <SoftwareSerial.h>
    
    SoftwareSerial esp8266(10,11);
    
    #define DEBUG true
                                 
    String NomduReseauWifi = "Wifi"; 
    String MotDePasse      = "*********"; 
    
    int connectionId;
    String Command_CipSend;
    
    void setup()
    {
      esp8266.begin(9600);
      delay(2000);
      Serial.begin(9600);
      wifi_init();
    }
     
    void loop()
    {
      if(esp8266.available()) 
      {
        if(esp8266.find("+IPD,"))
        {
         delay(1000);
         int connectionId = esp8266.read()-48;
    
            String HTMLCode   = "<HTML>"
                          "<HEAD><TITLE>Baptiste Mini8266 Server</TITLE>"
                          "<BODY><H1>Welcome to Pete's ESP8266 \"hacking\" project</H1>"
                             "<form action=\"\" method=\"post\">"
                             "<fieldset>"
                              "<legend>Red LED State</legend>"
                                "<input type=\"radio\" name=\"RedLEDState\" value=\"RED_ON\"> ON"
                                "<input type=\"radio\" name=\"RedLEDState\" value=\"RED_OFF\" checked=\"checked\"> OFF<br>"
                             "</fieldset>"
                             "<fieldset>"
                             "<legend>Green LED State</legend>"
                                "<input type=\"radio\" name=\"GreenLEDState\" value=\"GREEN_ON\"> ON"
                                "<input type=\"radio\" name=\"GreenLEDState\" value=\"GREEN_OFF\" checked=\"checked\"> OFF<br>"
                             "</fieldset>"
                             "<fieldset>"
                             "<legend>Blue LED State</legend>"
                                "<input type=\"radio\" name=\"BlueLEDState\" value=\"BLUE_ON\"> ON"
                                "<input type=\"radio\" name=\"BlueLEDState\" value=\"BLUE_OFF\" checked=\"checked\"> OFF<br>"
                             "</fieldset>"                         
                             "<input type=\"submit\" value=\"Submit\">"
                             "</form>"
                              "<BR><BR>"
                          "<HR>"
                          "<H2>Server Stats</H2>"  
                          "</BODY>
                        </HTML>";
    
          Envoi_DATA(HTMLCode, connectionId);
                      
          Close_Connect(connectionId);
    
        }
      }
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////
    
    String Com_ESP8266(String command, const int timeout, boolean debug) {   
        esp8266.print(command);
        String response = "";
        long int time = millis();    
        while( (time+timeout) > millis()) 
        {
          while(esp8266.available()) 
          {         
            char c = esp8266.read();
            response+=c; 
          }  
        }
           
        if(debug) {
          Serial.println(response);
          Serial.println("-----------------------------------");     
        }    
        return response;
    }
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void wifi_init() {
      Serial.println("**********************************************************");  
      Serial.println("**************** DEBUT DE L'INITIALISATION ***************");
      Serial.println("**********************************************************");
      //Com_ESP8266("AT+RST\r\n",1000,DEBUG); // Reset du module
      Com_ESP8266("AT+CIOBAUD=9600\r\n",1000,DEBUG); // On force la connexion a 9600 bds
      Com_ESP8266("AT+CWMODE=3\r\n",1000,DEBUG); // Configure le module en tant que serveur et client
      Com_ESP8266("AT+CWJAP=\""+ NomduReseauWifi + "\",\"" + MotDePasse +"\"\r\n",10000,DEBUG); // On se connecte au wifi
      Com_ESP8266("AT+CIFSR\r\n",1000,DEBUG); // Affiche l'adresse IP, Mac ...
      Com_ESP8266("AT+CIPMUX=1\r\n",1000,DEBUG); // On initialise en tant que serveur multi-client
      Com_ESP8266("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // Ouvre le serveur sur le Port 80 
      Serial.println("**********************************************************");
      Serial.println("***************** INITIALISATION TERMINEE ****************");
      Serial.println("**********************************************************");
    }
    
    void Envoi_DATA(String Data, int connectionId) {
      Command_CipSend = "AT+CIPSEND=" + String(connectionId) + "," + String(Data.length()+2) + "\r\n";
    
      //Serial.println("Co ID : " + String(connectionId) );
      //Serial.println("Length : " + String(Data.length()+2) );
      //Serial.println("Data : " + String(Data) );
      //Serial.println("Cmd : " + String(Command_CipSend) );
      
      Com_ESP8266(String(Command_CipSend),1000,DEBUG); 
      Com_ESP8266(String(Data),1000,DEBUG);
    }
    
    void Close_Connect(int connectionId) {
      String closeCommand = "AT+CIPCLOSE=" + String(connectionId) + "\r\n"; 
      Com_ESP8266(closeCommand,3000,DEBUG); 
    }

    -----

  2. #2
    HAYAC

    Re : Page Web générer via ESP8266 et Arduino : Problème

    Bonjour,
    Quelle est le message d'erreur,
    Que ce passe t-il exactement?

  3. #3
    kilouxa

    Re : Page Web générer via ESP8266 et Arduino : Problème

    Bon même après avoir refait le code de A à Z j'ai toujours le même problème :/

    Voici le nouveau code :

    Code:
    #include <SoftwareSerial.h>
    
    SoftwareSerial esp8266(10,11);
    
    #define DEBUG true       
                        
    String NomduReseauWifi = "Wifi_Vasseur"; 
    String MotDePasse      = "junior77370"; 
    
    void setup() {
      esp8266.begin(9600); // your esp's baud rate might be different
      delay(2000);
      Serial.begin(9600);
    
    Serial.println("////////////////////////////////////////////////////////");
    Serial.println("          > Initialisation du module : <");
    Serial.println("");
    //Com_ESP8266("AT\r\n", 1500, 'OK', "Connexion au module " ," -> Terminé", " -> Erreur", DEBUG);
    //Com_ESP8266("AT+RST\r\n", 1500, 'ready', "Réinitialisation du module" ," -> Terminé", " -> Erreur", DEBUG);
    Com_ESP8266("AT+CIOBAUD=9600\r\n", 1500, "OK", "Configuration de la connexion à 9600bds " ,"-> Terminé", "-> Erreur", DEBUG);
    Com_ESP8266("AT+CWMODE=3\r\n", 1500, "OK", "Configuration du module en tant que Client et Serveur " , "-> Terminé", "-> Erreur", DEBUG);
    Com_ESP8266("AT+CWJAP=\""+ NomduReseauWifi + "\",\"" + MotDePasse +"\"\r\n", 10000, "OK", "Connexion à " + NomduReseauWifi , " -> Terminé", "-> Erreur", DEBUG);
    Com_ESP8266("AT+CIFSR\r\n", 2000, "OK", "Obtention de l'adresse IP " , "-> Terminé", "-> Erreur", DEBUG);
    Com_ESP8266("AT+CIPMUX=1\r\n", 1500, "OK", "Configuration du mode multi-client " , "-> Terminé", "-> Erreur", DEBUG);
    Com_ESP8266("AT+CIPSERVER=1,80\r\n", 1500, "OK", "Ouverture du serveur Web sur le port 80 " , "-> Terminé", "-> Erreur", DEBUG);
    Serial.println("");
    Serial.println("          > Initialisation terminé <"); 
    Serial.println("////////////////////////////////////////////////////////");
    }
    
    boolean Com_ESP8266(String cmd, int timeout, String reponse, String msg_config, String msg_correct, String msg_echec, boolean debug)
    { 
      
      delay(200);
      Serial.print(msg_config);    
      
      esp8266.print(cmd);
      if(debug){ Serial.println(""); Serial.println("Commande envoyé : " + cmd); }
      
      long int time = millis(); 
      String rep = "";   
      while( (time + timeout) > millis()) 
      {
        while ( esp8266.available() ) 
        {
          char c = esp8266.read();
          rep += c;
        }
      }
    
      int ok_place_id = rep.indexOf(reponse);
      
    /* DEBUG */  if(debug){ Serial.println("////// Réponse du module : //////"); Serial.println(rep); Serial.println("////// Fin Réponse //////"); Serial.println("ok_place_id : "+ String(ok_place_id)); }
    
      if(ok_place_id > 0) 
      {
        Serial.println(msg_correct);
    /* DEBUG */  if(debug){Serial.println("==============================="); }
        return true; 
      }else{ 
        Serial.println(msg_echec);
    /* DEBUG */  if(debug){Serial.println("==============================="); }
        return false; 
      }
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void loop() {
    
      if(esp8266.available()) // check if the esp is sending a message 
      {
        if(esp8266.find("+IPD,"))
        {
          delay(1000);
          int connectionId = esp8266.read()-48;
          Serial.println("");  
          Serial.println("-> Nouvelle Connexion en cours");
          Serial.println("");                 
    
          Send_html("<html>  <head> <title>ESP8266 LED Control</title>", connectionId, 1000);
          Send_html("<link rel=\"icon\" type=\"image/png\" href=\"http://www.favicon.cc/favicon/695/679/favicon.png\" /> </head>", connectionId, 1000);
    
          delay(500);
          Close_Connect(connectionId);
          delay(1000);
        }
      }
    }
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    void Close_Connect(int connectionId) {
      Serial.println("");
      Serial.println("-> Fin de la connexion (ID : " + String(connectionId) + ")");
      Serial.println("////////////////////////////////////////////////////////");
      esp8266.print("AT+CIPCLOSE=" + String(connectionId) + "\r\n");
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void Send_html(String data, int connectionId, int timeout) {
     
       Com_ESP8266("AT+CIPSEND=" + String(connectionId) + "," + String(data.length()) + "\r\n", timeout, ">", "" , "Authorisation AT+CIPSEND", "Erreur AT+CIPSEND", DEBUG);
    /* DEBUG */   if(DEBUG){ Serial.println("AT+CIPSEND=" + String(connectionId) + "," + String(data.length()) + "\r\n");}
       Com_ESP8266(data, timeout, "SEND OK", "" , "Envoi data : " + String(data), "", DEBUG);
       Serial.println("---------------------------");
       delay(50);
       
    }
    Voila ce que j'obtient dans le moniteur série de l'arduino :


    ////////////////////////////////////////////////////////
    > Initialisation du module : <

    Configuration de la connexion à 9600bds
    Commande envoyé : AT+CIOBAUD=9600

    ////// Réponse du module : //////
    AT+CIOBAUD=9600


    OK

    ////// Fin Réponse //////
    ok_place_id : 20
    -> Terminé
    ============================== =
    Configuration du module en tant que Client et Serveur
    Commande envoyé : AT+CWMODE=3

    ////// Réponse du module : //////
    AT+CWMODE=3


    OK

    ////// Fin Réponse //////
    ok_place_id : 16
    -> Terminé
    ============================== =
    Connexion à Wifi_****
    Commande envoyé : AT+CWJAP="Wifi_****","****"

    ////// Réponse du module : //////
    AT+CWJAP="Wifi_****","****"

    WIFI DISCONNECT
    WIFI CONNECTED
    WIFI GOT IP

    OK

    ////// Fin Réponse //////
    ok_place_id : 88
    -> Terminé
    ============================== =
    Obtention de l'adresse IP
    Commande envoyé : AT+CIFSR

    ////// Réponse du module : //////
    AT+CIFSR

    +CIFSR:APIP,"192.168.4.1"
    +CIFSR:APMAC,"1a:fe:34:f9:2f:a 8"
    +CIFSR:STAIP,"192.168.1.25"
    +CIFSR:STAMAC,"18:fe:34:f9:2f: a8"

    OK

    ////// Fin Réponse //////
    ok_place_id : 138
    -> Terminé
    ============================== =
    Configuration du mode multi-client
    Commande envoyé : AT+CIPMUX=1

    ////// Réponse du module : //////
    AT+CIPMUX=1


    OK

    ////// Fin Réponse //////
    ok_place_id : 16
    -> Terminé
    ============================== =
    Ouverture du serveur Web sur le port 80
    Commande envoyé : AT+CIPSERVER=1,80

    ////// Réponse du module : //////
    AT+CIPSERVER=1,80

    no change

    OK

    ////// Fin Réponse //////
    ok_place_id : 33
    -> Terminé
    ============================== =

    > Initialisation terminé <
    ////////////////////////////////////////////////////////

    -> Nouvelle Connexion en cours


    Commande envoyé : AT+CIPSEND=0,57

    ////// Réponse du module : //////
    ,427:GET / HTTP/1.1
    Host: 192.168.4.1
    Connection: keep-aliveAT+CIPSEND=0,57


    OK
    >
    ////// Fin Réponse //////
    ok_place_id : 86
    Authorisation AT+CIPSEND
    ============================== =
    AT+CIPSEND=0,57


    Commande envoyé : <html> <head> <title>ESP8266 LED Control</title> </head>
    ////// Réponse du module : //////

    Recv 57 bytes

    SEND OK

    ////// Fin Réponse //////
    ok_place_id : 19
    Envoi data : <html> <head> <title>ESP8266 LED Control</title> </head>
    ============================== =
    ---------------------------

    Commande envoyé : AT+CIPSEND=0,93

    ////// Réponse du module : //////
    AT+CIPSEND=0,93


    OK
    >
    ////// Fin Réponse //////
    ok_place_id : 24
    Authorisation AT+CIPSEND
    ============================== =
    AT+CIPSEND=0,93



    ////// Réponse du module : //////

    ////// Fin Réponse //////


    ============================== =
    ---------------------------

    -> Fin de la connexion (ID : 0)
    ////////////////////////////////////////////////////////
    Du coup au final je ne reçois pas :
    <link rel=\"icon\" type=\"image/png\" href=\"http://www.favicon.cc/favicon/695/679/favicon.png\" /> </head>
    Si je rajoute plusieurs ligne d'html certaines sont envoyé correctement et d'autres non. Il me semble que c'est un problème de taille d'une chaine de caractère (mais je ne suis pas sûr)
    Dernière modification par kilouxa ; 01/05/2016 à 19h44.

Discussions similaires

  1. [Programmation] Caractère étrange ESP8266 et Arduino Uno
    Par kilouxa dans le forum Électronique
    Réponses: 5
    Dernier message: 28/04/2016, 21h30
  2. [Programmation] Probème de communication ESP8266
    Par TheWill dans le forum Électronique
    Réponses: 8
    Dernier message: 07/02/2016, 13h12
  3. [RF/Radioelec] Quelqu'un connaît-il le module wifi ESP8266 ?
    Par lpt1com2 dans le forum Électronique
    Réponses: 3
    Dernier message: 31/01/2016, 19h47
  4. Module wifi ESP8266 ne démarre plus
    Par boy30 dans le forum Électronique
    Réponses: 9
    Dernier message: 27/07/2015, 18h00
  5. problème numéro de page ds pied de page
    Par invitec0c0a7e9 dans le forum Logiciel - Software - Open Source
    Réponses: 0
    Dernier message: 09/10/2006, 15h18
Découvrez nos comparatifs produits sur l'informatique et les technologies.