Skip to content

[Static IP] Code that previously worked no longer works #6024

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

Closed
rtek1000 opened this issue Apr 29, 2019 · 4 comments · Fixed by #6026
Closed

[Static IP] Code that previously worked no longer works #6024

rtek1000 opened this issue Apr 29, 2019 · 4 comments · Fixed by #6026

Comments

@rtek1000
Copy link

Hi,

Without setting a fixed address, the ESP8266 can get the IP address via DHCP, so the hello webserver example works normally. But if I add the static IP configuration, then the browser can not find the server (The serial monitor shows the static IP address correctly)

The code worked correctly until about November 2018 (it was the last time I tested it).

Were there any radical changes in the library?

Arduino IDE 1.8.9
ESP8266 2.5.0 (library installed using the Board Manager)
Windows 10 x64
NodeMCU Lolin V3

I will downgrade the library version to try to find a version that works.

Ref.: https://arduino-esp8266.readthedocs.io/en/2.5.0/esp8266wifi/station-class.html#config

Basic code:

WiFi.begin(ssid, password);
IPAddress ip(192,168,1,74);   
IPAddress gateway(192,168,1,1);   
IPAddress subnet(255,255,255,0);   
IPAddress dns(8,8,8,8); 
WiFi.config(ip, gateway, subnet, dns);

Thank you.

@rtek1000
Copy link
Author

Yep, It worked with version 2.4.0 (but what a giant package this is!)

@rtek1000
Copy link
Author

I uninstalled version 2.4.0 and installed version 2.5.0 and then IDE showed this error:

cc1plus.exe: out of memory allocating 65536 bytes

If someone else receives this error: I've seen this error before, and to resolve it just reboot the computer.

@d-a-v
Copy link
Collaborator

d-a-v commented Apr 29, 2019

It will work if you move WiFi.config() before WiFi.begin().
This is #5839 duplicate

@d-a-v d-a-v closed this as completed Apr 29, 2019
@rtek1000
Copy link
Author

Yep, It worked with version 2.5.0 now.

It looks like the problem was waiting for the connection before setting the IP address.

Thank you.

static ip

d-a-v added a commit to d-a-v/Arduino that referenced this issue Apr 30, 2019
For some reason, ip address is not propagated in a visible way for lwip2
when switching to static address (wifi.config()) *after* wifi.begin().

This patch calls lwip-v1.4's netif_set_addr() with the new ip address to set
all things up, just like it is done and right when wifi.begin() is called
after wifi.config().

Also tested when IPv6 is enabled.

fixes esp8266#5839
fixes esp8266#6024
d-a-v added a commit that referenced this issue May 1, 2019
fix switching to static address with lwip2

For some reason, ip address is not propagated in a visible way for lwip2
when switching to static address (wifi.config()) *after* wifi.begin().

This patch calls lwip-v1.4's netif_set_addr() with the new ip address to set
all things up, just like it is done and right when wifi.begin() is called
after wifi.config().

Also tested when IPv6 is enabled.

fix documentation: It is more natural to set an IP address before starting WiFi
(.. and not after dhcp has started)
fixes #5839
fixes #6024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants