-->
Page 1 of 3

WiFi Client doesn't work

PostPosted: Tue Sep 22, 2015 6:54 pm
by zioax
I'm tring to make a GET request to a php file running in a localhost machine, but without success.
This is the code:
Code: Select all/*
 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.
 *
 *  You need to get streamId and privateKey at data.sparkfun.com and paste them
 *  below. Or just customize this script to talk to other HTTP servers.
 *
 */

#include <ESP8266WiFi.h>

const char* ssid     = "ssid";
const char* password = "password";

const char* host = "192.168.1.10";

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());
}



void loop() {
  delay(5000);
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  client.connect(host, httpPort);
 
  // We now create a URI for the request
  String url = "/wa/examples/wa1.php";


 

 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +

               "Host: " + host + "\r\n" +
               "Accept: */*\r\n" +
               "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" +
               "\r\n"
               
               );
  delay(100);
 
  // Read all the lines of the reply from server and print them to Serial

}

The code work well from the browser, so it isn't a server side issue

Re: WiFi Client doesn't work

PostPosted: Tue Sep 22, 2015 7:26 pm
by martinayotte
At first look, I don't any thing special here.

Code: Select all  // Read all the lines of the reply from server and print them to Serial


Instead of this comment, do you have some code which really print the reply ?
What is the content of this reply ?

Re: WiFi Client doesn't work

PostPosted: Tue Sep 22, 2015 7:31 pm
by SoC
what is the code you are using from the browser?

Re: WiFi Client doesn't work

PostPosted: Tue Sep 22, 2015 7:34 pm
by zioax
This is a modified sketch, but also with the original one it doesn't work. It just don't receive any reply