-1

Im trying to get html response from server via esp01 module

when using the serial monitor in arduino studio everything works fine

here is the serial monitor output

AT+CIPSTART="TCP","aaaa.aaaa",80

CONNECT

OK
AT+CIPSEND=43


OK
> 
Recv 43 bytes

SEND OK

+IPD,227:HTTP/1.1 200 OK
Date: Sat, 19 Jan 2019 18:42:58 GMT
Server: Apache
X-Powered-By: PHP/7.2.11
Vary: Accept-Encoding,User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

10
Hello from server

0

CLOSED

but when im trying to do the same from the sketch my response is returned partially

AT+CIPSTART="TCP","aaaa.aaaa",80

CONNECT

OK
AT+CIPSEND=43


OK
> 
Recv 43 bytes

SEND OK

+IPD,227:HTTP/1.1 200 OK
Date: S

it ends on the first letter of date for some reason

here is my sketch

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX //serial for comunication with esp
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.setTimeout(5000);//dont know if i need this

  delay(10000);

  //check wifi module
  mySerial.println("AT");
  delay(1000);
  if(mySerial.find("OK"))
  {
    Serial.println("Initializing");
  }else{
    Serial.println("Error initializing");
  }
}

void loop() { // run over and over

  Serial.println("go");
mySerial.println("AT+CIPSTART=\"TCP\",\"aaaa.aaaa\",80");
delay(1000);
    while(mySerial.available()){
    Serial.write(mySerial.read());
     delay(1);
  }
mySerial.println("AT+CIPSEND=43");
delay(1000);
    while(mySerial.available()){
    Serial.write(mySerial.read());
     delay(1);
  }
mySerial.println("GET /load.php HTTP/1.1");
delay(100);
    while(mySerial.available()){
    Serial.write(mySerial.read());
     delay(1);
  }
mySerial.println("Host: aaaa.aaaa");
delay(100);
    while(mySerial.available()){
    Serial.write(mySerial.read());
     delay(1);
  }
mySerial.println("");
delay(2000);


    while(mySerial.available()){
    Serial.write(mySerial.read());
     //delay(100);
  }

delay(5000);

}

what is the reason for this behavior? how can i fix this?

  • 1
    your while (mySerial.available()) ends at the first gap between bytes. the Serial at 9600 baud is very slow – Juraj Jan 20 '19 at 20:56
  • looks like your sketch is not waiting for the data stream to finish – jsotola Jan 20 '19 at 23:25
  • @Juraj increasing baud did not help – KoSMoS Jan 21 '19 at 16:03
  • @jsotola how can i add that? – KoSMoS Jan 21 '19 at 16:04
0

found the solution i had t wait for serial input without delay function

String sendCommand(String command, const int timeout)
{
  String res = "";
  mySerial.println(command); // send the read character to the wifi
  long int time = millis();
  while( (time+timeout) > millis())
  {
    while(mySerial.available())
    {
      // The esp has data so display its output to the serial window
      char c = mySerial.read(); // read the next character.
      res+=c;
    }
  }
  //Serial.print(response);
  return res;
}
| improve this answer | |
  • It's OK to accept your own answer if it solves the problem. I think you get 15 rep for that. – VE7JRO Oct 20 '19 at 0:10

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.