Ankündigung

Einklappen
Keine Ankündigung bisher.

- √ - Davis Wetterstation Werte aus dynamischer XML-Struktur auf den Bus bringen

Einklappen
Dieses Thema ist geschlossen.
X
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    [wiregate] - √ - Davis Wetterstation Werte aus dynamischer XML-Struktur auf den Bus bringen

    Hallo,
    ich versuche gerade die Daten einer Davis-Wetterstation auf den Bus zu bringen. Beim Googlen bin ich auf eine undokumentierte XML-Schnittstelle im Beta Stadium gestoßen.

    Voraussetzung hierfür:
    • Weatherlink IP Datenlogger
    • Account bei weatherlink.com
    • Online Verbindung via Router


    Die übergebenen Daten haben folgendes Format:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <current_observation version="1.0"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:noNamespaceSchemaLocation="http://www.weather.gov/view/current_observation.xsd">
    	<credit>Davis Instruments Corp.</credit>
    	<credit_URL>http://www.davisnet.com</credit_URL>
    	<image>
    		<url>http://www.davisnet.com/news/photos/Corporate/img-sml/logo_DI_reflxblu.jpg</url>
    		<title>Davis WeatherLink</title>
    		<link>http://www.weatherlink.com</link>
    	</image>
    	<suggested_pickup>15 minutes after the hour</suggested_pickup>
    	<suggested_pickup_period>60</suggested_pickup_period>
    	<dewpoint_c>11.7</dewpoint_c>
    	<dewpoint_f>53</dewpoint_f>
    	<dewpoint_string>53 F (11.7 C)</dewpoint_string>
    	<heat_index_c>15.6</heat_index_c>
    	<heat_index_f>60</heat_index_f>
    	<heat_index_string>60 F (15.6 C)</heat_index_string>
    	<latitude>52.054918320538</latitude>
    	<location>Bad Salzuflen, NRW, Germany</location>
    	<longitude>8.7285947799683</longitude>
    	<observation_time>Last Updated on Aug 10 2012, 10:07 am CEST</observation_time>
    	<observation_time_rfc822>Fri, 10 Aug 2012 10:07:38 +0200</observation_time_rfc822>
    	<pressure_in>30.329</pressure_in>
    	<pressure_mb>1027.1</pressure_mb>
    	<pressure_string>1027.1 mb</pressure_string>
    	<relative_humidity>77</relative_humidity>
    	<station_id>beermann</station_id>
    	<temp_c>15.6</temp_c>
    	<temp_f>60.0</temp_f>
    	<temperature_string>60.0 F (15.6 C)</temperature_string>
    	<wind_degrees>149</wind_degrees>
    	<wind_dir>Southeast</wind_dir>
    	<wind_kt>0</wind_kt>
    	<wind_mph>0</wind_mph>
    	<windchill_c>15.6</windchill_c>
    	<windchill_f>60</windchill_f>
    	<windchill_string>60 F (15.6 C)</windchill_string>
    	<davis_current_observation version="1.0">
    		<dewpoint_day_high_f>54</dewpoint_day_high_f>
    		<dewpoint_day_high_time>10:03am</dewpoint_day_high_time>
    		<dewpoint_day_low_f>45</dewpoint_day_low_f>
    		<dewpoint_day_low_time>5:48am</dewpoint_day_low_time>
    		<dewpoint_month_high_f>64</dewpoint_month_high_f>
    		<dewpoint_month_low_f>45</dewpoint_month_low_f>
    		<dewpoint_year_high_f>69</dewpoint_year_high_f>
    		<dewpoint_year_low_f>42</dewpoint_year_low_f>
    		<heat_index_day_high_f>60</heat_index_day_high_f>
    		<heat_index_day_high_time>10:32am</heat_index_day_high_time>
    		<heat_index_month_high_f>83</heat_index_month_high_f>
    		<heat_index_year_high_f>77</heat_index_year_high_f>
    		<observation_age>41</observation_age>
    		<pressure_day_high_in>30.339</pressure_day_high_in>
    		<pressure_day_high_time>9:22am</pressure_day_high_time>
    		<pressure_day_low_in>30.306</pressure_day_low_in>
    		<pressure_day_low_time>12:01am</pressure_day_low_time>
    		<pressure_month_high_in>30.339</pressure_month_high_in>
    		<pressure_month_low_in>29.729</pressure_month_low_in>
    		<pressure_tendency_string>Steady</pressure_tendency_string>
    		<pressure_year_high_in>30.383</pressure_year_high_in>
    		<pressure_year_low_in>29.508</pressure_year_low_in>
    		<rain_day_in>0.0000</rain_day_in>
    		<rain_month_in>0.4173</rain_month_in>
    		<rain_rate_day_high_in_per_hr>0.0000</rain_rate_day_high_in_per_hr>
    		<rain_rate_hour_high_in_per_hr>0.0000</rain_rate_hour_high_in_per_hr>
    		<rain_rate_in_per_hr>0.0000</rain_rate_in_per_hr>
    		<rain_rate_month_high_in_per_hr>2.3622</rain_rate_month_high_in_per_hr>
    		<rain_rate_year_high_in_per_hr>6.1260</rain_rate_year_high_in_per_hr>
    		<rain_storm_in>0.0000</rain_storm_in>
    		<rain_year_in>3.4016</rain_year_in>
    		<relative_humidity_day_high>100</relative_humidity_day_high>
    		<relative_humidity_day_high_time>5:44am</relative_humidity_day_high_time>
    		<relative_humidity_day_low>75</relative_humidity_day_low>
    		<relative_humidity_day_low_time>10:43am</relative_humidity_day_low_time>
    		<relative_humidity_in>46</relative_humidity_in>
    		<relative_humidity_in_day_high>50</relative_humidity_in_day_high>
    		<relative_humidity_in_day_high_time>2:15am</relative_humidity_in_day_high_time>
    		<relative_humidity_in_day_low>46</relative_humidity_in_day_low>
    		<relative_humidity_in_day_low_time>10:28am</relative_humidity_in_day_low_time>
    		<relative_humidity_in_month_high>51</relative_humidity_in_month_high>
    		<relative_humidity_in_month_low>42</relative_humidity_in_month_low>
    		<relative_humidity_in_year_high>60</relative_humidity_in_year_high>
    		<relative_humidity_in_year_low>39</relative_humidity_in_year_low>
    		<station_name>vantage_vue</station_name>
    		<sunrise>6:01am</sunrise>
    		<sunset>8:58pm</sunset>
    		<temp_day_high_f>60.1</temp_day_high_f>
    		<temp_day_high_time>10:40am</temp_day_high_time>
    		<temp_day_low_f>45.6</temp_day_low_f>
    		<temp_day_low_time>5:48am</temp_day_low_time>
    		<temp_in_day_high_f>76.2</temp_in_day_high_f>
    		<temp_in_day_high_time>10:40am</temp_in_day_high_time>
    		<temp_in_day_low_f>72.4</temp_in_day_low_f>
    		<temp_in_day_low_time>5:59am</temp_in_day_low_time>
    		<temp_in_f>76.0</temp_in_f>
    		<temp_in_month_high_f>82.7</temp_in_month_high_f>
    		<temp_in_month_low_f>72</temp_in_month_low_f>
    		<temp_in_year_high_f>84</temp_in_year_high_f>
    		<temp_in_year_low_f>68</temp_in_year_low_f>
    		<temp_month_high_f>82.6</temp_month_high_f>
    		<temp_month_low_f>45.6</temp_month_low_f>
    		<temp_year_high_f>92.2</temp_year_high_f>
    		<temp_year_low_f>41.7</temp_year_low_f>
    		<wind_day_high_mph>5</wind_day_high_mph>
    		<wind_day_high_time>10:42am</wind_day_high_time>
    		<wind_month_high_mph>18</wind_month_high_mph>
    		<wind_ten_min_avg_mph>1</wind_ten_min_avg_mph>
    		<wind_year_high_mph>18</wind_year_high_mph>
    		<windchill_day_low_f>46</windchill_day_low_f>
    		<windchill_day_low_time>5:09am</windchill_day_low_time>
    		<windchill_month_low_f>46</windchill_month_low_f>
    		<windchill_year_low_f>46</windchill_year_low_f>
    	</davis_current_observation>
    	<disclaimer_url>http://www.davisnet.com/about/terms.asp</disclaimer_url>
    	<copyright_url>http://www.davisnet.com/about/terms.asp</copyright_url>
    	<privacy_policy_url>http://www.davisnet.com/about/privacy.asp</privacy_policy_url>
    </current_observation>
    Leider ist dieses Format nicht fix. Ist z.B. kein Sturm, wird z.B. das Attribut
    Code:
    rain_storm_start_date
    nicht ausgeliefert.

    Die Antwort vom Support ist auch nicht wirklich weiterführend:
    There is no documentation on the XML data because it is only a beta and not in its final release yet. I do not have a complete list of all the variables. The data will be in imperial units.
    Nach und nach trage ich nun alle möglichen Attribute für meine Davis Vantage Vue zusammen - die Abfrage möchte ich dazu gerne möglichst auf diese unterschiedlichen Fälle dynamisch halten.
    Habe aber keine Idee, wie ich da am besten vorgehen sollte.

    In Anlehnung an andere Plugin habe ich mal folgendes zusammenkopiert:
    Code:
    # Plugin zum Abfragen von Davis Wetterstationen, die per Weatherlink IP die Daten ins auf weatherlink.com veröffentlichen
    # Version 0.1 2012-08-07
    # Copyright: alexbeer (https://knx-user-forum.de/members/alexbeer.html)
    # License: GPL (v2)
    # Aufbau möglichst so, dass man unterhalb der Definitionen nichts ändern muss!
    # in Anlehnung an http://openautomation.svn.sourceforge.net/viewvc/openautomation/wiregate/plugin/generic/Googleweather
    
    ##################
    ### DEFINITION ###
    ##################
    
    my $weatherlink_url = "http://www.weatherlink.com/xml.php?user="; 
    my $user = "[Username]";		# Benutzername von weatherlink.com
    my $pass = "[Password]";		# Password von weatherlink.com
    
    # Variablen der Weatherlink - XML Datei
    my $davis_dewpoint_c = "10/2/0"; #   ; Taupunkt, z.B. 10.6 ==> DPT 9.001
    # hier folgen dann die weiteren Variablen, zwecks Übersichtlichkeit hier mal entfernt.
    
    $plugin_info{$plugname.'_cycle'} = 600; # Eigenen Aufruf-Zyklus setzen (Initialisierung/zyklisches prüfen) 
    					# nicht zu klein, da die Daten sowieso in längeren Perioden refresht werden
    					# und das Plugin auf die CF schreibt.
    
    #######################
    ### ENDE DEFINITION ###
    #######################
    
    # Hauptverarbeitung
    use LWP::Simple;
    use XML::Simple;
    use Data::Dumper;
    use Encode qw(encode decode);
    # use open ":utf8";
    
    my $url = $weatherlink_url.$user."&pass=".$pass;
    my $xml = encode("utf8",get($url));
    # my $xml = get($url);
    die "Couldn't get it!" unless defined $xml;
    
    my $weather = XMLin($xml);
    
    knx_write($davis_dewpoint_c,$weather->{dewpoint_c},9);
    # hier werden dann die anderen Werte auf den Bus geschrieben
    Habt ihr einen Tipp, wie man dynamische XML-Strukturen am besten auswerten kann?
    Gruß
    alexbeer

    #2
    Sowas wie
    Code:
    if (defined $weather->{rain_storm_start_date}) { ...
    Im Sunnyweb-Plugin kann man sich zum Thema XML vielleicht noch das ein oder andere abgucken..

    Aber das Thema XML Auswertung ist viel Versuch&Irrtum, ich mach sowas erst in einem Standalone-Script und wenn das steht das Plugin (wobei das von der Davis aber recht "flach" ist)..

    Makki
    EIB/KNX & WireGate & HS3, Russound,mpd,vdr,DM8000, DALI, DMX
    -> Bitte KEINE PNs!

    Kommentar


      #3
      Hallo,

      vielen Dank für den Hinweis, werde mir das genannte Plugin mal näher zu Gemüte führen.

      P.S.
      Gerade weil die XML-Struktur recht überschaubar ist, fand ich das als Einstieg (für mich) ganz brauchbar.
      Gruß
      alexbeer

      Kommentar

      Lädt...
      X