Last active
November 28, 2018 10:11
-
-
Save jtuttas/edc6ac0fc63fe31c668a647e4e91a2a0 to your computer and use it in GitHub Desktop.
Einfacher WLAN Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "esp_wpa2.h" | |
#include <WiFi.h> | |
// SSID to connect to | |
static const char* ssid = "MMBBS-Intern"; | |
// Username for authentification | |
#define EAP_ID "tuttas" | |
#define EAP_USERNAME "tuttas" | |
#define EAP_PASSWORD "geheim" | |
WiFiServer server(80); | |
void setup() | |
{ | |
Serial.begin(115200); | |
delay(500); | |
WiFi.disconnect(true); | |
WiFi.mode(WIFI_STA); | |
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); | |
WiFi.begin(ssid); | |
// Wait for connection AND IP address from DHCP | |
Serial.println(); | |
Serial.println("Waiting for connection and IP Address from DHCP"); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(2000); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
Serial.write("\r\nStarte Webserver"); | |
server.begin(); | |
} | |
void loop() | |
{ | |
WiFiClient clientS = server.available(); | |
if (clientS) | |
{ | |
Serial.println("New Client"); | |
String s = "works!"; | |
clientS.print(s); | |
clientS.flush(); | |
clientS.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment