So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By AverageGuy
#91203 Here's my version of the code. It didn't like going to the site in the example and neither did Firefox so I wrote a simple php script. It works just fine from wget, curl and browsers but not the esp8266 I have three ESP8266-01 parts and none of them work so I've ruled out a hardware issue I think.
Here's the output:
Code: Select allConnecting to h*****
........
WiFi connected
IP address:
192.168.1.102
connecting to 192.168.1.100/php1.php:80
connection failed
connecting to 192.168.1.100/php1.php:80
connection failed
connecting to 192.168.1.100/php1.php:80
connection failed

Code: Select all/*
    This sketch establishes a TCP connection to a "quote of the day" service.
    It sends a "hello" message, and then prints received data.
*/

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "hxxxxxx"
#define STAPSK  "2xxxxxxx"
#endif

const char* ssid     = STASSID;
const char* password = STAPSK;

const char* host = "192.168.1.100/php1.php";
/* rustburg.us/php1.php */
const uint16_t port = 80;

void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
     would try to act as both a client and an access-point and could cause
     network-issues with your other WiFi-devices on your WiFi-network. */
  WiFi.mode(WIFI_STA);
  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() {
  static bool wait = false;

  Serial.print("connecting to ");
  Serial.print(host);
  Serial.print(':');
  Serial.println(port);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    delay(30000);
    return;
  }

  // This will send a string to the server
  Serial.println("sending data to server");
  if (client.connected()) {
    client.println("hello from ESP8266");
  }

  // wait for data to be available
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 15000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      delay(60000);
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  Serial.println("receiving from remote server");
  // not testing 'client.connected()' since we do not need to send data here
  while (client.available()) {
    char ch = static_cast<char>(client.read());
    Serial.print(ch);
  }

  // Close the connection
  Serial.println();
  Serial.println("closing connection");
  client.stop();

  if (wait) {
    delay(300000); // execute once every 5 minutes, don't flood remote service
  }
  wait = true;
}


It looks like it takes about 6 seconds to fail. I have tried to connect to a couple of systems on the lan.

Any help would be appreciated
Thsnks,
Jim