-
Notifications
You must be signed in to change notification settings - Fork 5
/
temperhum.sh
executable file
·53 lines (44 loc) · 1.24 KB
/
temperhum.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# read the TEMPerHUM
while getopts d: option
do
case "${option}"
in
d) DEVICE=${OPTARG};;
esac
done
#echo "DEVICE = $DEVICE"
DATA_GOOD=0
COUNTER=1
while [ $COUNTER -lt 11 ] && [ $DATA_GOOD -eq 0 ]
do
DATE2=`date +"%Y/%m/%d %H:%M:%S"`
TEMPerHUM=`/usr/bin/timeout 5 /usr/local/bin/tempered $DEVICE`
echo -ne "$DATE2 $COUNTER $? $TEMPerHUM \n" >> /home/hivetool/tempered.log
if [[ -n $TEMPerHUM ]]
then
HUMIDITY=`echo $TEMPerHUM | grep -o "\-*[0-9]*\.[0-9]\%" | grep -o "\-*[0-9]*\.[0-9]"`
TEMP=`echo $TEMPerHUM | grep -o "temperature \-*[0-9]*\.[0-9]" | grep -o "\-*[0-9]*\.[0-9]"`
HUMIDITY_TEST=`echo "$HUMIDITY < 0" | bc`
TEMP_TEST=`echo "$TEMP > -50" | bc`
if [ $HUMIDITY_TEST -eq 0 ] && [ $TEMP_TEST -ne 0 ]
then
DATA_GOOD=1
else
HUMIDITY=""
TMEP=""
fi
fi
let "COUNTER += 1"
sleep $COUNTER
done
#echo $COUNTER $TEMP $HUMIDITY
if [[ $COUNTER -gt 11 ]]
then
echo "$DATE2 ERROR reading $DEVICE" >> /home/hivetool/error.log
fi
if test $COUNTER -gt 2
then
echo "$DATE WARNING reading $DEVICE: retried $COUNTER" >> /home/hivetool/error.log
fi
echo $TEMP $HUMIDITY