2018-11-19 16:59:56 +01:00
|
|
|
#include <WiFi.h> //Wifi library
|
|
|
|
#include "esp_wpa2.h" //wpa2 library for connections to Enterprise networks
|
|
|
|
#define EAP_IDENTITY "login" //if connecting from another corporation, use identity@organisation.domain in Eduroam
|
2018-07-24 19:57:57 +02:00
|
|
|
#define EAP_PASSWORD "password" //your Eduroam password
|
|
|
|
const char* ssid = "eduroam"; // Eduroam SSID
|
|
|
|
const char* host = "arduino.php5.sk"; //external server domain for HTTP connection after authentification
|
2018-11-19 16:59:56 +01:00
|
|
|
int counter = 0;
|
2018-07-24 19:57:57 +02:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
delay(10);
|
|
|
|
Serial.println();
|
|
|
|
Serial.print("Connecting to network: ");
|
|
|
|
Serial.println(ssid);
|
|
|
|
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
|
2018-11-19 16:59:56 +01:00
|
|
|
WiFi.mode(WIFI_STA); //init wifi mode
|
2018-07-24 19:57:57 +02:00
|
|
|
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide identity
|
2018-11-19 16:59:56 +01:00
|
|
|
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)); //provide username --> identity and username is same
|
2018-07-24 19:57:57 +02:00
|
|
|
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)); //provide password
|
2021-04-05 13:23:58 +02:00
|
|
|
esp_wifi_sta_wpa2_ent_enable();
|
2018-11-19 16:59:56 +01:00
|
|
|
WiFi.begin(ssid); //connect to wifi
|
2018-07-24 19:57:57 +02:00
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
2018-11-19 16:59:56 +01:00
|
|
|
counter++;
|
|
|
|
if(counter>=60){ //after 30 seconds timeout - reset board
|
|
|
|
ESP.restart();
|
|
|
|
}
|
2018-07-24 19:57:57 +02:00
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
Serial.println("WiFi connected");
|
|
|
|
Serial.println("IP address set: ");
|
|
|
|
Serial.println(WiFi.localIP()); //print LAN IP
|
|
|
|
}
|
|
|
|
void loop() {
|
2018-11-19 16:59:56 +01:00
|
|
|
if (WiFi.status() == WL_CONNECTED) { //if we are connected to Eduroam network
|
|
|
|
counter = 0; //reset counter
|
|
|
|
Serial.println("Wifi is still connected with IP: ");
|
|
|
|
Serial.println(WiFi.localIP()); //inform user about his IP address
|
|
|
|
}else if (WiFi.status() != WL_CONNECTED) { //if we lost connection, retry
|
|
|
|
WiFi.begin(ssid);
|
|
|
|
}
|
|
|
|
while (WiFi.status() != WL_CONNECTED) { //during lost connection, print dots
|
|
|
|
delay(500);
|
|
|
|
Serial.print(".");
|
|
|
|
counter++;
|
|
|
|
if(counter>=60){ //30 seconds timeout - reset board
|
|
|
|
ESP.restart();
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 19:57:57 +02:00
|
|
|
Serial.print("Connecting to website: ");
|
|
|
|
Serial.println(host);
|
|
|
|
WiFiClient client;
|
2018-11-19 16:59:56 +01:00
|
|
|
if (client.connect(host, 80)) {
|
|
|
|
String url = "/rele/rele1.txt";
|
|
|
|
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: ESP32\r\n" + "Connection: close\r\n\r\n");
|
|
|
|
|
|
|
|
while (client.connected()) {
|
|
|
|
String line = client.readStringUntil('\n');
|
|
|
|
if (line == "\r") {
|
|
|
|
break;
|
|
|
|
}
|
2018-07-24 19:57:57 +02:00
|
|
|
}
|
2018-11-19 16:59:56 +01:00
|
|
|
String line = client.readStringUntil('\n');
|
|
|
|
Serial.println(line);
|
|
|
|
}else{
|
|
|
|
Serial.println("Connection unsucessful");
|
|
|
|
}
|
2018-07-24 19:57:57 +02:00
|
|
|
}
|