Pages: [1]   Go Down
Author Topic: Wetterdaten von Internetseite  (Read 337 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo,
Ich habe da ein problem bei Lesen der Internetseite
http://www.aviationweather.gov/adds/metars/?station_ids=eddf&std_trans=translated&chk_metars=on&hoursStr=most+recent+only&submitmet=Submit
Wenn ich die mit dem Sketch WebClient auslesen will bekomme ich den hinweis es wäre eine falsche anfrage.
Lasse ich nach .gov alles weg sehe ich daten von der hauptseite
 
Code:
/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0xXX, 0xXX, 0xF9 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.aviationweather.gov";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET / metar HTTP/1.1");
    client.println("Host: www.aviationweather.gov/adds/metars/?station_ids=eddf&std_trans=standard&chk_metars=on&hoursStr=past+1+hours&submitmet=Submit");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}
wo habe ich den fehler???
bello12
Logged

Cologne
Offline Offline
God Member
*****
Karma: 11
Posts: 512
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo bello12,
wenn ich die Seite mit wget abrufe, bekomme ich folgendem Inhalt
Quote
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>
<HEAD>
<TITLE>ADDS - METARS form results</TITLE>
<LINK REL="StyleSheet" type="text/css" HREF="/layout/awc/mystyle.css">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
  <TABLE SUMMARY="This table is used for formatting purposes only" BORDER=0 CELLPADDING=3 CELLSPACING=0>
    <TR VALIGN="top">
      <TD ALIGN="left" COLSPAN="2">
        <H2>Aviation Digital Data Service (ADDS)</H2>
        Output produced by METARs form (2115&#160;UTC&nbsp;23 March 2014)<BR>
        found at <A HREF="http://www.aviationweather.gov/adds/metars/"> http://www.aviationweather.gov/adds/metars/</A><BR>&#160;<BR>
      </TD>
    </TR>
    <TR VALIGN="top">
      <TD ALIGN="left" COLSPAN="2">
        <PRE><font face="Monospace,Courier" size="+1">TAF EDDF 231700Z 2318/2424 29006KT 9999 SCT040
     PROB40
     TEMPO 2410/2418 SHRA BKN030CB
       </font></PRE>
      </TD>
    </TR>
  </TABLE>
</BODY>
</HTML>
Der Aufruf wird aber nicht geschlossen. Ich vermute, dass die Nachfomatierung dann im Browser stattfindet.
Gruß
Reinhard
Logged

Germany S-H
Offline Offline
Faraday Member
**
Karma: 164
Posts: 3200
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wo habe ich den fehler???

Du hast zwei Fehler im Sketch.

Einmal ist die angegebene MAC-Adresse so fehlerhaft, dass Dein Code nicht fehlerfrei kompilieren kann.

Und einmal ist die angegebene GET-Anfrage so fehlerhaft, dass sie keinem jemals gültigen HTTP-Standard entspricht und daher allenfalls mit einer Fehlermeldung beantwortet werden kann.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hallo jurs,
wie sollte die GET abfrage aussehen. Das mit der MAC weiss ich
Gruß bello12
Logged

Germany S-H
Offline Offline
Faraday Member
**
Karma: 164
Posts: 3200
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wie sollte die GET abfrage aussehen.

Na eben so, dass die Serveranfrage entweder den aktuellen oder irgendwelchen früher mal geltenden HTTP-Standards wenigstens so weit entspricht, dass ein Server sie interpretieren kann.

Z.B.:
Code:
    client.println("GET /adds/metars/?station_ids=eddf&std_trans=standard&chk_metars=on&hoursStr=past+1+hours&submitmet=Submit HTTP/1.1");
    client.println("Host: www.aviationweather.gov");
Logged

Pages: [1]   Go Up
Jump to: