Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change IP of ESP32 acting as an access point

So my goal here is to set the IP of my ESP32. I'm using this piece of code to do so, but I always end up with "192.168.4.1" - I want it to be: 192, 168, 1, 1

  WiFi.mode(WIFI_AP_STA);
  IPAddress Ip(192, 168, 1, 1);
  IPAddress NMask(255, 255, 255, 0);
  WiFi.softAPConfig(Ip, Ip, NMask);

  WiFi.softAP(ssid);
  IPAddress myIP = WiFi.softAPIP();
  Serial.println(myIP);
like image 509
Martin Lukas Avatar asked Oct 18 '25 17:10

Martin Lukas


1 Answers

To me it was happening that the IP was getting back to default 192.168.4.1 even if I was setting it. Basically you have to launch the AP before the configuration and wait a bit that the AP is set.

Refer to this post for more info Wifi.softAPConfig() sometimes set the wrong IP address

  WiFi.mode(WIFI_AP); 
  WiFi.softAP(ssidAP, passwordAP);   //launch the access point
  Serial.println("Wait 100 ms for AP_START...");
  delay(100);
  Serial.println("Setting the AP");
  IPAddress Ip(192, 168, 123, 123);    //setto IP Access Point same as gateway
  IPAddress NMask(255, 255, 255, 0);
  WiFi.softAPConfig(Ip, Ip, NMask);
like image 143
Pietro Avatar answered Oct 22 '25 05:10

Pietro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!