Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By miladbrave
#73032 hi.i paired to esp826-01 with each other as server-client and now i want to send date from server to client but when i want to send data just i receive "A"!!!please help me to solve this problem
server:
Code: Select all#include <SoftwareSerial.h>

SoftwareSerial ESP8266(10, 11);//10==>TX , 11==>RX
String mychar;//for store the esp8266 serial input

int i=0;
void setup()
{
  Serial.begin(9600);
  ESP8266.begin(9600);
  initESP8266();
}

void loop()
{
  send();     
   mychar = ESP8266.readString();
   WaitForESP8266(1000);
   if(mychar.length()>1)
   {
     int colonPosition = mychar.indexOf(':');
     switch(mychar.charAt(colonPosition+1)){
     if ( mychar.charAt(colonPosition+1) == "ok")
      {
       i++;
       ESP8266.println(i);
       WaitForESP8266(1000);
       if(i==2){
        i=0;
   
      }
     }
    } 
   }   
}

void initESP8266()
{   
  SendToESP8266("AT+RST");
  WaitForESP8266(1000);
  SendToESP8266("AT+CWMODE=3");
  WaitForESP8266(1000);
  SendToESP8266("AT+CIPMUX=1");
  WaitForESP8266(1000);
  SendToESP8266("AT+CIPSERVER=1,8888");
  WaitForESP8266(1000);   
}
 
void SendToESP8266(String commande)

  ESP8266.println(commande);
}

void WaitForESP8266(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);   

}

void send(void)
{
SendToESP8266("AT+CIPSEND=0,1");
}