SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By shivgatech
#189533
I'm using this library https://github.com/sparkfun/SparkFun_ES ... no_Library alongside a ESP8266 and Teensy. I'd like to make simple HTTP GET requests and print the plain text response to the serial monitor.

Below is the code I have so far. I've confirmed from my server's end that the request is coming through over the web. However, all I get in response from client.read() is '13'. You can see a sample of the actual server response at http://minitron.shivspatel.com/plain

Any ideas?
Code: Select all
#include <SoftwareSerial.h>
#include <SparkFunESP8266WiFi.h>

const char mySSID[] = "testnetwork";
const char myPSK[] = "password";

String server = "minitron.shivspatel.com";
String httpHeader = "GET /plain HTTP/1.1\r\nHost: minitron.shivspatel.com\r\nConnection: close\r\n\r\n";

void setup() 
{
  int status;
  Serial.begin(9600);
  status = esp8266.begin();
  if (status <= 0)
  {
    Serial.println(F("Unable to communicate with shield. Looping"));
    while(1) ;
  }
  esp8266.setMode(ESP8266_MODE_STA); // Set WiFi mode to station
  if (esp8266.status() <= 0) // If we're not already connected
  {
    if (esp8266.connect(mySSID, myPSK) < 0)
    {
      Serial.println(F("Error connecting"));
      while (1) ;
    }    
  }  
  Serial.print(F("Station IP address: "));
  Serial.println(esp8266.localIP());
  Serial.println(F("Press any key to make a request..."));
}

void loop()
{
  if (Serial.available())
  {
    httpGet();
    while (Serial.available())
      Serial.read();
  }
}

void httpGet()
{
  ESP8266Client client;  
  if (client.connect(server, 80) <= 0)
  {
    Serial.println(F("Failed to connect to minitron.shivspatel.com"));
    return;
  }
  Serial.println(F("Making HTTP GET request to minitron.shivspatel.com"));

  client.print(httpHeader);

  Serial.println("Response:");
  Serial.println(client.read());
  
  if (client.connected())
    client.stop();
}