#!/bin/bash
#
# $Id: get_temp,v 1.1.1.1 2002/10/27 21:18:34 adicvs Exp $
#
# Get the temperature from the sensor
#
# This script runs digitemp and places the output (temperature reading)
# in a file. It is best run from cron every few minutes.
#
# The digitemp process takes a while to get the temperature. This delay
# resultes in a short but annoying strech of silence before the temperature
# is spoken by the IRLP node. By reading the 'cached' temperature from a
# file this delay is eliminated.
#
# A suitable line in root's crontab would look like:
# */5 * * * * su - -c "/home/irlp/custom/speak_temperature/get_temp" repeater
#

# Make sure we are user repeater!!!
if [ `/usr/bin/whoami` != "repeater" ] ; then
  echo "This program must be run as user REPEATER!"
  exit 1
fi

# Make sure we have sourced the environment file
if [ "$RUN_ENV" != "TRUE" ] ; then
  echo "You must source the environment file first. Do this by running:"
  echo ". /home/irlp/custom/environment"
  exit 1
fi

# The path we live in
homedir=`dirname $0`

# Source config
. "$homedir/config"

# Create digitemrc file if it doesn't exist
if [ ! -f "$digitemprc" ]; then
    $digitemp -s$digitempdev -c$digitemprc -i
fi

# Write temperature to a file
$digitemp -c$digitemprc -q -t0 -o%.2F | sed 's/ *//g' > "$tempf"
$digitemp -c$digitemprc -q -t0 -o%.2C | sed 's/ *//g' > "$tempc"

