I have an problem with sending longer commands to ESP8266 with SerialPort Monitor. I'm using Arduino Uno and on hardware serial everything is fine, but when I trying to send for example AT+CIPSEND command by SoftwareSerial, there is garbage response and garbage command which is going to ESP8266.
Garbage AT+CIPSEND looks like:
OK
A%AMEŐ‰5•bj
busy p...
no ip
How can I repair that without buying Arduino Mega which has more hardware serial ports?
My program:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3
String dataStr = "";
int number;
void setup()
{
Serial.begin(57600);
esp8266.begin(57600); // your esp's baud rate might be different
}
void loop()
{
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available()>0)
{
char c = esp8266.read(); // read the next character.
// dataStr = dataStr + c;
Serial.write(c);
/* if (c == 13) {
number = dataStr.indexOf('OK');
if (number>0) {
Serial.println("\n yolo");
}
dataStr = "";
} */
}
}
if(Serial.available())
{
// the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
// In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
// but we want to send everything at the same time.
delay(20);
String command="";
while(Serial.available()) // read the command character by character
{
// read one character
command+=(char)Serial.read();
}
esp8266.println(command); // send the read character to the esp8266
}
}
I hope that someone can help.