Skip to content

Commit d854dc1

Browse files
martinius96me-no-dev
authored andcommitted
Create WiFiClientEnterprise.ino (#1640)
Sketch for ESP32 boards that allow them to connect to WPA/WPA2 Enterprise Networks.
1 parent f1f8d7e commit d854dc1

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//Sketch edited by: Martin Chlebovec
2+
//Personal website: https://arduino.php5.sk
3+
#include "esp_wpa2.h"
4+
#include <WiFi.h>
5+
#define EAP_IDENTITY "[email protected]" //eduroam login --> [email protected]
6+
#define EAP_PASSWORD "password" //your Eduroam password
7+
String line; //variable for response
8+
const char* ssid = "eduroam"; // Eduroam SSID
9+
const char* host = "arduino.php5.sk"; //external server domain for HTTP connection after authentification
10+
void setup() {
11+
Serial.begin(115200);
12+
delay(10);
13+
Serial.println();
14+
Serial.print("Connecting to network: ");
15+
Serial.println(ssid);
16+
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
17+
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
18+
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username
19+
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
20+
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config to default (fixed for 2018 and Arduino 1.8.5+)
21+
esp_wifi_sta_wpa2_ent_enable(&config); //set config to enable function (fixed for 2018 and Arduino 1.8.5+)
22+
WiFi.begin(ssid); //connect to Eduroam function
23+
WiFi.setHostname("ESP32Name"); //set Hostname for your device - not neccesary
24+
while (WiFi.status() != WL_CONNECTED) {
25+
delay(500);
26+
Serial.print(".");
27+
}
28+
Serial.println("");
29+
Serial.println("WiFi connected");
30+
Serial.println("IP address set: ");
31+
Serial.println(WiFi.localIP()); //print LAN IP
32+
33+
}
34+
void loop() {
35+
delay(5000);
36+
if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
37+
WiFi.begin(ssid);
38+
delay(500);
39+
}
40+
Serial.print("Connecting to website: ");
41+
Serial.println(host);
42+
WiFiClient client;
43+
if (!client.connect(host, 80)) { // HTTP connection on port 80
44+
Serial.println("Connection lost! - Failed response");
45+
}
46+
String url = "/rele/rele1.txt"; //read .txt file
47+
Serial.print("Requesting URL: ");
48+
Serial.println(url);
49+
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
50+
unsigned long timeout = millis();
51+
while (client.available() == 0) {
52+
if (millis() - timeout > 5000) {
53+
Serial.println("Client timed out! - retry");
54+
}
55+
}
56+
while(client.available()) {
57+
line = client.readStringUntil('\n');
58+
Serial.println(line);
59+
}
60+
Serial.println();
61+
Serial.println("End connection");
62+
client.stop();
63+
}

0 commit comments

Comments
 (0)