-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_temperature.py
54 lines (48 loc) · 1.52 KB
/
log_temperature.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
import time
import datetime
import os
import glob
import logging
import RPi.GPIO as GPIO
import temperature_probe
import mysql.connector
import record_SQL_data
# Configs
time_interval=1
brewID=1
# Log file information
logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger(__name__)
handler=logging.FileHandler(os.getcwd()+"/"+
datetime.datetime.now().strftime('./logs/temp_log_debug_%H_%M_%d_%m_%Y.log'))
handler.setLevel(logging.INFO)
logger.addHandler(handler)
# Mysql startup info
mydb=mysql.connector.connect(
host="localhost",
user="dmueller",
passwd="Spartan1",
database="beerCode"
)
mycursor=mydb.cursor()
# Run main code to check temperature and operate heating/cooling
logger.info("Running main code...")
fout=open(datetime.datetime.now().strftime('./logs/temp_log_%H_%M_%d_%m_%Y.csv'),'w')
fout.write('time,temperature_air,temperature_liquid')
fout.write('\n')
try:
while True:
timeNow=datetime.datetime.now()
temperature_air=temperature_probe.read_temp(0)
temperature_liquid=temperature_probe.read_temp(1)
logger.info("Current time: "+str(timeNow))
logger.info("Current temperature, air: "+str(temperature_air))
logger.info("Current temperature, liquid: "+str(temperature_liquid))
fout.write(str(datetime.datetime.now())+','+str(temperature_air)+','+str(temperature_liquid))
fout.write('\n')
record_SQL_data.add_to_temp_log(mydb,mycursor,brewID,timeNow,temperature_air,temperature_liquid)
time.sleep(time_interval)
finally:
fout.close()
mydb.close()
print('Program ended, files closed.')