Description
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);
}
Activity
josepedrodiaz commentedon May 1, 2018
Same problem here
stale commentedon 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 commentedon Aug 15, 2019
This stale issue has been automatically closed. Thank you for your contributions.
peter1a commentedon Jan 20, 2021
Is now any support for static IP?
chupocro commentedon Mar 1, 2021
WiFi.config(ip, gateway, subnet);
should be after
WiFi.begin(ssid, password);
or after
wifiMulti.addAP(ssid, password);
jjavieralv commentedon 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 commentedon Oct 5, 2023
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 like192.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 inWiFi.localIP()
.Now Im using mDNS, but it's not available on all android versions.
Sojourneer commentedon 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.