arduinoesp32arduino-esp32access-point

'SYSTEM_EVENT_AP_STACONNECTED' was not declared in this scope


I can't flash esp32-cam because gives up error of command "WiFi.onEvent(WiFiPointConnected, SYSTEM_EVENT_AP_STACONNECTED);". SYSTEM_EVENT_AP_STACONNECTED is built-in parameter in Arduino IDE. May be I haven't anyfile. How to solve this? Thanks in advance.

Sketch:

#include <WiFi.h> 
const char* ssid = "CarDrone";
const char* password = "08060905";
String network_ssid = "---";
String network_password = "----";
WebServer server(80);

void WiFiPointConnected(WiFiEvent_t event, WiFiEventInfo_t info) {
  Serial.println("Connected!");
}
void setup() {
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  WiFi.onEvent(WiFiPointConnected, SYSTEM_EVENT_AP_STACONNECTED);
  Serial.println();
  Serial.println("ESP32-CAM IP Address: " + WiFi.localIP());
}
void loop() {}

Error:

WiFi.onEvent(WiFiPointConnected, SYSTEM_EVENT_AP_STACONNECTED);
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                    WIFI_EVENT_AP_STACONNECTED

exit status 1

Compilation error: 'SYSTEM_EVENT_AP_STACONNECTED' was not declared in this scope; did you mean 'WIFI_EVENT_AP_STACONNECTED'?

Solution

  • Your code is for esp32 Arduino platform version 1, but you compile it with version 3.

    In version 2 WiFi.onEvent was changed to use an enum where the name for the new STA connected to SoftAP is ARDUINO_EVENT_WIFI_AP_STACONNECTED.

    The WIFI_EVENT_AP_STACONNECTED constant recommended by the compiler is from the IDF framework on which the Arduino platform is built and it is not compatible with Arduino WiFi library's WiFi.onEvent` function.