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