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

Advertisements




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.