DigiTemp Installation

Extract the source:

     cd .../DigiTemp
     tar -xvzf digitemp-3.2.0.tar.gz

Copy device_name.c, digitemp.c and digitemp.h from the patch directory to the source directory:

     cp /packages/DigiTemp/digitemp-3.2.0.patches/device_name.c \
        .../DigiTemp/digitemp-3.2.0/src
     cp /packages/DigiTemp/digitemp-3.2.0.patches/digitemp.c \
        .../DigiTemp/digitemp-3.2.0/src
     cp /packages/DigiTemp/digitemp-3.2.0.patches/digitemp.h \
        .../DigiTemp/digitemp-3.2.0/src

Build the source (probably, you'll want the DS9097U build):

     cd digitemp-3.2.0
     make ds9097u

Create a user to use for environmental monitoring:

     useradd -c "Environmental monitoring" -m -s /bin/nologin monitor

Create two subdirectories under the home directory of the monitoring user to hold the DigiTemp executables and scripts and to hold the environmental data:

     su
     mkdir /home/monitor/data
     mkdir /home/monitor/digitemp
     chown monitor:monitor /home/monitor/data
     chmod ug=rwx,o=rx /home/monitor/data
     chown monitor:monitor /home/monitor/digitemp
     chmod ug=rwx,o=rx /home/monitor/digitemp

Install the newly-built digitemp application in the executable directory:

     su
     cp .../DigiTemp/digitemp-3.2.0/digitemp /home/monitor/digitemp
     chown monitor:monitor /home/monitor/digitemp/digitemp
     chmod u=rwx,go=rx /home/monitor/digitemp/digitemp

Copy the shell scripts from the patch directory to the executable directory:

     su
     cd /home/monitor/digitemp
     cp /packages/DigiTemp/digitemp-3.2.0.patches/avgplot .
     cp /packages/DigiTemp/digitemp-3.2.0.patches/ftpavgs .
     cp /packages/DigiTemp/digitemp-3.2.0.patches/ftptemps .
     cp /packages/DigiTemp/digitemp-3.2.0.patches/maxplot .
     chown monitor:monitor avgplot ftpavgs ftptemps maxplot
     chmod u=rwx,go=rx avgplot ftpavgs ftptemps maxplot

If you don't have the patch directory, you're outta luck for the avgplot script but a rudimentary maxplot script can be found in .../DigiTemp/digitemp-3.2.0/perl. Here are the two FTP scripts.

ftpavgs:

     #! /bin/sh
     #
     # ftpavgs - Script to generate and then FTP the average temperature graph to
     # jump-gate at regular intervals.
     /home/monitor/digitemp/avgplot --wantcentigrade --wantfahrenheit \
                                    --wanthumidity /home/monitor/data/avgplot.png
     echo -e "user monitor temperature\\nbin\\nput \
             /home/monitor/data/avgplot_C.png \
             /var/www/Sentient/html/Environment/avgplot_C.png\\nput \
             /home/monitor/data/avgplot_F.png \
             /var/www/Sentient/html/Environment/avgplot_F.png\\nput \
             /home/monitor/data/avgplot_H.png \
             /var/www/Sentient/html/Environment/avgplot_H.png" | ftp -n jump-gate

ftptemps:

     #! /bin/sh
     #
     # ftptemps - Script to generate and then FTP the temperature graph to
     # jump-gate at regular intervals.
     /home/monitor/digitemp/maxplot --wantcentigrade --wantfahrenheit \
                                    --wanthumidity /home/monitor/data/tempplot.png
     echo -e "user monitor temperature\\nbin\\nput \
             /home/monitor/data/tempplot_C.png \
             /var/www/Sentient/html/Environment/tempplot_C.png\\nput \
             /home/monitor/data/tempplot_F.png \
             /var/www/Sentient/html/Environment/tempplot_F.png\\nput \
             /home/monitor/data/tempplot_H.png \
             /var/www/Sentient/html/Environment/tempplot_H.png" | ftp -n jump-gate

Find a free serial port on your system (we'll use /dev/ttyS1 in these examples). Have udev dynamically assign the applicable group permission to the selected tty device by hacking the udev rules for that define the "/dev" device space. These can be found in the /etc/udev/rules.d dirctory, typically in the file /etc/udev/rules.d/50-udev.rules. Add something to the effect of:

     # Special case for environmental monitoring devices.
     KERNEL=="ttyS1",                NAME="%k", GROUP="monitor", MODE="0660",
                                     OPTIONS="last_rule"

Add these lines before the general case rules for the tty devices.

Alternately, the best place to add your udev rules for environmental monitoring is in a separate rules file that you make up just for this purpose (that way, subsequent releases of the OS won't monkey with your rules for the serial port). We suggest calling the file "52_monitor-ttyups.rules. It should be created in the /etc/udev/rules.d directory. You should add something like the following to that file, depending on which serial port you need to use:

     # udev rules for environmental monitoring devices.
     # Special case for environmental monitoring devices.
     KERNEL=="ttyS1", GROUP="monitor", MODE="0660"

You'll need to reboot the system for the new udev rules to take effect so you should do so now. After reboot, check that the permissions have been assigned correctly to your chosen serial port:

     ls -l /dev/ttyS1

Plug the DS9097-U into the proper serial port, if you haven't already. 9-pin to 25-pin adapters can be used if they connect all the pins between the 9-pin and 25-pin connectors.

Install the environ script from the patches directory to the /etc/init.d directory and edit it to use the selected tty device. Here is the entire script:

/etc/init.d/environ:

     #! /bin/sh
     #
     # environ - Script to start/stop the environmental monitoring daemon.
     #
     # Revision History:
     # ewilde      2003Dec18  Initial coding.
     #
     # chkconfig: 2345 15 85
     # description: Environmental monitoring daemon
     #
     # Define the install path for the DigiTemp binaries, etc.
     INSTALL_PATH="/home/monitor/digitemp"
     SERIAL_PORT="/dev/ttyS1"
     CONFIG_FILE="/home/monitor/digitemp/.digitemprc"
     LOG_FILE="/var/log/temperature"
     LOG_INTERVAL=30
     if [ -f /etc/redhat-release ]; then
         . /etc/rc.d/init.d/functions
     fi
     # Before starting up, check to see if there is a config file (it gives us
     # the list of sensors to check).  If there isn't one, build it by walking
     # the LAN.  After that, start the temperature monitor.
     start()
         {
      # If there's no config file, walk the LAN and build it.
      if [ ! -f $CONFIG_FILE ]; then
          echo -n "Environ initializing environmental monitoring network: "
          $INSTALL_PATH/digitemp -i -s$SERIAL_PORT -c$CONFIG_FILE
          startval=$?
          if [ $startval = 0 ] ; then
              echo_success
          else
              echo_failure
              echo
              return $startval
          fi
          echo
      fi
      # Start up the temperature monitoring daemon.
      echo -n "Environ starting environmental monitoring network: "
      $INSTALL_PATH/digitemp -a -n0 -d$LOG_INTERVAL -c$CONFIG_FILE \
                             -l$LOG_FILE >/dev/null 2>&1 &
      startval=$?
      if [ $startval = 0 ] ; then
          touch /var/lock/subsys/environ
          echo_success
      else
          echo_failure
          echo
          return $startval
      fi
      echo
      return $startval
      }
     # Upon shutdown, kill the temperature monitoring daemon.
     stop()
         {
         echo -n "Environ stoping environmental monitoring network: "
         killproc digitemp
         stopval=$?
         if [ $stopval = 0 ] ; then
             rm -f /var/lock/subsys/environ
         fi
         echo
      return $stopval
      }
     # See how we were called.
     case "$1" in
      # Start.
      start)
          start
          RETVAL=$?
          ;;
      # Stop.
      stop)
          stop
          RETVAL=$?
          ;;
      # Restart or reload (whatever).
      restart|reload)
          stop
          start
          RETVAL=$?
          ;;
      # Conditional restart.
      condrestart)
          if [ -f /var/lock/subsys/environ ]; then
              stop
              start
              RETVAL=$?
          fi
          ;;
      # Give the status of all of the environmental monitoring components
      # that are running.
      status)
          if [ ! -f /var/lock/subsys/environ ]; then
              echo Envrion is down
              exit 1
          fi
          echo Envrion is functioning normally
            
          ;;
      # Help text.
      *)
          echo $"Usage: $0 {start|stop|restart|condrestart|status}"
          exit 1

esac

     exit $RETVAL

Copy the environ script to the init.d directory, make it executable and turn it on:

     su
     cp /packages/DigiTemp/digitemp-3.2.0.patches/environ /etc/init.d
     chown root:root /etc/init.d/environ
     chmod ugo+w /etc/init.d/environ
     /sbin/chkconfig --add environ
     /sbin/chkconfig environ on

Set up the log file used by environmental monitoring:

     touch /var/log/temperature
     chown root:monitor /var/log/temperature
     chmod ug=rw,o=r /var/log/temperature

Set up logrotate to rotate the log every week by adding a rotate configuration file to the logrotate config directory.

/etc/logrotate.d/environ:

     /var/log/temperature {
         notifempty
         missingok
         create 0664 root monitor
         copytruncate
     }

If you wish, you can simply start environmental monitoring by starting the init script:

     su
     /etc/init.d/environ start

This will initialize the config file, if it doesn't exist. Or, if you'd rather test things out a bit, you can begin by initializing the /home/monitor/digitemp/.digitemprc file with the following commands:

     su
     cd /home/monitor/digitemp
     ./digitemp -s/dev/ttyS1 -i

You should see a response like this:

     DigiTemp v2.1 Copyright 1997-2001 by Brian C. Lane
     GNU Public License v2.0
     ROM #0 : 1077790000000078
     ROM #1 : 10777A0000000036

The ROM numbers for your sensors will be different of course. They are listed in the order that the search routine finds them. You can then use the -t X command to read a single sensor at a time.

Read all the temperatures with this command:

     ./digitemp -a

You should see something like this:

     DigiTemp v2.1 Copyright 1997-2001 by Brian C. Lane
     GNU Public License v2.0
     Dec 29 20:52:28 Sensor 0 C: 22.90 F: 73.22
     Dec 29 20:52:29 Sensor 1 C: 1.70 F: 35.06

If it doesn't work, try running the initialization again. Make sure you have the right serial port and that it works. Try plugging an external modem into the port and check that it works by using the minicom terminal program. Also make sure the user running digitemp has permission to access the serial port you are using.

If you have a master server, that displays the environmental monitoring Web site, and you need to send the environmental data over to it at periodic intervals, you can add a couple of lines to crontab to do so:

/etc/crontab:

.

       .

# Push the temperature plot over to jump-gate every 15 minutes and the # average temperature plot once every day. 00,15,30,45 * * * * monitor /home/monitor/digitemp/ftptemps 02 00 * * * monitor /home/monitor/digitemp/ftpavgs