Created
January 6, 2016 17:50
-
-
Save michaelsarduino/298f532c1f7fcbe0e9db 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> | |
String temp = "Bisher noch nichts empfangen"; | |
const char* ssid = "***************"; | |
const char* password = "***************"; | |
MDNSResponder mdns; | |
ESP8266WebServer server(80); | |
void handleRoot() { | |
server.send(200, "text/html", "<html> Aktuelle Temperatur: "); | |
server.send(200, "text/html", temp); | |
server.send(200, "text/html", "</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){ | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
} | |
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"); | |
} | |
void loop(void){ | |
if(Serial.available() > 0) | |
{ | |
temp = Serial.readString(); | |
} | |
mdns.update(); | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment