Chat freely about anything...

User avatar
By Dusk
#49486 Hi everyone ! :D

I hope someone can help me.. So.
I'd like to "talk" with my ESP8266-01, but when i write something in the "Serie Monitor" for my Arduino Uno, i can write commands like : "AT" (Without "") but when i tape enter, nothing appear ! So ..

My connections :

Image


That's my code (French yeah :mrgreen: ) :

Code: Select all#include <SoftwareSerial.h>
#define DEBUG true
    SoftwareSerial ESP8266(10, 11);

    String NomduReseauWifi = "Bbox-E78"; // Garder les guillements
    String MotDePasse      = "4C5ACAE33AAE4F6D67F1E"; // Garder les guillements
    String NameESP = "ESP8267";
    String mdpEsp = "123";
    String channel = "3";
    String WPA_PSK = "2";

    /****************************************************************/
    /*                             INIT                             */
    /****************************************************************/
    void setup()
    {
      Serial.begin(9600);
     
      ESP8266.begin(115200);
      envoieAuESP8266("AT+RST");
      envoieAuESP8266("AT+CIOBAUD=9600");
      recoitDuESP8266(4000);
 
     
      ESP8266.begin(9600); 
      /*while(1){initESP8266();}*/
      initESP8266();
    }
    /****************************************************************/
    /*                        BOUCLE INFINIE                        */
    /****************************************************************/
    void loop()
    {
       while(ESP8266.available())
       {   
         Serial.println(ESP8266.readString());
       }   

       if(ESP8266.find("+IPD,"))
        {
           delay(1000);
           int connectionId = ESP8266.read()-48; // subtract 48 because the read() function returns
                                                 // the ASCII decimal value and 0 (the first decimal number) starts at 48
       
           String webpage = "<h1>Hello</h1>&lth2>World!</h2><button>LED1</button>";
       
           String cipSend = "AT+CIPSEND=";
           cipSend += connectionId;
           cipSend += ",";
           cipSend +=webpage.length();
           cipSend +="\r\n";
       
           
           envoieAuESP8266(cipSend);
           envoieAuESP8266(webpage);
           
           webpage="<button>LED2</button>";
       
           cipSend = "AT+CIPSEND=";
           cipSend += connectionId;
           cipSend += ",";
           cipSend +=webpage.length();
           cipSend +="\r\n";
           
       
           envoieAuESP8266(cipSend);
           envoieAuESP8266(webpage);
       
           String closeCommand = "AT+CIPCLOSE=";
           closeCommand+=connectionId; // append connection id
           closeCommand+="\r\n";
       
           envoieAuESP8266(closeCommand);
        }
    }
    /****************************************************************/
    /*                Fonction qui initialise l'ESP8266             */
    /****************************************************************/
    void initESP8266()
    { 

     
      Serial.println("**********************************************************"); 
      Serial.println("**************** DEBUT DE L'INITIALISATION ***************");
      Serial.println("**********************************************************"); 
      envoieAuESP8266("AT");
      recoitDuESP8266(2000);
      envoieAuESP8266("AT+RST");
      recoitDuESP8266(5000);
      envoieAuESP8266("AT+CWSAP?");
      Serial.println("**********************************************************");
      envoieAuESP8266("AT+CWMODE=3");
      recoitDuESP8266(5000);
      Serial.println("**********************************************************");
      envoieAuESP8266("AT+CWJAP=\""+ NomduReseauWifi + "\",\"" + MotDePasse +"\"");
      recoitDuESP8266(10000);
      Serial.println("**********************************************************");
      envoieAuESP8266("AT+CIFSR");
      recoitDuESP8266(1000);
      Serial.println("**********************************************************");
      envoieAuESP8266("AT+CIPMUX=1");   
      recoitDuESP8266(1000);
      Serial.println("**********************************************************");
      envoieAuESP8266("AT+CIPSERVER=1,80");
      recoitDuESP8266(1000);
      Serial.println("**********************************************************");
      recoitDuESP8266(500);
      Serial.println("***************Config*************************");
      envoieAuESP8266("AT+CWSAP=\""+ NameESP + "\",""\"" + mdpEsp + "\"," + channel + "," + WPA_PSK +"");
      recoitDuESP8266(1000);
      Serial.println("**************Regarde si bien configure**********************");
      envoieAuESP8266("AT+CWSAP?");
      recoitDuESP8266(500);
      Serial.println("**************************DHCP****************************");
      envoieAuESP8266("AT+CWDHCP=2,1");
      recoitDuESP8266(500);
      Serial.println("**********************************************************");
      Serial.println("***************** INITIALISATION TERMINEE ****************");
      Serial.println("**********************************************************");
      Serial.println(""); 
    }

    /****************************************************************/
    /*        Fonction qui envoie une commande à l'ESP8266          */
    /****************************************************************/
    void envoieAuESP8266(String commande)
    { 
      ESP8266.println(commande);
    }
    /****************************************************************/
    /*Fonction qui lit et affiche les messages envoyés par l'ESP8266*/
    /****************************************************************/
    void recoitDuESP8266(const int timeout)
    {
      String reponse = "";
      long int time = millis();
      while( (time+timeout) > millis())
      {
        while(ESP8266.available())
        {
          char c = ESP8266.read();
          reponse+=c;
        }
      }
      Serial.print(reponse);   
    }



All responses :

Code: Select all
**********************************************************
**************** DEBUT DE L'INITIALISATION ***************
**********************************************************
AT

OK
AT+RST

OK
WIFI DISCONNECT
bBÖ†øRcjþÈÉ¥SNÊÉ¥SNÂI�ë"B„n"jˆBĵ

Ai-Thinker Technology Co.,Ltd.

invalid
WIFI CONNECTED
WIFI GOT IP
**********************************************************
AT+CWSAP?
+CWSAP:"ESP8266","123",1,0,4

OK
AT+CWMODE=3

OK
**********************************************************
AT+CWJAP="Bbox-E78","4C5ACAE33AAE4F6D67F1E"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP

OK
**********************************************************
AT+CIFSR
+CIFSR:APIP,"192.168.4.1"
+CIFSR:APMAC,"5e:cf:7f:84:86:d2"
+CIFSR:STAIP,"192.168.1.87"
+CIFSR:STAMAC,"5c:cf:7f:84:86:d2"

OK
**********************************************************
AT+CIPMUX=1

OK
**********************************************************
AT+CIPSERVER=1,80

OK
**********************************************************
***************Config*************************
AT+CWSAP="ESP8267","123",3,2

[color=#FF0000]ERROR[/color]
**************Regarde si bien configure**********************
AT+CWSAP?
+CWSAP:"ESP8266","123",1,0,4

OK
**************************DHCP****************************
AT+CWDHCP=2,1

OK
**********************************************************
***************** INITIALISATION TERMINEE ****************
**********************************************************




Configuration are OK, that's work ! But when i try to enter command, don't work, don't write anything ..
Configuration not ok to the : ERROR (Config)
I tried to work with ESPlorer, i can connect, but nothing more ! :(


So, if you can help me, i'll be very happy ! And sorry for my english if it's not good.

Thanks you ! :)
User avatar
By Dusk
#49660 Ok

Found something to solve it :
add

Code: Select all        if (ESP8266.available()) {
          Serial.write(ESP8266.read());
        }
       
        if (Serial.available()) {
          ESP8266.write(Serial.read());
        }


in function loop.