Difference between revisions of "Weather monitor"

From EttiWiki
Jump to navigationJump to search
m (Querying the Database)
(Querying the Database: added configuration of database directory)
Line 50: Line 50:
  
 
This library uses rrdtool's ''pipe mode'': It calls <code>"rrdtool -"</code> which causes rrdtool to wait for commands from stdin and output its responses to stdout. This mode is also very fast, because the rrdtool instance only needs to be started once and from then on serves all requests.
 
This library uses rrdtool's ''pipe mode'': It calls <code>"rrdtool -"</code> which causes rrdtool to wait for commands from stdin and output its responses to stdout. This mode is also very fast, because the rrdtool instance only needs to be started once and from then on serves all requests.
 +
 +
The tricky part is to configure the place of the database file differently depending on which machine it runs on (development machine or server). I decided to use Tomcat's ''Context Parameters''. I configured the context in <code>META-INF/context.xml</code> which resides in the deployable WAR file and is copied to a machine-specific directory upon first deployment. There I can modify it to fit the corresponding machine configuration. To access this context parameter in the source code I have to do the following:
 +
<code>@Context
 +
public void setServletContext(ServletContext context) throws IOException {
 +
servletContext = context;
 +
String rrdbdir = servletContext.getInitParameter("rrdbdir");</code>
  
 
== REST Server ==
 
== REST Server ==
 
The web server implements a [http://en.wikipedia.org/wiki/Representational_state_transfer REST] service which clients use to query data from the database. It is implemented in Java and uses the [http://jersey.java.net/ Jersey] framework.
 
The web server implements a [http://en.wikipedia.org/wiki/Representational_state_transfer REST] service which clients use to query data from the database. It is implemented in Java and uses the [http://jersey.java.net/ Jersey] framework.

Revision as of 16:47, 17 March 2013

The basic idea of the weathermon project is to obtain, record and monitor the weather at my home. All weather data sent from wireless sensors is to be stored in a database, from which different graphs are generated that can be monitored on a PC, over the Internet and on a smartphone.

System Overview

  1. Weather data is measured by sensors outside and inside the house. These sensors transmit all measured values via radio link.
  2. Transmitted values are received by a weather station and displayed for convenience.
  3. Transmitted values are also received by a small USB device which sends them to the PC connected.
  4. The PC reads received measurements and stores them in a database.
  5. From this database a web server serves all measurements to clients for display.

Sensors

The sensors and the weather station come as a set from ELV:

Receiver

For receiving the 868,35 MHz signals the following device from ELV is used:

Database

Data from weather sensors is stored in a Round Robin Database (RRDB) at different resolutions. This means, while high-resolution data is stored for the last 90 days, it also gets accumulated into daily data which is then kept for 10 years.

The database used is called RRDtool by Tobi Oetiker. It handles storing data at fixed intervals while updates come randomly, accumulating data and creating graphs. The latter is not used, instead a browser-based charting API is used to create dynamic charts.

Server

The server's job is to run the database and web server, so that clients can connect with a browser and retrieve and display all weather data.

  • The server is a standard Linux PC, but not a common desktop machine. Instead, a Raspberry PI is used.
  • The server runs an Apache Tomcat web server.

Interfaces

Protocol between Receiver and Server

Protocol between Server and Clients

  • REST with JSON

Software Components

Filling Database

Serial data coming from the receiver must be interpreted and then stored into the database.

Querying the Database

For fetching data from the database I decided to use the java-rrd library. In contrast to other Java implementations for interfacing an rrdtool database, this has the following advantages:

  • It uses rrdtool itself, so it is 100% compatible with the database file format. Other implementations re-implement rrdtool but use a slightly different file format. As I use the original rrdtool to enter data into the database, the Java components must be compatible with it.
  • It doesn't use JNI framework, which would cause the software to be not platform-independent any more. As I develop under Windows but run the server with Linux, this was no option either.


The java-rrd library is written by Peter Stamfest. The original announcement can be found here:

Very helpful is the brief introduction by Manuel Aldana:


This library uses rrdtool's pipe mode: It calls "rrdtool -" which causes rrdtool to wait for commands from stdin and output its responses to stdout. This mode is also very fast, because the rrdtool instance only needs to be started once and from then on serves all requests.

The tricky part is to configure the place of the database file differently depending on which machine it runs on (development machine or server). I decided to use Tomcat's Context Parameters. I configured the context in META-INF/context.xml which resides in the deployable WAR file and is copied to a machine-specific directory upon first deployment. There I can modify it to fit the corresponding machine configuration. To access this context parameter in the source code I have to do the following: @Context public void setServletContext(ServletContext context) throws IOException { servletContext = context; String rrdbdir = servletContext.getInitParameter("rrdbdir");

REST Server

The web server implements a REST service which clients use to query data from the database. It is implemented in Java and uses the Jersey framework.