简体   繁体   中英

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);

First stop the WiFi with WiFi.mode(WIFI_STA);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM