Writing

Software, technology, sysadmin war stories, and more. Feed
Monday, May 30, 2011

Low-latency weather monitoring software

I used to live in a part of the country that actually had weather, so I installed a wireless weather station. This is a device where you mount a bunch of sensors around your house outside, and it uses a combination of alkaline batteries, solar cells, and rechargeable batteries to keep going. Every sensor had a transmitter and would "phone home" every minute or so.

I bought it as a kit at a Radio Shack store based on what appeared to be good support from free software I could run on Linux. When I got it home and actually hooked everything up, it was anything but. Whoever had designed this thing was obviously not thinking about response times, and I had to throw it out and start over.

The best-known free software at the time did everything "live" -- there was no buffering of data. That means when you asked it for the conditions, you had to sit there until it heard enough data squawks from the weather station/receiver box to be happy. The box itself did not accept any commands, as it turned out. It would just pass along whatever it got from the radio, and there was no way to prod the sensors into transmitting on demand.

As a result, if you wanted to render a big complicated thing with a bunch of separate data points, you had to sit there for up to a minute as all of the various sensors checked in. If they happened to collide or otherwise missed a transmission, you could sit for several minutes. I wonder whoever thought that making a command-line on-demand tool sit like that was a good idea.

Anyway, I had other plans. It looked like the only way to roll would be to have a daemon which just sat there and waited for activity on its serial port. Then it would have to decode it and hang onto that data. Other programs could come along later and ask that daemon for status, and it would just provide whatever it had cached. This would reduce the latency to a minimum, and would allow answering queries without annoying users.

By the time I got tired of messing with it, I had something which could build a web page on the fly and say what the weather was like. I also later added something to push snapshots into MySQL and then pull back from there and render entire days, including graphs of the temperatures. This stuff just isn't that complicated.

Temperature chart

I eventually got it to a point where it did everything I needed, so I stopped poking at it. Also, my day job started stealing more cycles and there was no desire to deal with user support, so it was never released. These days, there's basically no weather where I live, so buying another station is not in the cards, at least, not for my own purposes.