An instrumentation network for weather data on the Web

Use Java to display data from realtime devices to Web browser clients

This is the first installment in a series of Java Developer columns devoted to the concept of instrumentation over the Web. This month we'll build a low-cost weather station and interface it to the Web. First, we'll introduce the concepts of building Web-based data collection, monitoring, and control systems. Next, we'll present an application, the 1-wire weather station, that uses Java servlet technology to post weather data to a Web server. This will be followed by a discussion of how to use Java to build systems with similar and/or different requirements. We'll point you to established and recognized sources of expertise on the Web that are already running weather data but that don't use Java. You can judge for yourself whether using Java technology could improve the current status quo.

In this article we'll also lay the groundwork for new combinations of Java technology -- for example, XML and object stores -- so that low-cost, easy-to-maintain systems for storing large amounts of time-varying data can be understood and prototyped. We'll cover this theme in greater detail in future articles in this series, introducing Jini implementations and embedded-server versions, as well as introducing an authenticated interface to home-automation devices, which you will actually be able to build yourself. So, if you forget to turn the air conditioner on or want to change the thermostat, with just a few bucks and the information in these upcoming articles, you'll be able to do these things securely with Java technology.

Enabling devices for the Web really does create new services. We aren't talking about making your printer Internet-aware or using your PalmPilot to browse the Web; we're talking about smaller things, like pool temperatures, door locks, weather data -- actually, more data than we can list here -- that could be used by factories and business offices with geographically dispersed locations. The most common example of this is a WebCam. If you've never seen a WebCam, we've included a URL for one in the Resources section. Cameras are easy to interface because well-defined interfaces already exist for them. What if you were asked to make the services or data from some other device available on the Web? Common wisdom in the past has been to connect instrumentation to private networks. This article explores this huge new growth area for Web-based interfaces using Java and Jini. How would you do it? That's the question we'll start to answer in this series. To bring this home, we'll provide code examples that can be used with a real device. This article demonstrates how to interface Dallas Semiconductor's low-cost weather station to the Internet so that data from this weather station is available around the clock to interested Web users.

The article is divided into five parts:

  • An introduction to the weather station

  • Building the weather station

  • Posting realtime weather observations to a weather servlet (a Dallas Semiconductor example of an application using servlets)

  • A code example for a simple Swing application using the Dallas Semiconductor weather station API

  • Going forward

Before we launch into a discussion of these four issues, it's important to provide an explanation of realtime data collection and how Java enables this -- a central concept behind the weather station application presented in this article.

Java and realtime data collection

What we mean by realtime is that the readings are from a peripheral unit that is directly connected to a computer -- not collected from some database that was loaded even as recently as a few hours ago in preparation for vector operations on a supercomputer. Although this article focuses on the weather station from Dallas Semiconductor, the goal is to encourage discussion and design of solutions in line with the Java spirit of being open; in other words, diverse types of implementations (meaning different weather stations or other architectures) could be integrated that depart from this particular implementation.

In the future, several different types of weather stations could be offered by different manufacturers. These could use Ethernet and/or wireless protocols on the link layer as the communication media, with diverse protocols and APIs. The beauty of Java technology is that it has so many APIs that use a consistent methodology, enabling mere mortals to connect up different legacy applications with new applications and actually understand what they're doing! For example, you can connect a Jini application with an RMI-based application and, yes, some of that horrible CGI code that you don't want to change. The net result of having this power is to present an interface to users that hides all this complexity, yet leverages components that work. Java really facilitates migration to new technologies very well. We'll demonstrate this in later articles about embedded Web servers.

In the early 1970s, coauthor Rinaldo Di Giorgio worked for the Environmental Protection Agency (EPA), and the organization had as a national goal the instrumentation of the entire water system of the United States. If Java had been available then, applying the concepts in this article would have resulted in a system that would be useful to many countries interested in getting a handle on pollution and global warming. The architectures and techniques we're proposing here are ideally suited to massive deployments of data-collection systems, and Jini goes a long way toward making this type of deployment a reality.

Why does XML matter in realtime data collection?

Recently, there has been much discussion of XML. XML is an emerging standard that may solve the problem of data and formatting being bundled together as it is on an HTML page. JavaWorld featured a comprehensive article on XML, "XML for the absolute beginner," in its April issue. XML provides a mark-up language that allows weather data to be tagged independently of the source data. In this article on the weather station, whenever you see data that is in a format that seems proprietary, assume it will eventually be tagged with XML as the standard matures and its adoption increases. Collecting realtime data requires an understanding of the data format, the ability to save the data as quickly as it arrives, and the ability to process this data. Data from realtime devices comes in many different formats. As a developer you will have to decode this data and store it. At the current time we're not aware of devices that send XML data, but this would be useful in the marketplace -- although embedding the necessary circuitry for this would probably increase costs significantly. If a device could send XML data directly, you wouldn't need to develop proxies that take the input data stream, decode it, then process it, and then reformat it as XML when users request or want to use this data.

An introduction to the weather station

There are many weather sites on the Web. A partial list thereof is provided in the Resources section.

Recently, Dallas Semiconductor introduced its low-cost 1-wire weather station, which provides realtime readings of the following data:

  • Temperature
  • Wind speed
  • Wind direction

Here's what the weather station looks like:

Figure 1. The Dallas Semiconductor 1-wire weather station, left, replaces the items on the right with electronic components

One of the reasons we chose the 1-wire weather station jointly produced by Dallas Semiconductor and Texas Weather Instruments is its low-cost architecture that uses a one-wire bus with inexpensive support components. The weather station can communicate both data and power over a single wire cable. The station has various sensors that require power and the ability to transmit data. These sensors are the DS2401 directional indicators for the compass, the DS2429 for wind speed, and the DS1820 for temperature. For those of you interested in a very technical description of the circuitry, the 1-wire weather station article published in Sensors magazine (see Resources) provides an excellent description. Information on the core technical components, the technical data sheets for the DS2401, DS1820, DS2429, and the one-wire protocol can also be found there.

Building the weather station

To obtain a 1-wire weather station, see Resources. Here you'll also find directions on building the weather station. Once you have the kit in hand, building the weather station requires a modest amount of manual skill and a few tools. The following includes a list of the tools needed to build a weather station, a segment on mistakes to avoid while building it (based on personal experience!), and a note about testing the weather station.

Construction tools

Here's a list of the tools you'll need to build the weather station from the components contained in the kit:

  • A Phillips screwdriver
  • Adjustable pliers
  • Good silicon caulk (clear or white)
  • A compass
  • Additional cable -- enough of the twisted-pair type to place the device where you need it

Common construction mistakes and how to avoid them

The weather station kit contains two long rods with rectangular PCB boards on the end. One PCB board contains one magnet; the other contains two magnets. The PCB board with one magnet should be connected to the wind vane, which requires only one magnet. When the vane turns, the magnet passes between eight one-wire chips. These relate to the 8 points of the compass (north, northeast, east, southeast, south, southwest, west, and northwest). To resolve 16 points of the compass, as the magnet passes between two chips, both chips show up on the one-wire bus. Hence, we get NNE, ENE, ESE, SSE, SSW, WSW, WNW, and NNW. The PCB board with two magnets should be turned by the anemometer cups. Each time a magnet passes over the one-wire counting chip, it counts a single pulse. Two magnets get better wind-speed resolution.

The weather station has a top and a bottom area inside the plastic casing shell. When assembling the unit, a common mistake is to swap the PCB board for wind direction with the PCB board for wind speed. When building the weather station make sure the wind vane is on the bottom and that the PCB board with 8 of the DS2401s is in the bottom half of the casing.

Test the weather station before mounting it

It's easy to test the construction job you did. We recommend you do this before you go through the effort of installing the 1-wire weather station in a permanent location only to find out it doesn't work. Do yourself a favor and test it! You can easily test it by running the program FindiButtonsConsole.class. You should see output like this:

D:\Weather\examples\FindiButtonsjava FindiButtonsConsole 
FindiButtonsConsole Java console application: Version 0.00 
Adapter/Port iButton Type and ID Description 
------------------------------------------------------------ 
DS9097U COM2 DS1920 5B000000261EB010 Digital thermometer measu... 
DS9097U COM2 DS1920 4000000008F19C10 Digital thermometer measu... 
DS9097U COM2 DS2407 9E0000000ABE1612 one-wire Dual Addressable S... 
DS9097U COM2 DS2407 F70000000AE86D12 one-wire Dual Addressable S... 
DS9097U COM2 DS1982 7700000105F11809 1024 bit Electrically Pro... 
DS9097U COM2 DS2423 CC00000000CA3C1D one-wire counter with 4096 ... 
DS9097U COM2 DS2423 1500000000A5011D one-wire counter with 4096 ... 

Mount the station in a safe place

Depending on where you mount the weather station, additional hardware may be required. Be very careful when mounting the station in high places: wind forces can disconnect parts and fling them at windows or, even worse, at a person. So, for those of you living in regions that have severe wind conditions, be sure to firmly bolt down the station with double-locking bolts.

Connecting the 1-wire weather station to your computer

The cable to the 1-wire weather station requires pins 2 and 3 on the RJ11 connector to be run directly to the DS9097. Inside the housing of the DS9097 are chips that convert RS232 from your computer to the Dallas one-wire Protocol. In earlier JavaWorld articles, we presented a tutorial on serial ports; see the Resources section for a link to this tutorial. The one-wire interface from Dallas Semiconductor was designed to overcome some of the limitations of RS232. Specifically, the one-wire interface works over greater distances, supports higher speeds, requires fewer wires, and can deliver power to the device at the other end of the cable as shown in Figure 2.

Figure 2. The one-wire interface works over greater distances, supports higher speeds, requires fewer wires, and can deliver power to the device at the other end of the cable

Testing and configuration

In the Resources section we've supplied a link to the complete source code. There you will find three example applications:

  • FindiButtons -- A console application to find all iButtons on the one-wire bus.

  • WeatherConsole -- A console application to find and read a 1-wire weather station.

  • WeatherSwing -- A simple Java Swing application to find and read a 1-wire weather station. We'll discuss a simple program that uses this data.
1 2 3 Page 1
Page 1 of 3