Skip to content

WifiMulti does not support Static IP #1202

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
williamesp2015 opened this issue Mar 11, 2018 · 8 comments
Closed

WifiMulti does not support Static IP #1202

williamesp2015 opened this issue Mar 11, 2018 · 8 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@williamesp2015
Copy link

I am using ESP32 Arduino websocket using WifiMulti. There is example using Static IP ((https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClientStaticIP/WiFiClientStaticIP.ino) I copied below:
#include <WiFi.h>

const char* ssid = "your_network_name";
const char* password = "your_network_password";
const char* host = "example.com";
const char* url = "/index.html";

IPAddress local_IP(192, 168, 31, 115);
IPAddress gateway(192, 168, 31, 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("");
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());
}
/******************************/
My problem is with my project using WiFiMulti which is not supporting Static IP
WiFiMulti.addAP(SSID, pass);
Serial.print("Wait for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(". ");
delay(500);
}

@josepedrodiaz
Copy link

Same problem here

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
@peter1a
Copy link

peter1a commented Jan 20, 2021

Is now any support for static IP?

@chupocro
Copy link

chupocro commented Mar 1, 2021

WiFi.config(ip, gateway, subnet);

should be after

WiFi.begin(ssid, password);

or after

wifiMulti.addAP(ssid, password);

dg0tm added a commit to dg0tm/LoRa_APRS_iGate that referenced this issue Jul 16, 2021
  rethink implementation overall
@jjavieralv
Copy link

jjavieralv commented May 2, 2023

Example of working with WifiMulti and staticIP
#include <WifiMulti.h>
//insert here your values
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
IPAddress local_IP(192, 168, 1, 40);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
//config wifi and check
if (!WiFi.config(local_IP, gateway, subnet)) {
Serial.println("STA Failed to configure");
}
WiFi.mode(WIFI_STA);
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to wifi");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}

@abhishekabhi789
Copy link

If gateway varies among different wifi APs then how can a device use static IP? I tested with 4 hotspot and two of them have same address 192.168.43.1 so I can use any adress like 192.168.43.### However, the other two hostpots have different address, resulted in showing null as IP adress in hostpot config page, at the same time prints the static ip in WiFi.localIP().
Now Im using mDNS, but it's not available on all android versions.

@Sojourneer
Copy link

Sojourneer commented Feb 25, 2025

I have the same issue. This issue should not have been closed.

I had a simple-minded go at this, putting an on_SSID_selected(ssid) callback before WiFi.begin() in ESP8266WiFiMulti. The user can set the callback, and then invoke a suitable WiFi.config inside the callback. It seems to work.

Here is the patch.
esp8266/Arduino#9232

In my scenario (IoT sensor), I look at both the SSID and the MAC to determine the IP. There is a lot of flexibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

7 participants