以下為程式碼 EAP_ID
、EAP_USERNAME
、EAP_PASSWORD
、EAP_SSID
為遮蓋後的結果,可以確定這些資訊都是對的(這些資訊用手機連到wifi是OK的),但esp32一直都連不到wifi,請問是否哪裡有錯呢?
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wpa2.h"
#define EAP_ID "..."
#define EAP_USERNAME "..."
#define EAP_PASSWORD "..."
const char *EAP_SSID = "...";
void setup() {
Serial.begin(115200);
// Initialize
WiFi.disconnect();
// Station mode
WiFi.mode(WIFI_STA);
Serial.println();
Serial.print("Connecting to ");
Serial.println(EAP_SSID);
// WPA2 enterprise magic starts here
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ID, strlen(EAP_ID));
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_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
esp_wifi_sta_wpa2_ent_enable(&config);
Serial.println("MAC address: ");
Serial.println(WiFi.macAddress());
Serial.println(EAP_ID);
Serial.println(EAP_PASSWORD);
WiFi.begin(EAP_SSID);
// Check connection status
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("WiFi connected !");
Serial.print("Local IP: ");
Serial.println(WiFi.localIP());
}
void loop() {
delay(10000);
}