Post topics, source code that relate to the Arduino Platform

User avatar
By kwajo
#35780 I've been messing with the board ESP8266 for a while now and it's caused em all sorts of grief. In the last two days this has manifested itself by sending me empty messages when I try sending get requests to adafruit's wifi test page. By empty I mean I would get a prompt telling me I was connecting to http://www.adafruit.com and then another prompt after an empty line saying closing connection. Both these prompts are just getting printed to the serial monitor for my benefit and I don't believe have significance in the actual transfer of data.
Today I changed something and I've gotten to the stage where I'm receiving a response from the wifi module in html. I pasted the html into a document to see what the message was and this is what I got http://imgur.com/4xQ0tYw . Does anyone know what is wrong. It claims I need a valid host header but I was under the impression that I provided them with one.

Here is my code for reference.
Code: Select all/*
 *  Simple HTTP get webclient test
 */
 
#include <ESP8266WiFi.h>
 
const char* ssid     = "ii0C3B5Eprimary";
const char* password = "8ce0fcc6";
 
const char* host = "www.adafruit.com";
 
void setup() {
  Serial.begin(115200);
  delay(100);
 
  // 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 = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  client.println("GET /testwifi/index.html http/1.1");
  delay(500);
 
  // 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");
}