Created
February 14, 2016 15:55
-
-
Save michaelsarduino/996994b729db76aa1911 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 <WiFiServer.h> | |
#include <WiFiUdp.h> | |
#include <ESP8266mDNS.h> | |
#include <ESP8266WebServer.h> | |
const char* ssid = "*********"; //Name des bestehenden Wlan Netzwerkes | |
const char* password = "**********"; //Passwort des bestehenden Wlan Netzwerkes | |
char serverw[] = "weather.yahooapis.com"; //Webserver | |
WiFiClient client; | |
String website; | |
ESP8266WebServer server(80); | |
MDNSResponder mdns; | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
WiFi.softAP("esp8266_ap", "michaelsarduino"); //Name und Passwort des neuen Wlan Netzwerks | |
// Connect to WiFi network | |
Serial.println(); | |
Serial.println(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
if (mdns.begin("esp8266", WiFi.localIP())) { | |
Serial.println("MDNS responder started"); | |
} | |
server.begin(); | |
server.on("/", handleRoot); | |
} | |
void loop() { | |
server.handleClient(); | |
mdns.update(); | |
} | |
void handleRoot() { | |
if (client.connect(serverw, 80)) { | |
//Serial.println("connected to server"); | |
client.println("GET /forecastrss?w=676757&u=c HTTP/1.1"); // /index.html durch gewuenschte Unterseite ersetzen (index.html = Startseite) | |
client.println("Host: weather.yahooapis.com"); //Adresse des Webservers | |
client.println("Connection: close"); | |
client.println(); //Verbindungs mit Server aufbauen und HTTP Anfrage senden | |
} | |
while(website.length() < 10) | |
{ | |
while (client.available()) | |
{ | |
website = client.readString(); | |
} | |
} | |
if (!client.connected()) { | |
Serial.println(); | |
Serial.println("disconnecting from server."); | |
client.stop(); | |
//Beenden der Verbindung | |
} | |
server.send(200, "text/html", "<h1>Yahoo Wetter</h1>"); | |
server.send(200, "text/html", website); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment