0

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;
 }
1

The problem was about high baud for SoftwareSerial. Changing it to 9600 the problem disappears.

0

 esp connections

Take a look at the connections check the all the connections properly i also had the same problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.