Skip to content

Commit e4da840

Browse files
committed
Fix WPA2 examples
1 parent 629c2cd commit e4da840

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

libraries/HTTPClient/examples/HTTPClientEnterprise/HTTPClientEnterprise.ino

+11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
/*|----------------------------------------------------------|*/
66
#include <WiFi.h>
77
#include <HTTPClient.h>
8+
#if __has_include ("esp_eap_client.h")
9+
#include "esp_eap_client.h"
10+
#else
811
#include "esp_wpa2.h"
12+
#endif
913
#include <Wire.h>
1014
#define EAP_IDENTITY "identity" //if connecting from another corporation, use [email protected] in Eduroam
1115
#define EAP_PASSWORD "password" //your Eduroam password
@@ -42,10 +46,17 @@ void setup() {
4246
Serial.println(ssid);
4347
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
4448
WiFi.mode(WIFI_STA); //init wifi mode
49+
#if __has_include ("esp_eap_client.h")
50+
esp_eap_clien_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
51+
esp_eap_clien_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username
52+
esp_eap_clien_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
53+
esp_wifi_sta_enterprise_enable();
54+
#else
4555
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
4656
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same
4757
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
4858
esp_wifi_sta_wpa2_ent_enable();
59+
#endif
4960
WiFi.begin(ssid); //connect to wifi
5061
while (WiFi.status() != WL_CONNECTED) {
5162
delay(500);

libraries/WiFi/examples/WiFiClientEnterprise/WiFiClientEnterprise.ino

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <WiFi.h> //Wifi library
2-
#include "esp_wpa2.h" //wpa2 library for connections to Enterprise networks
32
#define EAP_IDENTITY "login" //if connecting from another corporation, use [email protected] in Eduroam
43
#define EAP_USERNAME "login" //oftentimes just a repeat of the identity
54
#define EAP_PASSWORD "password" //your Eduroam password

libraries/WiFiClientSecure/examples/WiFiClientSecureEnterprise/WiFiClientSecureEnterprise.ino

+11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
#include <WiFi.h>
1717
#include <WiFiClientSecure.h>
18+
#if __has_include ("esp_eap_client.h")
19+
#include "esp_eap_client.h"
20+
#else
1821
#include "esp_wpa2.h"
22+
#endif
1923
#include <Wire.h>
2024
#define EAP_ANONYMOUS_IDENTITY "[email protected]" //anonymous identity
2125
#define EAP_IDENTITY "[email protected]" //user identity
@@ -64,10 +68,17 @@ void setup() {
6468
Serial.println(ssid);
6569
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
6670
WiFi.mode(WIFI_STA); //init wifi mode
71+
#if __has_include ("esp_eap_client.h")
72+
esp_eap_clien_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity
73+
esp_eap_clien_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username
74+
esp_eap_clien_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
75+
esp_wifi_sta_enterprise_enable();
76+
#else
6777
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY)); //provide identity
6878
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username
6979
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
7080
esp_wifi_sta_wpa2_ent_enable();
81+
#endif
7182
WiFi.begin(ssid); //connect to wifi
7283
while (WiFi.status() != WL_CONNECTED) {
7384
delay(500);

0 commit comments

Comments
 (0)