简体   繁体   English

如何更改 ESP32 的 IP 作为接入点

[英]How to change IP of ESP32 acting as an access point

So my goal here is to set the IP of my ESP32.所以我的目标是设置我的 ESP32 的 IP。 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我正在使用这段代码来执行此操作,但我总是以“192.168.4.1”结尾 - 我希望它是: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);首先用 WiFi.mode(WIFI_STA) 停止 WiFi;

To me it was happening that the IP was getting back to default 192.168.4.1 even if I was setting it.对我来说,IP 正在恢复到默认的 192.168.4.1,即使我正在设置它。 Basically you have to launch the AP before the configuration and wait a bit that the AP is set.基本上你必须在配置之前启动 AP 并等待 AP 设置好。

Refer to this post for more info Wifi.softAPConfig() sometimes set the wrong IP address有关更多信息,请参阅此帖子Wifi.softAPConfig() 有时会设置错误的 IP 地址

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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