Last active
November 2, 2015 15:14
-
-
Save michaelsarduino/7bf4a52bf68897af74cb 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> | |
#include <WiFiClient.h> | |
#include <ESP8266WebServer.h> | |
#include <ESP8266mDNS.h> | |
#include <Time.h> | |
const char* ssid = "************"; | |
const char* password = "************"; | |
MDNSResponder mdns; | |
String bewegung_html = "<table border = 1>"; | |
ESP8266WebServer server(80); | |
void handleRoot() { | |
server.send(200, "text/html", "<html>"); | |
server.send(200, "text/html", bewegung_html); | |
server.send(200, "text/html", "</table></html>"); | |
} | |
void handleNotFound(){ | |
String message = "File Not Found\n\n"; | |
message += "URI: "; | |
message += server.uri(); | |
message += "\nMethod: "; | |
message += (server.method() == HTTP_GET)?"GET":"POST"; | |
message += "\nArguments: "; | |
message += server.args(); | |
message += "\n"; | |
for (uint8_t i=0; i<server.args(); i++){ | |
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | |
} | |
server.send(404, "text/plain", message); | |
} | |
void setup(void){ | |
setTime(18, 36, 10, 28, 9, 15); | |
pinMode(2, INPUT); | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
Serial.println(""); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to "); | |
Serial.println(ssid); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
if (mdns.begin("esp8266", WiFi.localIP())) { | |
Serial.println("MDNS responder started"); | |
} | |
server.on("/", handleRoot); | |
server.on("/inline", [](){ | |
server.send(200, "text/plain", "this works as well"); | |
}); | |
server.onNotFound(handleNotFound); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
} | |
unsigned long akt = millis(); | |
unsigned long zuletzt = millis(); | |
void loop(void){ | |
akt = millis(); | |
if(digitalRead(2) == HIGH && ((akt - zuletzt) > 20000)) | |
{ | |
bewegung_html = bewegung_html + "<tr><td>" + hour() + ":" + minute() + "</td> <td> Bewegung erkannt an Sensor 1 </td> </tr><br />"; | |
zuletzt = millis(); | |
} | |
mdns.update(); | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment