Tweeting the weather with a WS2350, Open2300 and Raspberry Pi

13 06 2012

Well the last day or two have brought another USB/Serial adapter and some success, the weather station (Ws2350) is now communicating with the Raspberry Pi via USB. So what was the problem and what was the solution?

The weather station is well know for being a picky little device (read non standard) about its serial comunications, you’ll find many horror stories from people who have had to link it via a USB adapter. It’s worth noting that even though I now have communications there may be further problems to come, so the side project of adding a serial port to the GPIO of the Raspberry Pi is only on hold.

Anyway the problem was having a USB/Serial adapter that both the Raspberry Pi and the weather station were happy with. Other people with similar issues have thought it may be power related as the Raspberry Pi doesn’t have a lot of power to pass to the USB, but these adapters draw less than 25mA and I tried via a powered USB hub too, it wasn’t a power issue.

Original (supplied with the weather station) FTDI adapter (FT232BM), worked with the weather station and using Ubuntu on a PC, hung the Raspberry Pi when accessed but was recognised by the Raspberry Pi when plugged in.

PL2323 Adapater, bought to try a different chipset. Raspberry Pi was quite happy with it, even hooked up a PSION Series 5 as a terminal (see this) but the weather station via Raspberry Pi or via Ubuntu on a PC did not want to play. This failure was almost certainly down to the WS2350 being picky about its adapters or possibly a non standard pin out on the adapter.

FTDI Adapter (FT232RL) I had a post about the problem at RasberryPi.org and someone confirmed that they had an FTDI device working with Raspberry Pi, a device using a newer chipset. I did some research at the chip manufacturer and decided to track down an adapter using the newer FT232RL chip, thinking that as the weather station was happy with the old FTDI adapter maybe it would be with the new one too. I found one at tronisoft.com and ordered it on Sunday evening, it arrived Tuesday am. It worked.

Now that communications were in full swing I started to hack a little bit of python code to read the Open2300 log file and tweet it, my current Cumulus software tweets the weather every hour or so and its pretty easy to tweet from code.

 

The tweet2300.py code

#
#tweet2300 Steve Wardell 2012
#
from subprocess import call
import twitter
#auth twitter
auth = twitter.OAuth("your", "twitter", "oauth", "keys")
t = twitter.Twitter(auth=auth)
t.account.verify_credentials()
#run log2300
call(["rm", "log2300.txt"])
call(["log2300", "log2300.txt"])
#open and read the tweet.txt file produced by log2300
file = open("log2300.txt","r")
log2300 = file.read()
file.close()
#chop up the string to get only the basics we are interested in
words = log2300.split()
tweet = "Forecast " + words[17] + " : Wind " + words[8] + "mph " + words[10] + " : Baro " + words[15] + "hpa " + words[16] + " : Temp " + words[4] + "c" + " : Rain " + words[13] + "mm " + " : Humidity " + words[7] + "%"
#tweet the content of tweet.txt
t.statuses.update(status=tweet)
#the end

Its not very elegant but as a quick hack it did the job.

Open2300 is a suite of programs to read data from the Ws2350 by Kenneth Lavrsen (his web site). For this quick hack we first get authorised with twitter then the Log2300 program writes (appends in fact) to a file a short data stream from the Ws2350. As I just want a file with a single data set the code above first deletes any existing log then writes a new one. The log is then read into a python variable and split into an array, the array is then mashed up into a suitable order with some additional text to form a tweet.

All very basic stuff and quite a bodge but we get a tweet

This simple script could be added to a CRON job to run every hour and keep on tweeting. Now that I’m happy with basic communications and have a little bit of code and a tweet to show for my efforts I can focus on developing some python routines to make use of Open2300’s fetch2300 program to write feeds for my web site weather.60redwood.com and the live gauges.

More posts as progress is made





Raspberry Pi and the weather

29 05 2012

Ever since I heard about the Raspberry Pi project I knew that it would potentially be the ideal always on low power ‘pc’ to hook up to a weather station and fire data off to a web site. Realising that project has taken its first step with delivery of my first Raspberry Pi this week.

RaspberryPi

RaspberryPi

In outline the project is simple enough, use the Raspberry Pi device with a combination of pywws and Open2300 to read the data from my WS2350 weather station and ftp a data stream to my web site. Currently this is done using the excellent Cumulus software from Sandaysoft but this runs on a Windows based PC and finding a mini pc suitable isn’t cheap (which I regard as one of the main tenets of a hobby).

Currently my web site is built using various Cumulus bits but the principle is that Cumulus feeds a simple, structured text file every 15 seconds or so, via ftp, and the web site reads it and uses some basic JavaScript to dynamically update the page. A principle requirement of this project is that it either writes a compatible text file (in fact various text files for gauges and graphs etc) or I code a web site based converter that can take the Raspberry Pi feed and translate it.

Stage 1 will be to get the Raspberry Pi up and running with a stable OS, this should be fairly straightforward

Stage 2 will be interfacing the Ws2350 to the Raspberry Pi via USB (possibly via serial later)

Stage 3 will be seeing if pywws will run and read the ws2350, if not then some lower level investigation using Open2300 is going to be needed

Stage 4 will be to extract from Stage 3 a suitable file on a regular (cron) basis and ftp it to a web server (the web server will initially be one in my office, it may even be on the Raspberry Pi or another Raspberry Pi)

Each stage will be liberally inter spaced with as yet undefined quantities of alcohol which will be at various times proportional to success or inversely proportional to failure.

If any fellow weather geeks want to help out or just see how it goes I will try to blog progress here and no doubt on twitter via @stevewardell. If anyone has any ideas or suggestions or anything that may help this little venture I would be interested in hearing from you.

Let the hacking commence…

Update 30/5/12

Stage 1 held up a little awaiting some essential parts that I forgot to order initially then forgot again when I eventually got a shipping notice. Anyway, parts en route. I started to look in more detail at pywws and a few other similarly minded weather geeks have embarked on similar projects, so far it looks like the usb libs in the debian distro are dropping packets on the Raspberry Pi so there may be some issues there, also I still don’t know if pywws will even read my weather station at all.

In order to get things moving and determine if pywws was an option I set up on one of my Ubuntu servers in the office, after some fiddling to get the weather station recognised via usb/serial converter (Raspberry Pi has USB) and a few hours playing with pywws I’ve concluded it either doesn’t work with a WS2350 or I cannot get the right combination’s of usb libs to play with python. So pywws question passed to its author, in the meantime Open2300 checked out and compiled, a little configuration and success, a simple cron job has the weather station updating my Weather Underground site, all mostly thanks to the Open2300 code I have to say.

If I can decode the full memory map from the station with Open2300, which I think I can, then this looks like it should work out quite well, assuming it can be compiled on the RPi ofcourse





Redwood Lake Weather Station

2 04 2010

Over the last month of so I’ve been making a number of incremental changes to the web site for the Redwood Lake Weather Station. I still would love to build my own site from the ground up and a few prototypes have even gone from white board to web site and back again.

My biggest issue is instrumentation or gauges, Ive tried various offerings the most successful being the free gauges offered by Bindows but even these have left a lot to be desired, wide browser compatibility being top of a list of niggles.

So I decided, while I continue my search for the tools to build my own site, to apply a lot of the other tricks, tips and technology to my Cumulus based site from SandaySoft?

My weather station, a WS2350, is connected to an old server here in my office and via the excellent Cumulus software from Steve at  SandaySoft keeps the Redwood web site up to date.

Redwood Lake Weather Station Web Site

Redwood Lake Weather Station Web Site

So what are the key differences between the standard Cumulus web page and the Redwood site?

The old multi page standard site has been replaced by a single main page incorporating some of the data found on the old additional pages and driven by AJAX based dynamic updates based on a live data feed from the weather station. You can find details of the AJAX scripts on the Cumulus forum pages, implementing it was very simple.

The page has been reformatted a little with some minor tweaks to the CSS and the addition of a banner image (a picture of Redwood Lake, of course).

I have also implemented a data log to drive some graphs. The graphs are based on JPGraph package using the logging and data generation scripts by TNET Services, these are really good and very simple to get working. However they dont seem to deal with data gaps as I would like, I would prefer to see time on the graphs with no data rather than the period omitted. I’ve been looking at Open Flash Chart but have not really had the free time to define scripts to feed data in the JSON format required.

The navigation bar has been changed to allow me to include some great external content from Weather Underground and from Meteorologica, the standard Cumulus instrumentation gauges have been retained but I’m no fan of Silverlight and at best they are troublesome, which is a shame as I think Steve from SandaySoft has actually done a great job in building them.

One thing I always disliked about the standard Cumulus web site was the Moon phase graphic, so I’ve replaced it with some new images.

Overall I’m fairly pleased with the results, I think there is still a lot that could be done (time permitting of course). I would like to implement a better forecast, currently I’m using the simple (Zambretti based) forecast produced by Cumulus, the WS2350 doesn’t produce anything better itself as some weather stations do.

I think a forecast graphic and, if I can work out the scripting, a ‘current’ conditions graphic are next on the TO-DO list.