small refactor
This commit is contained in:
20
readSensor
20
readSensor
@ -13,7 +13,7 @@
|
|||||||
RETRY=3
|
RETRY=3
|
||||||
|
|
||||||
# Number of seconds to wait between retries
|
# Number of seconds to wait between retries
|
||||||
DELAY=3
|
DELAY=2
|
||||||
|
|
||||||
# Specify the temperature range where you expect the sensors will be operating
|
# Specify the temperature range where you expect the sensors will be operating
|
||||||
# This is simply used as a safeguard to detect implausible sensor readings
|
# This is simply used as a safeguard to detect implausible sensor readings
|
||||||
@ -36,7 +36,7 @@ declare -A SENSORS=( [0]=LuftTemp [1]=WasserTemp [2]=BodenTemp )
|
|||||||
|
|
||||||
# Location where the readings should be stored
|
# Location where the readings should be stored
|
||||||
OUTFILE="output"
|
OUTFILE="output"
|
||||||
|
RESULT=""
|
||||||
|
|
||||||
#
|
#
|
||||||
# no configuration/changes should be necessary below this line
|
# no configuration/changes should be necessary below this line
|
||||||
@ -44,7 +44,6 @@ OUTFILE="output"
|
|||||||
|
|
||||||
cd "$(dirname "$0")";
|
cd "$(dirname "$0")";
|
||||||
touch "$OUTFILE" 2> /dev/null
|
touch "$OUTFILE" 2> /dev/null
|
||||||
echo "Timestamp="`date +%s` > "$OUTFILE"
|
|
||||||
|
|
||||||
if [ ! -w $OUTFILE ]; then
|
if [ ! -w $OUTFILE ]; then
|
||||||
echo "Error: output file '$OUTFILE' not writeable"
|
echo "Error: output file '$OUTFILE' not writeable"
|
||||||
@ -64,13 +63,19 @@ function check_output () {
|
|||||||
read_sensor
|
read_sensor
|
||||||
check_output
|
check_output
|
||||||
else
|
else
|
||||||
echo "${SENSORS[$SENSORID]}=Error" > "$OUTFILE"
|
RESULT="$RESULT${SENSORS[$SENSORID]}=Error\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function write_results () {
|
function store_result () {
|
||||||
echo "${SENSORS[$SENSORID]}=${VALUE}" >> "$OUTFILE"
|
RESULT="$RESULT${SENSORS[$SENSORID]}=${VALUE}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
function write_to_file () {
|
||||||
|
echo "Timestamp="`date +%s` > "$OUTFILE"
|
||||||
|
|
||||||
|
echo -e "$RESULT" >> "$OUTFILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
for SENSORID in "${!SENSORS[@]}"
|
for SENSORID in "${!SENSORS[@]}"
|
||||||
@ -78,6 +83,7 @@ do
|
|||||||
CNT=0
|
CNT=0
|
||||||
read_sensor
|
read_sensor
|
||||||
check_output
|
check_output
|
||||||
write_results
|
store_result
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
done
|
done
|
||||||
|
write_to_file
|
||||||
|
|||||||
Reference in New Issue
Block a user