#!/bin/sh # This is the script calling the metering program for various water metering # units. The return value is saved into a log file for each metering unit, # together with a date/time stamp. This script gets regularly called as a # cron job. # define logging root # lg=/home/chris/BTUmetering lg=MAINPROGROOT # serial device. Read link reference to keep short file name for libmodbus call serdev=$(readlink -e /dev/serial/by-id/*WATERSERIALDEVICE*) # address list of heat measurement units. adrlist=(1 2 3 4 5 6 64 31) #logfilenamelist logroot=("AHU1" "AHU2" "AHU3" "AHU4" "AHU5" "AHU6" "PCW2" "S14L3") # go through the list for (( i=0 ; $i<${#adrlist[*]} ; i++)) do adr=${adrlist[$i]} logfile=$lg/log/heat_${logroot[$i]}.log # generate time and response from water meter # response is kWh, Volume, power, temp_hi, temp_lo tm=$(date +"%D %T") $lg/meter_read/meter_read -a $adr -d $serdev -c >$lg/tmp retval=$? rb=$(cat $lg/tmp) # See if something silly happened; in that case, uncomment that line if [[ $retval -ne 0 ]] ; then echo "# $tm $rb" >>$logfile else echo $tm $rb >>$logfile fi done # here a call to the sms check code $lg/scripts/docheck.sh