#include <WiFi.h>
Serial.begin(115200);
WiFi.softAP("MyESP32AP");After that we will register an handling function for the SYSTEM_EVENT_AP_STACONNECTED event, which will be fired whenever a new station connects to the network. We will call our handling function WiFiStationConnected and define it later.
WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_AP_STACONNECTED);
void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info){ Serial.println("Station connected"); }The final code can be seen below.
#include <WiFi.h> void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info){ Serial.println("Station connected"); } void setup() { Serial.begin(115200); WiFi.softAP("MyESP32AP"); WiFi.onEvent(WiFiStationConnected, SYSTEM_EVENT_AP_STACONNECTED); } void loop() {}