Last active
February 1, 2016 20:27
-
-
Save michaelsarduino/97de5ce8c0b621fd66c1 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 = "*************"; | |
char server[] = "weather.yahooapis.com"; //Webserver | |
WiFiClient client; | |
String website; | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
// 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("."); | |
} | |
//Serial.println(""); | |
//Serial.println("WiFi connected"); | |
// Print the IP address | |
//Serial.println(WiFi.localIP()); | |
//Serial.println("\nStarting connection to server..."); | |
//Ausgabe ueber serielle Verbindung | |
} | |
void loop() { | |
if (client.connect(server, 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 | |
} | |
int tagkurzelst = website.indexOf("Date: "); | |
char tag1 = website[tagkurzelst + 6]; | |
char tag2 = website[tagkurzelst + 7]; | |
char tag3 = website[tagkurzelst + 8]; | |
String tag = String(tag1) + String(tag2) + String(tag3); | |
int datint = tag.toInt(); | |
int zusatz = 0; | |
if(datint > 9) | |
{ | |
zusatz = 1; | |
} | |
String dat = String(website[tagkurzelst + 11]) + String(website[tagkurzelst + 12]); | |
String morgen; | |
if(tag == "Mon") | |
{ | |
morgen = "Tue"; | |
} | |
else | |
{ | |
if(tag == "Tue") | |
{ | |
morgen = "Wed"; | |
} | |
else | |
{ | |
if(tag == "Wed") | |
{ | |
morgen = "Thu"; | |
} | |
else | |
{ | |
if(tag == "Thu") | |
{ | |
morgen = "Fri"; | |
} | |
else | |
{ | |
if(tag == "Fri") | |
{ | |
morgen = "Sat"; | |
} | |
else | |
{ | |
if(tag == "Sat") | |
{ | |
morgen = "Sun"; | |
} | |
else | |
{ | |
if(tag == "Sun") | |
{ | |
morgen = "Mon"; | |
} | |
else | |
{ | |
//Woche durch ->Fehlermeldung hier moeglich | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
String stelletx = "<yweather:forecast day=\"" + morgen; | |
int stelle = website.indexOf(stelletx); | |
int vorhersagelow; | |
int stellen; | |
int ort = stelle + 52 + zusatz; | |
int ort2 = stelle + 53 + zusatz; | |
String low2 = String(website[ort2]); | |
if(low2.toInt() == 0) | |
{ | |
String zwischen = String(website[ort]); | |
vorhersagelow = zwischen.toInt(); | |
stellen = 0; | |
} | |
else | |
{ | |
String vorhersagelowstring = String(website[ort]) + String(website[ort2]); | |
vorhersagelow = vorhersagelowstring.toInt(); | |
stellen = 1; | |
} | |
Serial.print("|"); | |
Serial.print(vorhersagelow); | |
Serial.print("|"); | |
int ort3 = ort + 9 + stellen; | |
int ort4 = ort + 10 + stellen; | |
int vorhersagehigh; | |
int weitere; | |
String high2 = String(website[ort4]); | |
if(high2.toInt() == 0) | |
{ | |
String zwischen2 = String(website[ort3]); | |
vorhersagehigh = zwischen2.toInt(); | |
} | |
else | |
{ | |
String vorhersagehighstring = String(website[ort3]) + String(website[ort4]); | |
vorhersagehigh = vorhersagehighstring.toInt(); | |
} | |
Serial.print(vorhersagehigh); | |
Serial.print("|"); | |
delay(14400); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment