This directory contains a loose collection of files / scripts / programs / etc for the logging / displaying of water metering data. It needs more cleanup and better documentation, but here is a start: 1. How it is supposed to work Water: The water consumption meters are connected to the logging machine with a RS485 interface running a modbus protocol. The RS485 loop is connected to the logging machine with a USB/RS485 converter. The one I use is based on a FTDI232B chip. The actual readout and modbus protocol dingdong is sorted out by a small C program "meter_read", which has a bunch of options to address various meters on that loop. It uses the libmodbus-3.0.2 library and returns the instantaneous values of a meter in plain text. The C program is called regularly as a cron job via a logging script (logscript.sh) since a resolution of one minute was considered sufficient. The logscript.sh code tests for errors and appends the latest reading, together with a timestamp, to a logfile. The contact to the outside world takes place via a set of cgi scripts in the apache web server running on this machine. A front page points to one script ("lastvalue") that displays the latest entry in the logfiles in a human-readable form, and to another one ("form") that generates a log file graphic for instantaneous power and chilled water temperatures. SMS warning: In case of a chilled water temperature problem, an SMS is sent via the SMS modem to numbers stored in a file "numbers" in the sms directory. Be aware that the modem needs to be configured for this first via the gammu package. Electricity: Very similar structure, but the communication with the meters follows a different protocol, and thus is connected to a different USB/RS485 converter. The corresponding files resides in the directory e_meter, and consist of a C program (getresponse_emeter.c) that does some chat protocol with a specific electricity meter (type Landis+Gyr ZMD405) according to the IEC 62056-21 protocol in its simplest version (a "/xxx?!" command). An awk script converts the structured reply from a meter into a single line suitable for adding to a log file. The script "e_logscript.sh" in the scripts directory (once configured) does the call to the C program for all attached meters, and adds the result to the log files for each meter. This script is called from the cron daemon every two minutes. The larger time spacing is due to the relatively slow response of electricity meters to readout requests. 2. Prerequisites: The following packages/abilities are needed: - C compiler, make - Perl, sed, awk - gnuplot (with png terminal driver) - apache2 - cron - the "tail" utility - gammu utility for SMS setup 3. Where to find stuff documentation: This directory contains manuals and protocol description documents. crontab_template: this can be copied into the crontab to establish regular meter readout. This file needs path configuration. gnuplot: Directory which contains some gnuplot test scripts to generate the graphics. One of them (combined_multi.gnu) is called by the cgi script "form" to generate the graphics. This file by now should not have any hard-coded paths in it anymore. libmodbus-3.0.2 Directory where the library is compiled in. This needs to be done for various architectures I have been running this on; go through a configuration/installation procedure as described in this directory. Check that the metering program finds the correct library with ldd or something. After compiling, you may need to reload the library cache with the ldconfig command. libmodbus-3.0.2.tar.gz: packed source for above directory log: Directory containing log files. Only here for convenience and testing, no content is saved in the svn repository. meter_read: Directory containing the C code, makefile and libraries for the water meter reading program. See source code for command line options of that program. The C program may need adjustments if the USB-to-serial converter changes address. e_meter: Directory that contains C code to read out the Landis+Gyr electricity meters, and an awk script to parse their response into something that is useful for logging. install: Various script templates and a configure/install script to make correct paths everywhere. This is now working relatively smoothly. See below how to install. scripts: a directory which holds various scripts after configuration. One of them is the log script, others are for monthly billing. sms: directory that contains a status file for temperature warnigs, and a "numbers" file with sms phone numbers that get sent a warning. web/apache: contains a configuration file that allows the cgi scripts to reside in a separate/cgi-bin/metering directory. This needs to be copied into the /etc/apache2/conf.d directory. web/cgi: Perl scripts that generate the dynamic content pages. They are supposed to reside in the cgi-bin/metering path for the web server. Hard-coded data/script paths get adjusted with the install script. web/htdocs: Directory containing the front page of the metering server web/img: Directory containing a dynamically generated image for test purposes. web/css: Contains a basic style sheet for the server page. 4. Installation At the moment, most of it is automated with a configuration / installation script in the install directory. No more hand-changing of paths are necessary, but I am not sure I captured all permission settings in the installation script. The current strategy for installation is as follows: a. Download the complete subversion repository into a directory of your choice. This can be a user directory and does not need to have specific superuser rights. b. Make sure the user who is supposed to run the logger is allowed to talk to the serial interface units, i.e., is in a group that can read/write to the corresponding /dev/ttyUSB devices. Eventually configure the names of the serial devices (such as serial numbers etc) if there is more than one serial device attached to the logging machine. This is the case if water meters, electricity meters and a GSM modem are attached to the logger. c. Make sure that libmodbus is installed and can be found by the system. After various makes, I needed a ldconfig to tell the library-cache about its existence. This version is now migrated to the library API 3.0 that allows also TCP connections. d. configure various scripts according to the file directories by executing the "configure" script in the install directory. e. Install all the files that reside outside the directory tree by executing the "install" script in the install directory. This also installs the crontab tables for the logs. f. Prepare an image directory in the web browser root. Adjust this in the form script. Make sure the directory is writable by the cgi user. I used /srv/www/htdocs/img2. Make sure that this directory is recognized by the apache2 server. For that, I had to make an entry in /etc/apache2/conf.d - the corresponding file is in the web/apache dir. g. If SMS messaging is used, conifgure gammu with gammu-config. Documentation to follow, but you need to know the SMS modem device node for that. This should go into the configure script as well, but I have not found a way yet to do this automatically. 5. ToDo - Ensure that automated installation code works smoothly (almost done) - Add electricity billing overview (waiting for meter connections) - Add SMS messaging scripts on water temperature failure (testing)