-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor2.py
57 lines (48 loc) · 1.73 KB
/
sensor2.py
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
51
52
53
54
55
56
57
#!/usr/bin/env python
from datetime import datetime # Zeit modul um festzulegen wie oft messungen gemacht werden
import time
def is_time(): # Alle 30 Minuten die Daten auslesen.
return True
now = datetime.now()
current_minute = now.strftime("%M")
print(current_minute)
if current_minute == "30" or current_minute == "00":
print("fa")
return True
else:
return False
sensor1 = "/sys/bus/w1/devices/28-3c01f0960400/w1_slave" # Sensor 1
sensor2 = "/sys/bus/w1/devices/28-3c01f096db57/w1_slave" # Sensor 2
f = open(sensor1, "r") # Auf beide Sensoren zugreifen
f2 = open(sensor2, "r")
sensor1_text = open("Sensor1.txt", "a")
sensor2_text = open("Sensor2.txt", "a")
data = f.read() # Die Daten auslesen
data2 = f2.read()
while True:
if is_time():
f = open(sensor1, "r") # Auf beide Sensoren zugreifen
f2 = open(sensor2, "r")
data = f.read()
data2 = f2.read()
print("Its time")
print("Data ready")
(discard, sep, reading) = data.partition(' t=')
t = float(reading) / 1000.0
print("Sensor 1 {:.1f}".format(t))
with open("Sensor1.txt", "a") as f:
f.write("\n")
now = datetime.now()
current_minute = now.strftime("%H:%M")
f.write(current_minute + " ," + str(t))
print("Data 2 ready")
(discard, sep, reading) = data2.partition(' t=')
t = float(reading) / 1000.0
print("Sensor 2 {:.1f}".format(t))
with open("Sensor2.txt", 'a') as f:
f.write("\n")
now = datetime.now()
current_minute = now.strftime("%H:%M")
f.write(current_minute + " ," + str(t))
else:
time.sleep(20)