WPA2 Enterprise Causes Problem For OTA in ESP32

I am trying to connect accespoint's spesific SSID and its works perfectly but when I add the OTA network codes into code OTA doesnt works. I tried simply OTA connection WPA2'less server it was works perfect but I just added simply OTA code into WPA2 configurated code its doesnt works OTA.(Wifi connection section still works fine in tihs situation).
Here is the my code:

#include <Arduino.h>
#include <AsyncElegantOTA.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WiFi.h>
#include "esp_wpa2.h"
#include "esp_wifi.h"

// ########  Set Parameters ##########

#define WIFI_SSID "SSID"
#define EAP_USERNAME "EAP_USERNAME"
#define EAP_IDENTITY "EAP_USERNAME"
#define EAP_PASSWORD "EAP_PASSWORD"

IPAddress local_IP(10, 54, 243, 28);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(10, 54, 243, 1);

AsyncWebServer server(80);

//###################################

void scanNetworks() {
  Serial.println("Scanning  network...");
  int n = WiFi.scanNetworks();
  Serial.println("Scan done.");

  if (n == 0) {
    Serial.println("No networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found.");

    for (int i = 0; i < n; ++i) {
      if (WiFi.SSID(i) == WIFI_SSID) {
        // Print SSID and RSSI for each network found
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(WiFi.SSID(i));
        Serial.print("\t\t(");
        Serial.print(WiFi.RSSI(i));
        Serial.print(")");
        Serial.print("\t\tencryption type: ");
        Serial.print(WiFi.encryptionType(i));
        Serial.print(" Bssid: ");
        Serial.print(WiFi.BSSIDstr(i));
        Serial.print(" ch: ");
        Serial.println(WiFi.channel(i));
        Serial.println(WiFi.BSSIDstr(i));

        delay(10);
      }
    }
  }
}


void initWiFi() {
  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect(true);
  delay(100);

  scanNetworks();

  // Configures static IP address
  if (!WiFi.config(local_IP, gateway, subnet)) {
    Serial.println("STA Failed to configure");
  }

  //ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
  //ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY));
  esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_USERNAME, strlen(EAP_USERNAME));
  esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD));
  esp_wifi_sta_wpa2_ent_enable();

  //WiFi.begin(WIFI_SSID);

   byte desired_bssid[] = { 0x00, 0x4E, 0x35, 0xF3, 0x24, 0x81 };
   byte desired_channel = 6;
   WiFi.begin(WIFI_SSID, EAP_PASSWORD, desired_channel, desired_bssid);
}


void checkWiFiConnection() {
  unsigned long startAttemptTime = millis();
  unsigned long interval = 30000;

  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to WiFi .. ");
  }
  while (WiFi.status() != WL_CONNECTED && (millis() - startAttemptTime <= interval)) {
    Serial.print('.');
    delay(500);
  }

  Serial.println();
  Serial.print("Mac address: ");
  Serial.print(WiFi.macAddress());
  Serial.print("    Local Ip: ");
  Serial.println(WiFi.localIP());
  Serial.print("  BSSID: ");
  Serial.print(WiFi.BSSIDstr());
  Serial.print("\tRRSI: ");
  Serial.println(WiFi.RSSI());

  Serial.print("WiFi status: ");
  Serial.println(WiFi.status());

  if (WiFi.status() != WL_CONNECTED) {
    //ESP.restart();
    initWiFi();
  }
}

void setup() {

  Serial.begin(115200);
  delay(100);
  initWiFi();
  Serial.println("");
  Serial.println("Connected to WiFi Network with Name: ");
  Serial.print(WIFI_SSID);
  Serial.print("IP Address for ESP32: ");
  Serial.println(WiFi.localIP());

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
    request->send(200, "text/plain", "OTA v2.0 - Update wirelessly");
  });

  AsyncElegantOTA.begin(&server);
  server.begin();
  Serial.println("Elegant OTA Initiated");
  Serial.println("HTTP Server Has started Sucessfully");
  Serial.println("To access OTA Update, type");
  Serial.println(WiFi.localIP());
  Serial.print("/update");
}


void loop() {
  checkWiFiConnection();
  delay(1000);
}

Where is your OTA code?

Initialized in setup function.

As you do not serve any pges but OTA there's no way telling if your webserver is working correct. You should serve at least one demo page to figure out what's happening.

Actually I dont need any web pages for this project. I am currently working only with request on async web server. This code works with async web server side but ota IP link doesn't works. I wonder I am streaming comminucations on I choosed IP but at the same time streaming ota site at the same IP. Is that problem ? Also I wonder can I work with 2 different IP's at the same time in 1 device?

Can you serve a single HTML page? If not, solve this first. Or take a look at the OTA examples.

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