Created
October 7, 2015 15:21
-
-
Save michaelsarduino/cb206940189b58f33bf0 to your computer and use it in GitHub Desktop.
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 <ESP8266WiFi.h> | |
const char* ssid = "****************"; | |
const char* password = "**********'*"; | |
WiFiServer server(80); | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
WiFi.begin(ssid, password); | |
Serial.println("Verbindung wird aufgebaut:"); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.print("."); | |
delay(500); | |
} | |
// Start the server | |
server.begin(); | |
Serial.println(""); | |
Serial.println("Verbunden"); | |
} | |
int angemeldet = 2; | |
void loop() { | |
// Check if a client has connected | |
WiFiClient client = server.available(); | |
if (!client) { | |
return; | |
} | |
while(!client.available()){ | |
delay(1); | |
} | |
// Read the first line of the request | |
String req = client.readStringUntil('\r'); | |
client.flush(); | |
String html = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html> <h3>Bitte Anmelden!</h3><form action=\"192.168.178.30/index.html\" method=\"GET\"> Username: <br /> <input type=\"text\" name=\"user\" value=\"\" /> <br /> Passwort: <br /> <input type=\"password\" name=\"password\" value=\"\" /> <br /> <input type=\"submit\" name=\"absenden\" value=\"anmelden!\" /><br /></form></html>\n"; | |
// Match the request | |
int val = -1; | |
if ((req.indexOf("user=arduino") != -1) && (req.indexOf("password=michaelsarduino") != -1)) | |
{ | |
angemeldet = 1; | |
} | |
else if((req.indexOf("user") != -1) && (req.indexOf("password") != -1)) | |
{ | |
angemeldet = 0; | |
} | |
else if(req.indexOf("/index.html") != -1) | |
client.print(html); | |
else { | |
//Serial.println("invalid request"); | |
client.stop(); | |
return; | |
} | |
if(angemeldet == 1) | |
{ | |
Serial.println(angemeldet); | |
client.flush(); | |
// Send the response to the client | |
client.print("<html><h3>Erfolgreich angemeldet!</h3></html>"); | |
delay(1); | |
} | |
if (angemeldet == 0) { | |
client.print("<html><h3>Leider Falsch!</h3></html>"); | |
delay(1); | |
} | |
angemeldet = 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment