Skip to content

WifiMulti does not support Static IP #1202

Closed
@williamesp2015

Description

@williamesp2015

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

josepedrodiaz commented on May 1, 2018

@josepedrodiaz

Same problem here

stale

stale commented on Aug 1, 2019

@stale

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 commented on Aug 15, 2019

@stale

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

peter1a

peter1a commented on Jan 20, 2021

@peter1a

Is now any support for static IP?

chupocro

chupocro commented on Mar 1, 2021

@chupocro

WiFi.config(ip, gateway, subnet);

should be after

WiFi.begin(ssid, password);

or after

wifiMulti.addAP(ssid, password);

jjavieralv

jjavieralv commented on May 2, 2023

@jjavieralv

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

abhishekabhi789 commented on Oct 5, 2023

@abhishekabhi789

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

Sojourneer commented on Feb 25, 2025

@Sojourneer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      WifiMulti does not support Static IP · Issue #1202 · espressif/arduino-esp32