I wrote the following code. The idea is to execute some AT command on my ESP-01 module. The problem is that first command is execute without problem, the second sometimes but the reply on AT+GMR is the following: AT
OK
AT+GMR
AT version:1.1/0.0(May 11 3016 18:09:57)
SDK version:1.5.ar.0
AR)�WS�TZ�j
C�j�L�AZCA�O�C�
FINE
The problem is that, after some thing that I don't understand, the formatting (maybe the baud change?) gone wrong. Then the reply of the following commands became unreadable. Any idea why it happens?
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial wifi(2,3);
void setup() {
Serial.begin(115200);
wifi.begin(115200);
sendCommand("AT\r\n", 2000);
sendCommand("AT+GMR\r\n",2000);
sendCommand("AT+CWMODE=2\r\n", 2000);
sendCommand("AT\r\n", 2000);
Serial.print("\n\nFINE");
}
void loop() {}
String sendCommand(String cmd, int timeout){
wifi.print(cmd);
return readSerial(timeout);
}
String readSerial(int timeout){
long int time = millis();
String res = "";
while( (time+timeout) > millis() ){
while(wifi.available()){
char c = wifi.read();
res += c;
}
}
if(DEBUG)
Serial.print(res);
return res;
}
String
usage is making mincemeat of your heap... – Majenko♦ Jan 22 '17 at 0:13