Client.connect fails with static IP Address
Posted: Wed Jun 22, 2016 4:12 pm
Hello ,
I am trying to send GET request with static ip address from the esp ,
With client.begin everything works fine the esp gets ip from the DHCP table and the GET request to the server works .
When i use the client.config before client.begin the esp connects to WiFi successfully , and i can see the esp connected to router from the router clients table .
Unfortunately client.connect fails and returns 0 ( port 80 )
What can cause this ? i was thinking the port 80 blocked but its not because its works normally w/o the static ip , i also added port forwarding by trying to open the port from the esp to him self maybe i should do some other forwarding ( i think it has nothing to do with port forwarding ) ?
Any one can help please ?
I have written question on github developer's support :
https://github.com/esp8266/Arduino/issues/2182
Thanks !
I am trying to send GET request with static ip address from the esp ,
With client.begin everything works fine the esp gets ip from the DHCP table and the GET request to the server works .
When i use the client.config before client.begin the esp connects to WiFi successfully , and i can see the esp connected to router from the router clients table .
Unfortunately client.connect fails and returns 0 ( port 80 )
What can cause this ? i was thinking the port 80 blocked but its not because its works normally w/o the static ip , i also added port forwarding by trying to open the port from the esp to him self maybe i should do some other forwarding ( i think it has nothing to do with port forwarding ) ?
Any one can help please ?
Code: Select all
#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); // this is the gateway ip of the router as i see it when login to the router panel
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;
}
.....
}
I have written question on github developer's support :
https://github.com/esp8266/Arduino/issues/2182
Thanks !