Skip to content

Client.connect fails with static IP Address #2182

@stavBodik

Description

@stavBodik

Hardware

Hardware: ?ESP-12E?
Core Version: ? How do i find it (^^) ? ?

Description

Connecting with WiFiClient.connect fails when connected to router with static ip address,
When connected trough DHCP works fine .
Port 80 forward configured .

Settings in IDE

Module: ?Generic ESP8266 Module?
Flash Size: ?512K (64K SPIFFS)?
CPU Frequency: ?80Mhz?
Flash Mode: ?dio?
Flash Frequency: ?40Mhz?
Upload Using: ?SERIAL?
Reset Method: ?nodemcu?

Sketch

#include <ESP8266WiFi.h>
#include <SPI.h>

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

IPAddress ip(192, 168, 0, 20);    
IPAddress gateway(192,168,1,1); 
IPAddress subnet(255,255,255,0); 

void setup() {

  String Statuses[] =  { "WL_IDLE_STATUS=0", "WL_NO_SSID_AVAIL=1", "WL_SCAN_COMPLETED=2", "WL_CONNECTED=3", "WL_CONNECT_FAILED=4", "WL_CONNECTION_LOST=5", "WL_DISCONNECTED=6"};

  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.config(ip, gateway, subnet);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.println(Statuses[WiFi.status()]);
  }

  Serial.println("WiFi connected");  

}


void loop() {
  delay(5000);

  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 error");
    Serial.println(client.connect(host, httpPort));
    return;
  }

.....
} 

Debug Messages

Connecting to ********
wifi evt: 0
wifi evt: 3
WL_CONNECTED=3
WiFi connected
connecting to ********
[hostByName] request IP for: ********
[hostByName] Host: ******** lookup error: -5!
connection failed error
[hostByName] request IP for: ********
[hostByName] Host: ******** lookup error: -5!
0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions