2013-12-27 09:33:23 +01:00
#!/bin/bash
2014-01-18 10:28:38 +01:00
zufall = 0
2014-01-24 17:00:27 +01:00
PFAD = "/var/www/" #Pfad zum Web-Verzeichnis
2014-02-16 11:14:45 +01:00
r = 0 # Backup-Zahl auf Null setzen
2014-01-24 16:36:39 +01:00
IFS = "; " #Spezial-Variable, enthält Trennzeichen zum Trennen von Luftdruck und -temperatur
2014-04-19 16:31:56 +02:00
re = '^[0-9]+$' # Regulärer Ausdruck, ob Variable eine Zahl ist
pushbullet_api_key = $( cat /home/pi/Temperaturmessung/Fremddateien/pushbullet_settings.txt | head -n 1)
pushbullet_device = $( cat /home/pi/Temperaturmessung/Fremddateien/pushbullet_settings.txt | tail -n 1)
2014-02-16 13:24:46 +01:00
gpio mode 13 out # gelb
gpio mode 12 out # rot
gpio mode 3 out #grün
2014-04-19 10:19:07 +02:00
gpio write 13 0 # nur grün einschalten
2014-02-22 10:51:50 +01:00
gpio write 12 0
2014-04-19 10:19:07 +02:00
gpio write 3 1
2014-01-24 17:00:27 +01:00
if [ $1 ] # if- und case- Abfrage für Startparameter
2013-12-27 09:33:23 +01:00
then
case " $1 " in
2014-02-01 18:45:20 +01:00
"-d" ) rm /home/pi/Temperaturmessung/dygraph.csv
2013-12-27 09:33:23 +01:00
; ;
2014-01-18 10:28:38 +01:00
"-h" ) echo -e "-d csv-Datei leeren \nfür weitere Informationen siehe http://lukaswiki.onpw.de/rasp oder https://github.com/Findus23/Temperaturmessung"
2013-12-27 09:33:23 +01:00
exit 1
; ;
*) echo "unbekannter Parameter - Für Hilfe -h"
exit
; ;
esac
fi
while true
do
2014-04-19 10:19:07 +02:00
2014-02-22 10:51:50 +01:00
uhrzeit = $( date +%Y/%m/%d\ %H:%M:%S)
2014-03-01 13:02:13 +01:00
uhrzeit_display = $( date +%d.%m\ %H:%M:%S)
2014-03-02 15:10:06 +01:00
uhrzeit_lang = $( date +%d.%m.%y\ %H:%M:%S)
2014-01-18 10:28:38 +01:00
#zufall=$(($zufall + $((RANDOM % 10)) - 5)) # a um eine zufällige Zahl zwischen -5 und 5 ändern
2013-12-27 09:33:23 +01:00
##a=a+[Zufallszahl von 0-32767] modulo 10 (um eine Zahl von 0-10 zu bekommen) -5 (-> -5 bis 5)
2014-01-18 10:28:38 +01:00
#zufall=$a
#load=$(cut -c 1,2,3,4 /proc/loadavg) # Load messen
2014-01-17 20:34:05 +01:00
rasp = $( /opt/vc/bin/vcgencmd measure_temp | cut -c 6,7,8,9) #Betriebstemberatur messen
2014-01-18 10:28:38 +01:00
#cpu=$(sensors |grep Core\ 0 |cut -c 18,19,20,21) #CPU-Temperatur, lm-sensors muss installiert sein, bei jedem PC anders
2014-02-16 09:56:57 +01:00
temp1 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-000802b53835/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l) #Innentemperatur
2014-02-16 10:55:08 +01:00
while [ " $temp1 " = = "-1.250" ] || [ " $temp1 " = = "85.000" ] || [ " $temp1 " = = "85.000" ]
2014-01-18 19:36:25 +01:00
do
2014-04-19 10:19:07 +02:00
gpio write 13 1
2014-01-18 19:36:25 +01:00
echo " ----Temp1: $temp1 "
temp1 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277abe1/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l)
2014-04-19 10:19:07 +02:00
gpio write 13 0
2014-01-18 19:36:25 +01:00
done
2014-02-16 09:56:57 +01:00
temp2 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277a5db/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l) #Gerätesensor 1
2014-02-16 10:55:08 +01:00
while [ " $temp2 " = = "-1.250" ] || [ " $temp2 " = = "85.000" ] || [ " $temp2 " = = "85.000" ]
2014-01-18 19:36:25 +01:00
do
2014-04-19 10:19:07 +02:00
gpio write 13 1
2014-01-18 19:36:25 +01:00
echo " ----Temp2: $temp2 "
temp2 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277a5db/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l)
2014-04-19 10:19:07 +02:00
gpio write 13 0
2014-01-18 19:36:25 +01:00
done
2014-01-24 17:00:27 +01:00
temp3 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-000802b4635f/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l) #Außensensor
2014-02-16 10:55:08 +01:00
while [ " $temp3 " = = "-1.250" ] || [ " $temp3 " = = "85.000" ] || [ " $temp3 " = = "85.000" ]
2014-01-18 19:36:25 +01:00
do
2014-04-19 10:19:07 +02:00
gpio write 13 1
2014-01-18 19:36:25 +01:00
echo " ----Temp3: $temp3 "
2014-01-24 17:00:27 +01:00
temp3 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-000802b4635f/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l)
2014-04-19 10:19:07 +02:00
gpio write 13 0
2014-01-18 19:36:25 +01:00
done
2014-02-16 09:56:57 +01:00
temp4 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277a5db/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l) #Gerätesensor 2
2014-02-16 10:55:08 +01:00
while [ " $temp3 " = = "-1.250" ] || [ " $temp4 " = = "85.000" ] || [ " $temp4 " = = "85.000" ]
2014-02-01 14:06:06 +01:00
do
2014-04-19 10:19:07 +02:00
gpio write 13 1
2014-02-01 14:06:06 +01:00
echo " ----Temp4: $temp4 "
temp4 = $( echo " scale=3; $( grep 't=' /sys/bus/w1/devices/w1_bus_master1/10-00080277a5db/w1_slave | awk -F 't=' '{print $2}' ) / 1000 " | bc -l)
2014-04-19 10:19:07 +02:00
gpio write 13 0
2014-02-01 14:06:06 +01:00
done
2014-02-22 10:51:50 +01:00
2014-06-15 11:04:46 +02:00
luft_roh = $( sudo python /home/pi/Temperaturmessung/Fremddateien/AdafruitDHT.py 2302 17) # Rohdaten des Luftfeuchtigkeits-Sensors
2014-02-28 18:17:55 +01:00
set -- $luft_roh
luft_temp = $1
luft_feucht = $2
2014-02-16 17:37:02 +01:00
while [ -z " $luft_roh " ] || [ " $( echo $luft_temp '>' 40 | bc -l) " -eq 1 ] || [ " $( echo $luft_temp '<' -20 | bc -l) " -eq 1 ]
2014-01-17 20:34:05 +01:00
do
2014-04-19 10:19:07 +02:00
gpio write 13 1
2014-01-18 19:36:25 +01:00
echo " ----Luft: $luft_roh "
2014-06-15 11:04:46 +02:00
luft_roh = $( sudo python /home/pi/Temperaturmessung/Fremddateien/AdafruitDHT.py 2302 17) # Rohdaten des Luftfeuchtigkeits-Sensors
2014-02-28 18:17:55 +01:00
set -- $luft_roh
luft_temp = $1
luft_feucht = $2
2014-04-19 10:19:07 +02:00
gpio write 13 0
2014-01-17 20:34:05 +01:00
done
2014-02-01 18:45:20 +01:00
druck_roh = $( sudo python /home/pi/Temperaturmessung/Fremddateien/Adafruit_BMP085_auswertung.py) # Rohdaten des Luftdruck-Sensors
2014-01-24 16:36:39 +01:00
set -- $druck_roh #Zerlegen mithilfe von IFS (siehe ganz oben)
temp_druck = $1
druck = $2
2014-02-22 10:51:50 +01:00
qualitat = $( sudo /home/pi/Temperaturmessung/Fremddateien/airsensor -v -o)
2014-04-19 16:31:56 +02:00
if [ " $qualitat " = "0" ] || ! [ [ $qualitat = ~ $re ] ]
2014-02-28 16:32:01 +01:00
then
qualitat = ""
fi
2014-02-22 10:51:50 +01:00
ausgabe = ${ uhrzeit } \, ${ temp1 } \, ${ temp2 } \, ${ temp3 } \, ${ temp4 } \, ${ luft_temp } \, ${ luft_feucht } \, ${ druck } \, ${ temp_druck } \, ${ rasp } ,${ qualitat }
2014-02-01 18:45:20 +01:00
echo $ausgabe >>/home/pi/Temperaturmessung/dygraph.csv
2014-02-22 10:51:50 +01:00
echo " $uhrzeit ${ temp1 } , ${ temp2 } , ${ temp3 } , ${ temp4 } , ${ luft_temp } , ${ luft_feucht } , ${ druck } , ${ temp_druck } , ${ rasp } , ${ qualitat } " #Ausgabe des aktuellen Wertes im Terminal
2014-03-01 13:02:13 +01:00
temp1_r = $( echo $temp1 | rev | cut -c 3- | rev)
temp2_r = $( echo $temp2 | rev | cut -c 3- | rev)
temp3_r = $( echo $temp3 | rev | cut -c 3- | rev)
temp4_r = $( echo $temp4 | rev | cut -c 3- | rev)
luft_temp_r = $( echo $luft_temp | rev | cut -c 3- | rev)
luft_feucht_r = $( echo $luft_feucht | rev | cut -c 3- | rev)
temp_druck_r = $( echo $temp_druck | rev | cut -c 2- | rev)
druck_r = $( echo $druck | rev | cut -c 2- | rev)
2014-03-10 19:07:52 +01:00
echo " $uhrzeit_display
$temp1_r
$temp2_r
$temp3_r
$temp4_r
$luft_temp_r
$luft_feucht_r
$temp_druck_r
$druck_r
$rasp
$qualitat " >/home/pi/Temperaturmessung/text.txt.temp
2014-03-02 15:10:06 +01:00
echo " $uhrzeit_lang , ${ temp1_r } , ${ temp2_r } , ${ temp3_r } , ${ temp4_r } , ${ luft_temp_r } , ${ luft_feucht_r } , ${ temp_druck_r } , ${ druck_r } , ${ rasp } , ${ qualitat } " >/home/pi/Temperaturmessung/text_ws.txt # Daten für Webseite
sudo cp /home/pi/Temperaturmessung/text_ws.txt ${ PFAD } text_ws.txt
2014-02-15 22:07:55 +01:00
mv /home/pi/Temperaturmessung/text.txt.temp /home/pi/Temperaturmessung/text.txt
2014-02-01 18:45:20 +01:00
sudo cp /home/pi/Temperaturmessung/dygraph.csv ${ PFAD } dygraph.csv
2013-12-27 09:33:23 +01:00
sleep 8 # kurz warten
2014-01-24 17:00:27 +01:00
r = $(( $r + 1 )) # Anzahl der Durchläufe zählen
if [ " $r " = = "1000" ] # und alle 1000 Durchgänge Sicherung anfertigen
2013-12-30 11:21:14 +01:00
then
2014-02-01 18:45:20 +01:00
cp /home/pi/Temperaturmessung/dygraph.csv /home/pi/Temperaturmessung/dygraph.csv.bak
2014-02-16 11:14:45 +01:00
python /home/pi/Temperaturmessung/Fremddateien/send.py "l.winkler23@me.com" "Backup" "" "/home/pi/Temperaturmessung/dygraph.csv" &
2014-04-19 16:31:56 +02:00
/home/pi/Temperaturmessung/Fremddateien/pushbullet_cmd.py $pushbullet_api_key note $pushbullet_device "Backup erfolgreich" " $uhrzeit_display "
2013-12-30 11:21:14 +01:00
echo "Backup"
2014-01-24 17:00:27 +01:00
r = 0
2013-12-30 11:21:14 +01:00
fi
2013-12-27 09:33:23 +01:00
done