Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi.localIP() returns 255.255.255.255 after connect #4732

Closed
SvenArke opened this issue Jan 18, 2021 · 14 comments · Fixed by #6659
Closed

WiFi.localIP() returns 255.255.255.255 after connect #4732

SvenArke opened this issue Jan 18, 2021 · 14 comments · Fixed by #6659
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved

Comments

@SvenArke
Copy link

Hardware:

Board: ESP32-WROOM-32
Core Installation version: 1.0.4 & 1.0.5 rc6
IDE name: Arduino 1.8.13

Description:

With 1.0.6 - any version i get always 255.255.255.255 as IP address from WiFi.localIP()

Code:
log_i("Connected to: ");
log_i( "%s", WiFi.SSID() );
log_i( "%s", WiFi.localIP().toString().c_str() );

Core 1.0.4 returns:
[I][Test-2020.ino:85] setup(): Connected to:
[I][Test-2020.ino:86] setup(): NET1
[I][Test-2020.ino:87] setup(): 192.168.0.169

Core 1.0.5 rc1 to rc6 returns:
[I][Test-2020.ino:85] setup(): Connected to:
[I][Test-2020.ino:86] setup(): NET1
[I][Test-2020.ino:87] setup(): 255.255.255.255

Tested all rc versions - no luck. Code runs only on 1.04 flawless. Any suggestions ?

Thank you !

@SvenArke
Copy link
Author

Found the problem !
Sketch contained a bugfix for "hostname not sent via dhcp" - >#2537

WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);

This kills WiFi.localIP() on Core 1.0.5 rc6 ...

@me-no-dev
Copy link
Member

done :) thanks for finding this

frewie added a commit to frewie/SensESP that referenced this issue May 5, 2021
When using this workaround, WiFi.localIP() returns 255.255.255.255 after a successful wifi connect and the signal k server can't be found with mdns.  
I tested that for the ESP8266 v2 with platform version Espressif 8266 v2.6.3

see here: espressif/arduino-esp32#4732
@hutje
Copy link

hutje commented Dec 13, 2021

When will the be fixed?

@gerab
Copy link

gerab commented Dec 21, 2021

wow, surprisingly it's still there!

@thomastech
Copy link

Yes, I ran into this bug too. As mention before, no problem if I remove the bugfix for "hostname not sent via dhcp" - >#2537. Is that the final/only solution? Hoping for some words of wisdom from the devs.

@VojtechBartoska
Copy link
Contributor

@me-no-dev Can you please test this again?

@YordanYanakiev
Copy link

Same issue here in all around the projects. :'(

@VojtechBartoska VojtechBartoska added the Area: BT&Wifi BT & Wifi related issues label Apr 20, 2022
@VojtechBartoska
Copy link
Contributor

@YordanYanakiev tested on v2.0.3-rc1?

@YordanYanakiev
Copy link

yes, also the previous ones downto 2.0.0

@SuGlider
Copy link
Collaborator

This issue is linked to #6610

@SuGlider SuGlider self-assigned this Apr 21, 2022
@SuGlider
Copy link
Collaborator

The main issue is that <lwip/inet.h> declares #define INADDR_NONE IPADDR_NONE and it includes <lwip/ip4_addr.h> that declares #define IPADDR_NONE ((u32_t)0xffffffffUL) (IP 255.255.255.255)

When <lwip/inet.h> is included, it makes the Arduino declaration of "IPAddress INADDR_NONE(0,0,0,0)" invalid.

This process occurs in all the WiFi/ETH Arduino Libraries.

@SuGlider SuGlider added Status: In Progress Issue is in progress and removed Status: Test needed Issue needs testing labels Apr 22, 2022
@me-no-dev me-no-dev removed their assignment Apr 27, 2022
@VojtechBartoska VojtechBartoska moved this to Under investigation in Arduino ESP32 Core Project Roadmap Apr 28, 2022
@SuGlider
Copy link
Collaborator

This is the test case used to verify/test this issue and PR Fix:

#include <Arduino.h>
#include <WiFi.h>

void setup() {
  WiFi.begin("Your_SSID", "Your_wifi_password");
  String nodeName = "NODE-" + WiFi.macAddress();
  nodeName.replace(":", "");
  char _nodeName[20]; nodeName.toCharArray(_nodeName, 20);
  WiFi.setHostname(_nodeName);
  WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
  WiFi.mode(WIFI_STA);

  log_i("Connected to: ");
  log_i( "%s", WiFi.SSID() );
  log_i( "%s", WiFi.localIP().toString().c_str() );
  log_i( "%s", WiFi.getHostname());
}

void loop() {
}

Repository owner moved this from Under investigation to Done in Arduino ESP32 Core Project Roadmap Apr 29, 2022
me-no-dev pushed a commit that referenced this issue Apr 29, 2022
Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for #6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes #6610
fixes #6247
fixes #4732
@VojtechBartoska VojtechBartoska added Status: Solved and removed Status: In Progress Issue is in progress labels Apr 29, 2022
Jason2866 added a commit to tasmota/arduino-esp32 that referenced this issue Apr 29, 2022
Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for espressif#6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes espressif#6610
fixes espressif#6247
fixes espressif#4732

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
@rysiulg
Copy link

rysiulg commented May 4, 2022

In This arduino libraries bugs and workaround for hostname on esp32 ...
any version i get always 255.255.255.255 as IP address from WiFi.localIP()

use:
WiFi.config(((u32_t)0x0UL),((u32_t)0x0UL),((u32_t)0x0UL));
or
#ifdef INADDR_NONE
#undef INADDR_NONE
#define INADDR_NONE ((u32_t)0x0UL)
#endif
WiFi.config(INADDR_NONE ,INADDR_NONE ,INADDR_NONE );

to get config definitions of ip 0.0.0.0 and be able to obtain dhcp values.
By default arduino resolves definitions INADDR_NONE -> IPADDR_NONE -> ((u32_t)0xffffffff0UL) which gives 255.255.255.255 ip and dhcp resolution doesn't work.

best regards

Hardware:

Board: ESP32-WROOM-32 Core Installation version: 1.0.4 & 1.0.5 rc6 IDE name: Arduino 1.8.13

Description:

With 1.0.6 - any version i get always 255.255.255.255 as IP address from WiFi.localIP()

Code: log_i("Connected to: "); log_i( "%s", WiFi.SSID() ); log_i( "%s", WiFi.localIP().toString().c_str() );

Core 1.0.4 returns: [I][Test-2020.ino:85] setup(): Connected to: [I][Test-2020.ino:86] setup(): NET1 [I][Test-2020.ino:87] setup(): 192.168.0.169

Core 1.0.5 rc1 to rc6 returns: [I][Test-2020.ino:85] setup(): Connected to: [I][Test-2020.ino:86] setup(): NET1 [I][Test-2020.ino:87] setup(): 255.255.255.255

Tested all rc versions - no luck. Code runs only on 1.04 flawless. Any suggestions ?

Thank you !

@SuGlider
Copy link
Collaborator

SuGlider commented May 4, 2022

In This arduino libraries bugs and workaround for hostname on esp32 ... any version i get always 255.255.255.255 as IP address from WiFi.localIP()

use: WiFi.config(((u32_t)0x0UL),((u32_t)0x0UL),((u32_t)0x0UL)); or #ifdef INADDR_NONE #undef INADDR_NONE #define INADDR_NONE ((u32_t)0x0UL) #endif WiFi.config(INADDR_NONE ,INADDR_NONE ,INADDR_NONE );

to get config definitions of ip 0.0.0.0 and be able to obtain dhcp values. By default arduino resolves definitions INADDR_NONE -> IPADDR_NONE -> ((u32_t)0xffffffff0UL) which gives 255.255.255.255 ip and dhcp resolution doesn't work.

best regards

Hardware:

Board: ESP32-WROOM-32 Core Installation version: 1.0.4 & 1.0.5 rc6 IDE name: Arduino 1.8.13

Description:

With 1.0.6 - any version i get always 255.255.255.255 as IP address from WiFi.localIP()
Code: log_i("Connected to: "); log_i( "%s", WiFi.SSID() ); log_i( "%s", WiFi.localIP().toString().c_str() );
Core 1.0.4 returns: [I][Test-2020.ino:85] setup(): Connected to: [I][Test-2020.ino:86] setup(): NET1 [I][Test-2020.ino:87] setup(): 192.168.0.169
Core 1.0.5 rc1 to rc6 returns: [I][Test-2020.ino:85] setup(): Connected to: [I][Test-2020.ino:86] setup(): NET1 [I][Test-2020.ino:87] setup(): 255.255.255.255
Tested all rc versions - no luck. Code runs only on 1.04 flawless. Any suggestions ?
Thank you !

@rysiulg - The PR #6659 works for Arduino Core 2.0.3 onward.
In your post you say it doesn't work for Arduino 1.0.4 and 1.0.5, right?
In that case I suggest not using INADDR_NONE within these core versions, as you said.

INADDR_NONE can be replaced by IPAddress(0,0,0,0) or (u32_t)0UL as you wrote.

Jason2866 added a commit to tasmota/arduino-esp32 that referenced this issue Aug 11, 2022
* Tasmota changes

* Fixes INADDR_NONE  (espressif#6659) (#136)

Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for espressif#6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes espressif#6610
fixes espressif#6247
fixes espressif#4732

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>

* Update README.md

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved
Projects
Development

Successfully merging a pull request may close this issue.

9 participants