Alle 5 Sensoren
authorChrisu Jähnl <chrisu@skorzak.priv.at>
Sat, 27 May 2017 22:01:15 +0000 (00:01 +0200)
committerChrisu Jähnl <chrisu@skorzak.priv.at>
Sat, 27 May 2017 22:01:15 +0000 (00:01 +0200)
seewasser.py

index e573e81..a17e794 100755 (executable)
@@ -5,7 +5,6 @@ import re
 import sys
 import csv
 import os
-import glob
 
 #May 27 21:32 /sys/bus/w1/devices/28-0416a1bab9ff
 #May 27 21:33 /sys/bus/w1/devices/28-0416a1ac66ff
@@ -31,8 +30,8 @@ def readsensor(sensorID):
 
     yesno = match.group(1)
     if yesno != "YES":
-        sys.exit(1)
-
+        return None
+        
     # Temperatur raus
     linetemp = file.readline()
     match = re.search(" t=([-0-9]+)",linetemp)
@@ -52,16 +51,19 @@ def readsensor(sensorID):
 
     file2.close()
 
-
-    print(temp)
-
     # Nur für die Ausgabe wird gerundet
-    print('Die Seetemperatur ist {:.1f}°C'.format(temp))
+    return temp
     
-#May 27 21:32 /sys/bus/w1/devices/28-0416a1bab9ff
-#May 27 21:33 /sys/bus/w1/devices/28-0416a1ac66ff
-#May 27 21:35 /sys/bus/w1/devices/28-0516a207a4ff
-#May 27 21:38 /sys/bus/w1/devices/28-0316a2193bff
-#May 27 21:38 /sys/bus/w1/devices/28-0316a21383ff
+sensoren = ["0416a1bab9ff","0416a1ac66ff","0516a207a4ff","0316a2193bff","0316a21383ff"]
+
+error = False
+
+for sensorID in sensoren:
+    temp = readsensor(sensorID)
+    if temp is None:
+        print("Fehler bei Sensor{}".format(sensorID))
+        error = True
+    else:
+        print('Sensor {}: {:.1f}°C'.format(sensorID,temp))
 
-readsensor("0416a1bab9ff")
\ No newline at end of file
+sys.exit(1 if error else 0)
\ No newline at end of file