v0.1, 01.06.1999
So after a while the whole system was shut down and isn't running any more at the moment.
Now my intention was to reactivate the weather station which was lying around full of dust. But of couse I didn't want to build the old modem system any more. So it was a very lucky moment for me, cause I searched for a chance to write a small linux device driver while I war reading a book about writing linux drivers. And because I like linux very much the idea was born to write some tools under linux to drive the weather station with an old PC and put the data into a SQL database, so everybody can access them over the network with all the nice standard tools.
Here you find some pictures of the "live" system here in Dillingen: pictures.html.
Here's an overview of the whole system. You can see two weather stations each with a datagrabber PC which distribute their data to the database server. The clients can then query the database server and retrieve the weather data.
Here is an overview of how the data travels through the three main parts shown above:
I wrapped around the structure of a kernel module.
The module is called petra and can be compiled on linux 2.0.x. 2.2.x doesn't work at the moment, cause there are some changes to the interface of kernel modules.
modprobe -v petra [petra_base=HEX_IOPORT] [petra_major=MAJOR_DEVICE_NUMBER]If you don't specify the petra_base parameter the default will be 0x378 which is normally the first parallel port in your PC.
After loading the module, you can »access« the weather station through several devices. Each corresponds to one data-channel of the station. So you can for example capture the temperature every 10 seconds but the windspeed only once per hour. It is also possible that different applications access the device simultanously, cause the kernel code can't be interrupted during a read. So a read of 2 bytes from one of the devices is an atomic operation.
Here is a table of the channels whith our station in Dillingen:
channel number | data | device |
---|---|---|
0 | temperature | /dev/petra0 |
1 | pressure | /dev/petra1 |
2 | humidity | /dev/petra2 |
3 | windspeed | /dev/petra3 |
4 | winddir | /dev/petra4 |
5 | unused | |
6 | rain | /dev/petra6 |
7 | unused |
If you read data, you must know that every two bytes represent one value from the station. It's range is between 0 and 4096 cause the D/A converter in the station can handle 12 bit. The remaining bits are simply set to zero by the driver.
The driver also supports two IOCTL calls. One to reset the rain
counter and one to start the rain counter.
You can use them from user programs with a code similar to the
following:
if(ioctl(fd, PETRA_IOC_RESETRAIN) != 0) perror("error in ioctl\n"); if(ioctl(fd, PETRA_IOC_STARTRAIN) != 0) perror("error in ioctl\n");
Of course you have to include the petra.h
header file
which defines the PETRA_IOC_*
constants.
To compile the program of course you need the MySQL development system, which consists of the header files and the mysqlclient library. You can get MySQL for free from http://www.tcx.se. The SDK files are included there. You also need a C compiler and GNU make of course.
For usage of the MySQL function, you need of course a MySQL server anywhere reachable with TCP/IP. The port number is 3306 if this is relevant perhaps, cause you've got a firewall. But I wouldn't recommend opening an existing MySQL server for everybody, cause this could be a big security whole.
You also need a table on the server. grabdata by default uses the following table structure:
fieldname | datatype |
---|---|
ts | TIMESTAMP |
temperature | DOUBLE |
windspeed | DOUBLE |
winddir | DOUBLE |
humidity | DOUBLE |
pressure | DOUBLE |
rain | DOUBLE |
You get a similiar output to the following:
grabdata v0.2 - petra II weather station data grabber usage: grabdata [options] -h, --host=mysql_hostname specify mysql hostname -d, --db=mysql_database specify mysql database -t, --table=mysql_table specify mysql table -u, --user=mysql_user specify mysql user -p, --password=mysql_password specify mysql password -i, --intervall=grab intervall pause between each grab -l, --loop loop until killed -r, --rawdata also display raw sensoric data -c, --channel only display selected channel available channels: 0 - temperature 1 - pressure 2 - humidity 3 - windspeed 4 - winddir 6 - rain
If you want, you can use long and short options together without any problems. Just don't specify options for MySQL if you don't want to use it and the program won't complain about a missing server ;-)
When it is finished I will include it into the tarball distribution.
To sweeten your waiting you can see a preview here: sample.gif.
It is a temperature plot of our server room here in Dillingen, where we tested the weather station.
Because the hardware should be as cheap as possible we don't want to use a harddisk and we want to use our old i486 which also waits for the grabage collection to come by ;-)
So we need a very small solution which ideally fits onto one floppy (cause then you can reboot the machine without wating to change any disks...). And because linux is so flexible we can have a complete running linux onto one floppy.
Apart from the petra II driver and datagrabber the linux disk contains nothing more than:
Because it would not be very easy to compile such a mini distribution by ourselves, I decided to use a already existing solution. The so called LRP - Linux Router Project. Its aim is to develop a small linux system fitting on one disk which can be used to build routers. I just thrown out the programs, we would never need and included the petra driver (only one file, the kernel module) and the grabdata program.
[2] PHP/FI script language; http://www.php.net
[3] Apache web server; http://www.apache.org
[4] LRP - the linux router project; http://www.linuxrouter.org