ESP32, how to get IP of AP from STA?

When a ESP32 station connects to a ESP32 AP, how can the station get the AP's IP?

The problem is after a connection is made, I need to start a websocket using the AP's IP.

There is no requirement for an Access Point to have an IP address, however many do if they are multifunctional devices e.g. home router.

What other services will the AP be supporting, other than WiFi and presumably some form of IP/TCP?

A websocket server and sensor data using Adafruit's library. If it comes to adding something large specifically for this I'll leave it hardcoded. I was hoping there was an API that could determine this. but either I'm missing something or it doesn't exist as I've tried most (all?) Arduino API's and some from espidf (tcpip_adapter_get_sta_list, esp_wifi_get_config).

How is the webserver/AP getting it's ip address? Presumably through DHCP since otherwise you could hard code the IP address. You could try broadcasting from the webserver/AP (or possibly multicast) the ip address so that all nodes in your network can find out what it is.

I’m not an expert, but presumably yes. The AP currently goes up like this using Arduino API…

// in a nutshell, as seen in tutorials
WiFI.softAP(ssid, pass, chan, hidd, clie);
// ** the below ip is created from esp_efuse_mac_get_default()
WiFi.softAPConfig(ip, gw, nm);
// also a DNS server on the first AP
dnsServer.start(port, “*”, WiFi.softAPIP() );

There’s also wifi and socket events happening, but none of them help the STA get the IP before bringing up its websocket client. If the DNS server can help, I haven’t seen how yet, however it only comes up on the first AP (the one with the GUI/browser).

Thank you for trying to help, but I’m starting to think that without me having greater understanding of TCP/IP and DHCP it might be hopeless :-/. I can spin up something up on the STA like a socketServer (or whatever), get the IP, then destroy that instance of whatever and move on. For some reason though I felt that if there is IP’s going around, everything with one should have a API to find all them that are reachable.

There should be a Wifi.localIP() that should give you the ip address on the webserver not sure if you have to start the webserver first or not though.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.