title: ESP8266 - Response from server gets cut
body: <p>I'm using an ESP8266 connected to an Arduino one via SoftwareSerial to make a post request to a node web server. The ESP8266 sends some data to the server and it should get back other data. The data arrives at the server correctly, but the response from the server is incomplete (it gets cut each time in a different way) and I can't access the body of the response from my Arduino sketch. The server sends the response correctly, as i've checked with hurl.</p>
  
  <p>This is my code:</p>
  
  <pre><code>#include "SoftwareSerial.h"
  
  String ssid ="ssid";
  String password="pwd";
  SoftwareSerial esp(3, 2);// RX, TX
  
  ESP8266_Simple wifi(3,2);
  
  String data;
  String server = "server"; 
  String uri = "uri";
  
  String token = "token";
  
  float temp_set = 15; //standard values
  float temp_rec = 15;
  String temp_set_s;
  String temp_rec_s;
  
  int activate = LED_BUILTIN; //pin for relay
  int button_up = 4;
  int button_down = 5;
  
  unsigned long time;
  
  //LCD
  #include &lt;LiquidCrystal.h&gt;
  LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
  
  // DHT11
  #include &lt;Adafruit_Sensor.h&gt;
  #include &lt;DHT.h&gt;
  #include &lt;DHT_U.h&gt;
  #define DHTPIN 6
  #define DHTTYPE DHT22    
  DHT_Unified dht(DHTPIN, DHTTYPE);
  
  void setup() {
    esp.begin(9600);
    Serial.begin(9600);
    delay(10);
  
    reset();
    connectWifi();
  
    pinMode(activate, OUTPUT);
    pinMode(button_up, INPUT);
    pinMode(button_down, INPUT);
  
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
  
    //DHT setup
    dht.begin();
    sensor_t sensor;
  
    delay(500);
  }
  
  //reset the esp8266 module
  void reset() {
      esp.println("AT+RST");
      delay(1000);
      if(esp.find("OK") ) Serial.println("Module Reset");
  
  }
  
  //connect to your wifi network
  void connectWifi() {
      String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
  
      esp.println(cmd);
  
      delay(4000);
  
      if(esp.find("OK")) {
          Serial.println("Connected!");
          time = millis();
      } else {
          connectWifi();
          Serial.println("Cannot connect to wifi"); 
      }
  } 
  
  
  void loop () {
  
    //temp_rec_s = String(temp_rec);
    //temp_set_s = String(temp_set);
    //data = "tempRec=" + temp_rec_s + "&amp;tempSet=" + temp_set_s;
    //httppost();
  
    // dht data
    sensors_event_t event;  
    dht.temperature().getEvent(&amp;event);
    temp_rec = event.temperature; 
  
    //temp_rec_s = String(temp_rec);
    //temp_set_s = String(temp_set);
    //data = "tempRec=" + temp_rec_s + "&amp;tempSet" + temp_set_s;
  
  
    // to activate
    if(temp_set &lt; temp_rec){
      digitalWrite(activate, LOW);
    } else{
      digitalWrite(activate, HIGH);
    }
  
    //function for physical buttons
    if((digitalRead(button_up)) == HIGH){
      temp_set = temp_set + 0.5;
      delay(100);
    }
    if((digitalRead(button_down)) == HIGH){
      temp_set = temp_set - 0.5;
      delay(100);
    }
  
    //shows temperature on display
    lcd.setCursor(0, 0);
    lcd.print("T rec " + String(temp_rec));
  
    //shows temperature on display
    lcd.setCursor(0, 1);
    lcd.print("T set " + String(temp_set));
  
    temp_rec_s = String(temp_rec);
    temp_set_s = String(temp_set);
    data = "tempRec=" + temp_rec_s + "&amp;tempSet=" + temp_set_s + "&amp;token=" + token;
    //Serial.println(data);
    if((millis() - time) &gt;= 10000){
      httppost();
    }
  
  
    delay(200);
  }
  
  void httppost () {
      esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.
  
      if(esp.find("OK")) {
          Serial.println("TCP connection ready");
      } 
      delay(1000);
  
      String postRequest =
      "POST " + uri + " HTTP/1.0\r\n" +
      "Host: " + server + "\r\n" +
      "Accept: *" + "/" + "*\r\n" +
      "Content-Length: " + data.length() + "\r\n" +
      "Content-Type: application/x-www-form-urlencoded\r\n" +
      "\r\n" + data;
  
      String sendCmd = "AT+CIPSEND="; //determine the number of caracters to be sent.
  
      esp.print(sendCmd);
      esp.println(postRequest.length());
  
      Serial.println(postRequest);
  
      delay(500);
  
      if(esp.find("&gt;")) {
          Serial.println("Sending.."); 
          esp.print(postRequest);
  
          String tmpResp = esp.readString();
          Serial.println(tmpResp);
  
          if(esp.find("SEND OK")) { 
              Serial.println("Packet sent");
  
              while(esp.available()) {
                  String line = esp.readString();
                  Serial.print(line);
              }
  
              // close the connection
              esp.println("AT+CIPCLOSE");
  
          }
      }
  } 
  </code></pre>