I am trying to get response from my web server(Raspberry) via HTTP GET method, but I don't see any reply on my client serial monitor (ESP).
#include <ESP8266WiFi.h>
const char* ssid = "Pi_AP";
const char* password = "Raspberry";
const char* host = "data.sparkfun.com";
const char* streamId = "1/";
IPAddress server(192, 168, 2, 1);
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 8000;
if (!client.connect(server, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/start/";
url += streamId;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: 192.168.2.1" + "\r\n\r\n");
//"Host: " + host + "\r\n" +
//"Connection: close\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
My request successfully reach the server because function on my server is executed.
Web server is working correctly I test it from terminal
$ curl -i -X GET http://192.168.2.1:8000/start/1/
HTTP/1.1 200 OK
Server: gunicorn/19.3.0
Date: Sun, 08 Nov 2015 22:59:59 GMT
Connection: close
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
<!DOCTYPE html>
<html lang="en">
<head>
.......
Output from my serial monitor is here:
Can you help me? Why I don't see response from server in my serial monitor?