-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproof_test.py
More file actions
73 lines (66 loc) · 2.35 KB
/
Copy pathproof_test.py
File metadata and controls
73 lines (66 loc) · 2.35 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
import datetime
import os
import glob
import logging
import RPi.GPIO as GPIO
import temperature_probe
def read_config_file(config_file):
# Standard function to read in config files.
with open(config_file,"r") as file:
lines=file.read().splitlines()
configs=[]
for line in lines:
line=line.split(",")
line[0]=int(line[0])
configs=configs+[line]
return configs
# Log file information
logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger(__name__)
handler=logging.FileHandler(os.getcwd()+"/"+
datetime.datetime.now().strftime('./logs/proof_test_%H_%M_%d_%m_%Y.log'))
handler.setLevel(logging.INFO)
logger.addHandler(handler)
# Read config file settings to establish run parameters.
logger.info("Reading config file data")
pinout_config_file="pinout.config"
pinout_data=read_config_file("./configs/"+pinout_config_file)
# Assign pinouts to relays
logger.info("Assigning pinouts to relays")
for idx,pinout in enumerate(pinout_data):
if pinout[1]=="relay_cool":
relay_cool=pinout[0]
if pinout[1]=="relay_hot":
relay_hot=pinout[0]
logger.debug("relay_cool: "+str(relay_cool))
logger.debug("relay_hot: "+str(relay_hot))
# Configure how the pins are interacted with
logger.info("Configuring how the pins are interacted with")
GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers
GPIO.setup([relay_cool,relay_hot], GPIO.OUT) # GPIO assign mode
GPIO.output([relay_cool,relay_hot], GPIO.LOW) # Initialize all pinouts to off
# Run main code to proof test system.
logger.info("Running proof test...")
time_interval=1.5 # Interval in seconds for when the system alternates
test_duration=60*60*3 # Total duration for the test in seconds
start=time.time()
counter=0
try:
while (time.time()-start)<test_duration:
timeNow=datetime.datetime.now()
logger.info("Time remaining: "+str(datetime.timedelta(seconds=(test_duration-(time.time()-start)))))
# Heat chamber
GPIO.output(relay_cool, GPIO.LOW) # Turn off cooler, if on
GPIO.output(relay_hot, GPIO.HIGH) # Turn on heater
logger.debug("Chamber heating now.")
time.sleep(time_interval)
# Cool chamber
GPIO.output(relay_cool, GPIO.HIGH) # Turn on cooler
GPIO.output(relay_hot, GPIO.LOW) # Turn off heater, if on
logging.debug("Chamber cooling now.")
time.sleep(time_interval)
counter=counter+1
finally:
GPIO.cleanup()
print('Proof test complete. Cycles completed: '+str(counter))