WiFi - Static IP fails to connect wifi

mistergreen
Posts: 10
Joined: Tue Jan 23, 2018 4:56 pm

WiFi - Static IP fails to connect wifi

Postby mistergreen » Tue Feb 06, 2018 3:06 pm

Here's a typical Wifi config code.

Code: Select all

IPAddress ip(192,168,1,129);
IPAddress gateway(192,168,1,1);	
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

if (!WiFi.config(ip, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
WiFi.status() won't connect. It's shows a '6' - disconnect.

If I get rid of WiFi.config(), going with the localIP, Wifi can connect. So I can't do a static IP it looks like.

rcholewa@interia.pl
Posts: 1
Joined: Sat Feb 10, 2018 5:01 pm

Re: WiFi - Static IP fails to connect wifi

Postby rcholewa@interia.pl » Sat Feb 10, 2018 5:03 pm

I've got the same problem :(

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: WiFi - Static IP fails to connect wifi

Postby tele_player » Sun Feb 11, 2018 7:06 pm

It's working here.

I just added the lines above (IPAddress and WiFi.config() ) to a working WiFi HTTP server sketch, and device is properly operating with static IP. To further verify, I used various IP addresses which were definitely never assigned by my DHCP server.

What might be different? Router (Asus RT-N53) DHCP Server (Raspberry Pi Zero W running pihole), Arduino library version, ESP SDK version?

mistergreen
Posts: 10
Joined: Tue Jan 23, 2018 4:56 pm

Re: WiFi - Static IP fails to connect wifi

Postby mistergreen » Mon Feb 12, 2018 12:31 am

I have the latest Arduino Core. What do you have?
I checked on GitHub and you can hack the WiFi library to make it work but I'll wait for an official commit.

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: WiFi - Static IP fails to connect wifi

Postby tele_player » Mon Feb 12, 2018 7:31 am

It’s been a while since I installed the esp32 Arduino core, I don’t know how to check the version.

robademar
Posts: 4
Joined: Tue Feb 13, 2018 5:24 pm

Re: WiFi - Static IP fails to connect wifi

Postby robademar » Tue Feb 13, 2018 5:42 pm

I've the same problem. I downloaded again yesterday from git the libraries and ran in verbose mode. I added a println of the status code after attempting to get the ip address confirmed. I have othe devices (pc,phones, etc) with fix address in my network.
Arduino IDE 1.8.5
this is the code I used:

Code: Select all

/*
     Example of connection using Static IP
     by Evandro Luis Copercini
     Public domain - 2017
*/

#include <WiFi.h>
//#include <debug.h>

const char* ssid     = "Vodafone-roberto";
const char* password = "xxxxxxxxxxxxxx";
const char* host     = "corriere.it";
const char* url      = "/index.html";

IPAddress local_IP(192, 168, 1, 2);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

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

  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

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

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    Serial.println (WiFi.status());
    
  }

  Serial.println("");
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.print("ESP Mac Address: ");
  Serial.println(WiFi.macAddress());
  Serial.print("Subnet Mask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print("Gateway IP: ");
  Serial.println(WiFi.gatewayIP());
  Serial.print("DNS: ");
  Serial.println(WiFi.dnsIP());
}

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");
    return;
  }

  Serial.print("Requesting URL: ");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("closing connection");
}


and this is the printout

ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078a58
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 2 - STA_START
Connecting to Vodafone-roberto
.6
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:293] _eventCallback(): Event: 7 - STA_GOT_IP
.6
.6
.6
.6
.6

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: WiFi - Static IP fails to connect wifi

Postby tele_player » Wed Feb 14, 2018 4:47 pm

So, it appears to be a bug in SDK or Arduino core, introduced in newer code than I have installed.

mistergreen
Posts: 10
Joined: Tue Jan 23, 2018 4:56 pm

Re: WiFi - Static IP fails to connect wifi

Postby mistergreen » Fri Feb 16, 2018 2:52 pm

Yes, wifi.status() = 6 means disconnect. So it's constantly disconnecting.

HiJack
Posts: 1
Joined: Thu Jun 24, 2021 5:50 pm

Re: WiFi - Static IP fails to connect wifi

Postby HiJack » Thu Jun 24, 2021 5:55 pm

Hello, everibody.
I have the same problem with an ESP32 DevKit V1.
WiFi connection fails when I try to set a static ip.
Have anyone solved this?

ullixesp
Posts: 83
Joined: Wed Oct 16, 2019 9:34 am
Location: Germany

Re: WiFi - Static IP fails to connect wifi

Postby ullixesp » Fri Jun 25, 2021 8:10 am

This reminds me of the "Double-Hit" problem in lengthy discussion here: https://github.com/espressif/arduino-es ... -867874049

In short: Certain routers, the FritzBox 74XX and 75XX are the most often named one, but they are not exclusive, require that you call `WiFi.begin()` twice in order to make a single connection.

Do at least verify that your situation is different!

This specific issue has been overcome - I don't say solved - by using ESP-core 1.0.6 instead of 1.0.4. The disadvantage is that a connection now takes >2sec, while before the complete double-hitting was completed in under 0.5sec.

Something is still not right, I think.

Who is online

Users browsing this forum: Google Adsense [Bot] and 35 guests