Chat freely about anything...

User avatar
By vivekvpandya
#57241 Hello,

I am trying to connect Arduino to Internet via ESP8266 module.
AT+PING command works for dev-pdemo.pantheonsite.com URL but when I try to make a GET request which returns JSON response I am getting CLOSED SEND FAIL.

Here is my code please help me.
Code: Select all#include <SoftwareSerial.h>
SoftwareSerial ESP8266_Response(2,3);
#define DEBUG true
//AT+UART_DEF=9600,8,1,0,0
void setup() {
   ESP8266_Response.begin(9600);
   Serial.begin(9600);
   
   String s1="";
   s1=sendCommand("AT\r\n",2000,DEBUG);
   Serial.print(s1);
 
   s1=sendCommand("AT+RST\r\n",2000,DEBUG);
   Serial.print(s1);
   
   s1= sendCommand("ATE0\r\n",2000,DEBUG);
   Serial.print(s1);
   
   s1=sendCommand("AT+CWMODE=1\r\n",2000,DEBUG);
   Serial.print(s1);
   
   s1=sendCommand("AT+CWJAP=\"Satyam\",\"vivekvpandya\"\r\n",5000,DEBUG);   
   Serial.print(s1);
   
   sendCommand("AT+CIPMUX=0\r\n",3000,DEBUG);
   sendCommand("AT+CIFSR\r\n",3000,DEBUG);
   
   String siteResp=sendCommand("AT+CIPSTART=\"TCP\",\"dev-pdemo.pantheonsite.io\",80\r\n",5000,DEBUG);
   Serial.print(siteResp);
   
  String cmd = "GET /dustbin_list HTTP/1.1\r\nHost:dev-pdemo.pantheonsite.io\r\n\r\n";

  ESP8266_Response.print("AT+CIPSEND=");
  ESP8266_Response.println(cmd.length());
  delay(8000);
 if(ESP8266_Response.find(">"))
  {
     String s2 = sendCommand(cmd,5000,DEBUG);
     Serial.print(s2);
  } else {
   Serial.print("Could not find >");
  }
}

void loop()
{


}

String sendCommand(String command, const int timeout, boolean debug)
{
    String response = "";
           
    ESP8266_Response.print(command); // send the read character to the esp8266
   
    long int time = millis();
   
    while( (time+timeout) > millis())
    {
      while(ESP8266_Response.available())
      {
        char c = ESP8266_Response.read(); // read the next character.
        response+=c;
      } 
    }
   
    return response;
}