Last active
October 8, 2018 06:55
-
-
Save jtuttas/a6654eee18000d44a8ec7df76c3c8a09 to your computer and use it in GitHub Desktop.
ESP32 mit Form TAG
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); | |
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 request = clientS.readStringUntil('\r'); | |
Serial.println(">" + request + "<"); | |
String param = " "; | |
if (request.indexOf("?") != -1) | |
{ | |
param = request.substring(request.indexOf("?") + 1, request.indexOf(" HTTP/1.1")); | |
Serial.println(">" + param + "<"); | |
} | |
String s = "<form action=\"?state=true\" method=\"get\"><input type=\"checkbox\" name=\"led\" value=\"1\">LED<button type=\"submit\">Klick mich</button></form>"; | |
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