title: I am having trouble sending data to website from ESP8266 (ESP-01) via Arduino with AT commands
body: <p>I am sending GET request to my website via the ESP8266 through Arduino AT commands.
  I have searched a lot on Google but couldn't come up with a good solution.</p>
  
  <p>For the first loop the code works fine but for next loop the code gives errors.
  Different type
  Here is my code:</p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  SoftwareSerial esp(2, 3); // Arduino RX:2, TX:3
  
  String WIFI_SSID = "wifi_ssid";   //your network SSID
  String WIFI_PWD  = "wifi_pass";    //your network password
  String Domain = "www.example.com";
  
  void setup() {
    Serial.begin(9600);
    Serial.println("Started....");
    esp.begin(9600);
    //esp.setTimeout(500);
    espAT("AT\r\n", 1000);
    espAT("AT+CWMODE=1\r\n", 1000);
    espAT("AT+CWJAP=\"" + WIFI_SSID + "\",\"" + WIFI_PWD + "\"\r\n", 5000);
    espAT("AT+CIPSTATUS\r\n", 1000);
    espAT("AT+CIPSTART=\"TCP\",\"" + Domain + "\",80\r\n", 5000);
  }
  
  void loop() {
    int val = rand() % 255;
  
    String request = "GET /iot/ HTTP/1.1\r\nHost: " + Domain + "\r\n\r\n";
    espAT("AT\r\n", 1000);
    espAT("AT+CIPSEND=" + String(request.length()+2) + "\r\n", 500);
    espAT(request, 200);
    String response = "";
    while (esp.available()) {
      response = esp.readStringUntil('0');
    }
  
    Serial.println(response);
    espAT("AT+CIPCLOSE\r\n", 0);
    delay(5000);
  }
  
  
  void espAT(String command, int waitFor)
  {
    esp.print(command);
    int timeMillis = millis() + waitFor;
    while (timeMillis &gt; millis()) {
      if (esp.available()) {
        Serial.write(esp.read());
      }
  
    }
  
  }
  </code></pre>