Get Request not working
Posted: Wed Aug 12, 2015 7:55 am
Hi, I am using a ESP8266-01 with the following code. I am able to send the ESP8266 response to an OLED display to ready. At this point I am able to get an IP address and connected to the server (linked), but my GET request doesn't seems to return anything. Am I constructing my GET correctly?
Code: Select all
#include <Adafruit_ssd1306syp.h>
#define SDA_PIN A4
#define SCL_PIN A5
int led = 13;
Adafruit_ssd1306syp display(SDA_PIN, SCL_PIN);
void setup()
{
display.initialize();
display.clear();
display.setCursor(0, 0);
display.println("Connect TX..");
display.update();
pinMode(led, OUTPUT);
delay(5000);
Serial.begin(115200);
// Set up Wifi
Serial.println("AT");
delay(800);
if (Serial.find("OK")) {
display.println("WIFI Ok:");
display.update();
Serial.println("AT+CIFSR");
delay(800);
display.println(Serial.readString());
display.update();
delay(2000);
display.clear();
display.update();
} else {
display.println("WIFI Failed to initialize");
}
}
void loop()
{
Serial.println("AT+CIPMUX=1");
delay(300);
getResponse();
Serial.println("AT+CIPSTART=4,\"TCP\",\"192.168.1.250\",8081");
delay(2000);
getResponse();
Serial.println("AT+CIPSEND=4,400");
delay(2000);
getResponse();
String data;
data = "GET /index.html HTTP/1.1\r\n";
data += "Host: 192.168.1.250 \r\n";
data += "Content-Length: 400 \r\n";
data += "content-type:application/x-www-form-urlencoded;charset=utf-8\r\n";
Serial.println(data);
delay (2000);
getResponse();
delay (2000);
Serial.println("AT+CIPCLOSE=4");
getResponse();
delay(5000);
display.setCursor(0, 0);
}
void getResponse() {
display.clear();
display.update();
display.setCursor(0, 0);
display.println(Serial.readString());
display.update();
Serial.flush();
}