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.Config() setting wrong IP Address #540

Closed
brycebot opened this issue Jul 28, 2017 · 7 comments
Closed

WiFi.Config() setting wrong IP Address #540

brycebot opened this issue Jul 28, 2017 · 7 comments
Labels
Type: For reference Common questions & problems

Comments

@brycebot
Copy link

The following issue is present for me when using WiFi.config.
Code:


IPAddress chipIP = (192,168,10,22); 
WiFi.config(chipIP,WiFi.gatewayIP(),WiFi.subnetMask());

Result of code is:

IP Address: 22.0.0.0

Seems like every number I put in the last parameter of IPAddress is assigned as the first number of the new IP address, all other parameters are discarded.

@lonerzzz
Copy link
Contributor

How about when you use this syntax 'IPAddress chip( 192, 168, 10, 22 )' ?

@everslick
Copy link
Contributor

everslick commented Jul 29, 2017

I think this is related to #500 which was closed by the original reporter. Anyway, I cannot set static IP addresses either. So probably the issue should be kept open for other people to find it.

@brycebot
Copy link
Author

@lonerzzz

How about when you use this syntax 'IPAddress chip( 192, 168, 10, 22 )' ?

This seemed to work, thanks for the help.

@me-no-dev me-no-dev added the Type: For reference Common questions & problems label Aug 1, 2017
@everslick
Copy link
Contributor

After IDF has been updated last night, I gave it a shot again. But I see rather confusing behaviour when trying to set a static IP address.

First of all, the IP address can be set without any issue, but name resolution fails afterwards. Even though, when i read back the config the DNS server(s) have been configured correctly.

Second the SoftAP sometimes ignores the configured IP address and defaults to 192.168.4.1 without me being able to recognize a pattern, when it happens. But I think when it happens, the stack canary exception will trigger the next time the WiFi Event callback is called.

I would appreciate if someone could comment, if static IP configuration DOES indeed work for them INCLUDING name resolution and SoftAP (or at least name resolution). THX

@me-no-dev
Copy link
Member

// STA Static IP
    if(!WiFi.config(IPAddress(169, 254, 1, 3), IPAddress(10, 0, 0, 1), IPAddress(255, 255, 0, 0), IPAddress(10, 0, 0, 1))){
        Serial.println("STA Failed to configure");
    }
    if(WiFi.begin(STA_SSID, STA_PASS) == WL_CONNECT_FAILED){
        Serial.println("STA Failed to start");
    }

// AP Static IP
    if(!WiFi.softAPConfig(IPAddress(192, 168, 5, 1), IPAddress(192, 168, 5, 1), IPAddress(255, 255, 255, 0))){
        Serial.println("AP Config Failed");
    }
    if(!WiFi.softAP(AP_SSID)){
        Serial.println("AP Start Failed");
    }

@everslick this is what worked for me. Did not notice issues with resolution

@everslick
Copy link
Contributor

Static IP configuration started working after IoT was updated a view days ago, so I suggest closing this issue.

The second problem regarding WiFi.softAPConfig() not setting the configuration turned out to be a race condition between calling WiFi.softAP() and then setting the config with WiFi.softAPConfig(). The solution is to:

  1. Start SoftAP with WiFi.softAP()
  2. Wait for SYSTEM_EVENT_AP_START
  3. Set the config with WiFi.softAPConfig()

Not waiting for the SYSTEM_EVENT_AP_START event might overwrite the config one has just set for the interface.

@lonerzzz
Copy link
Contributor

Closing since the original and the related issue seem resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: For reference Common questions & problems
Projects
None yet
Development

No branches or pull requests

4 participants