PDA

View Full Version : Importing weather data



Chris Mason
2004-12-06, 15:00
I can get the data saved to the slimserver's shared folder eaily, will look
at the format.

Chris Mason
masonc (AT) masonc (DOT) com
Box 340, The Valley, Anguilla, British West Indies
Tel. (264) 497-5670 - Cell: (264) 235-5670 - Also (305)-735-3483
Fax: (264) 497-8463 - US Fax (815)301-9759
Yahoo IM: netconcepts_anguilla (AT) yahoo (DOT) com

> -----Original Message-----
> From: discuss-bounces (AT) lists (DOT) slimdevices.com
> [mailto:discuss-bounces (AT) lists (DOT) slimdevices.com] On Behalf Of
> Kevin Walsh
> Sent: Sunday, December 05, 2004 3:46 PM
> To: Slim Devices Discussion
> Subject: [slim] Importing weather data
>
>
> Chris Mason [lists (AT) masonc (DOT) com] wrote:
> > We have a Davis weather station and weatherview32 software for our
> > weather site http://www.altamer.com/article/articleview/149/
> >
> > We would like to export the current temp, humidity and wind
> > direction/speed and display on our slimp3s as a plugin. How
> hard is that
> > to do, any ideas, anyone want some work to do it?
> >
> If you can get the weather station to export its data into a file
> periodically, and you know the format of the file, then reading that
> file and displaying data with a SlimServer plug-in module will be
> easy enough.
>
> You will need to either get the exported data file onto the machine
> running the SlimServer, or provide a method for the plug-in to get
> the file itself (web server running on the weather station
> server etc.)
>
> It would be even better if the weather station provided some sort of
> server interface (SOAP or whatever), so that it could be
> polled directly
> by the plug-in module.
>
> --
> _/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
> _/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n
> W a l s h
> _/ _/ _/ _/ _/ _/ _/ _/_/ kevin (AT) cursor (DOT) biz
> _/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
>
>

jakematic
2005-12-07, 22:09
Did you folks get this working? I'm revisiting some plugins and also use WeatherView32. I know that the data we want is in wu.txt, but am pretty rusty in Perl and am hoping the code has already been written.

Thanks-
Jake

MrC
2005-12-08, 00:49
Seach the plugins for SuperDateTime here:

http://wiki.slimdevices.com/index.cgi?PluginInfoDisplay

jakematic
2005-12-08, 07:13
Yep, I already have that. Its an awesome plugin and it is my "off" screensaver.

I want to pull the data from my own station though instead of Weather.com .

I looked at the code and thought I'd check to see if anyone else had done it before I spent the time writing a shell script (I know shell scripting very well) to convert this:
http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID= &PASSWORD= &dateutc=2005-12-08+01%3A51%3A00&winddir=302&windspeedmph=000&windgustmph=000&humidity=051&tempf=042.3&rainin=0.00&baromin=29.64&dewptf=25.399&weather=&clouds=&softwaretype=Weather%20View%2032%20v60&action=updateraw

into a) the same format html as weather.com or b) rewrite the gotWeather subroutine to read my data or c) a combination of both.

The weather station software spits out that file once a minute, so I figure I can grab it and pull it every 5 or so into the plugin and spit my local (out in the back yard) data onto the SB display.


Jake

GoCubs
2005-12-08, 07:43
Yep, I already have that. Its an awesome plugin and it is my "off" screensaver.

I want to pull the data from my own station though instead of Weather.com .

I looked at the code and thought I'd check to see if anyone else had done it before I spent the time writing a shell script (I know shell scripting very well) to convert this:
http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?ID= &PASSWORD= &dateutc=2005-12-08+01%3A51%3A00&winddir=302&windspeedmph=000&windgustmph=000&humidity=051&tempf=042.3&rainin=0.00&baromin=29.64&dewptf=25.399&weather=&clouds=&softwaretype=Weather%20View%2032%20v60&action=updateraw

into a) the same format html as weather.com or b) rewrite the gotWeather subroutine to read my data or c) a combination of both.

The weather station software spits out that file once a minute, so I figure I can grab it and pull it every 5 or so into the plugin and spit my local (out in the back yard) data onto the SB display.
Hey Jake-
It looks like that URL just passes your weather station's data to wunderground.com to generate a nice looking web page with the data you pass to it.

I'm thinking the easiest way to accomplish what you want would be to modify the get/GotWeather SuperDateTime routines to parse the .txt file. If you have a web server running on the computer you have the weather station connected to you can make that file accessable through it. Then change the URL in SuperDateTime to use that file/URL instead. (If your slimserver and weather station are on the same computer you could also modify the code to directly access the file without a webserver, but that would probably require a lot more changes to the code.)

Next, you'll need to modify the parsing code for each of the pieces of data you're pulling from your file. If you post an example of this file, I can probably help you with this.

I believe I designed the plugin to function even if some of the data isn't found in your source data (such as long weather descriptions/forecasts/etc) so you should be okay.

I'd recommend using the latest beta of the plugin (4.0 beta 5) as your initial source.

-Greg

jakematic
2005-12-08, 08:43
Hi Greg-

That is exactly what I was thinking! The computer with the wx station does have a web server and I was planning to stick the file in the httpdocs dir so it can be served as well. (*Jake pines for symlinks on window like in unix*)

The file simply contains the url I posted earlier. Using awk -F \& '{print $x}' I was able to derive:

5=wind speed
6=wind gust
7=humidity
8=temp (f)
9=rainfaill
10=barometer

I know Perl has builtin things like sed and awk - looks like that is what SuperDateTime is using to extract the data from the weather.com page.

I'm not exactly sure how to handle parsing the url tho, which is actually a text file (wu.txt) containing the url that will get served by the wx computer. AND I don't want to much up SuperDateTime too badly in case later we want to be able to switch back to weather.com's feed.

Thanks for you advice and help. And yes I should dig out the O'Reilly Perl books collecting dust on my shelf.

Jake

GoCubs
2005-12-08, 09:52
Jake-

The .txt file only has one line in it right (it's overwritten each minute with the current readings)?

I don't have the time right now, but I think this should be pretty easy using Perl regular expressions. Since all of the data is on one line, you'll replace all the elsif's in gotWeather with one. Then within this you'll set all the appropriate SuperDateTime local variables.

-Greg

jakematic
2005-12-08, 16:29
Greg-

That's right, just the one line. Yes it updates it once a minute. I was thinking the same thing. I'll play around with it some and see if I can get the expression right. Thanks!

Jake

jakematic
2005-12-13, 10:25
Well I got it running. I didn't have time to figure out the perl with the work insanity lately, and a little bit of laziness so I copied the html file to the WX pc and sub'd things like WXTemp where the actual numbers were and then wrote a quickie shell script to sed the data from my file:

#/usr/bin/cat /cygdrive/c/Program\ Files/Weather\ View\ 32\ 600/wu.txt | /usr/bin/awk -F\& '{print $3 " "$5 " " $6 " " $7 " " $8 " " $9 " " $10}' > /cygdrive/c/Program\ Files/Apache\ Group/Apache2/htdocs/wx.html

Humid=$(/usr/bin/cat /cygdrive/c/Program\ Files/Weather\ View\ 32\ 600/wu.txt | /usr/bin/awk -F\& '{print $7}' | /usr/bin/awk -F\= '{print $2}')

Temp=$(/usr/bin/cat /cygdrive/c/Program\ Files/Weather\ View\ 32\ 600/wu.txt | /usr/bin/awk -F\& '{print $8}' | /usr/bin/awk -F\= '{print $2}' | /usr/bin/cut -c1-3)

Wind=$(/usr/bin/cat /cygdrive/c/Program\ Files/Weather\ View\ 32\ 600/wu.txt | /usr/bin/awk -F\& '{print $5}' | /usr/bin/awk -F\= '{print $2}')


#strip leading zeros
Humid=${Humid#0}
Temp=${Temp#0}
Wind=${Wind#0}

DateTime=$(/usr/bin/date)


#put it in a simpler format for later
echo ${Temp} " " ${Humid} " " ${Wind} " " ${DateTime} > /cygdrive/c/Program\ Files/Apache\ Group/Apache2/htdocs/wx.html


#kludge the template
/usr/bin/cat /home/Administrator/weather.com.template.html | /usr/bin/sed "s/WXHumid/$Humid/g" | /usr/bin/sed "s/WXTemp/$Temp/g" | /usr/bin/sed "s/WXWind/$Wind/g" > /cygdrive/c/Program\ Files/Apache\ Group/Apache2/htdocs/wu.html


As you can see I made provisions for when I get to modifying the Perl, but for now it works great even if it is a bit Rube Goldberg-ish....