-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendArduino.py
More file actions
47 lines (40 loc) · 1.71 KB
/
sendArduino.py
File metadata and controls
47 lines (40 loc) · 1.71 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
import time, serial, datetime,sqlite3, sqlalchemy, pandas as pd
eng = sqlalchemy.create_engine('sqlite:////home/fish/tank.db')
metadata = sqlalchemy.MetaData()
metadata.reflect(bind=eng)
conn = eng.connect()
next_change = pd.read_sql_query('select * from suncycle limit 1', eng)
#print(datetime.datetime.now(), datetime.datetime.strptime(next_change.iloc[0]['dt'], '%Y-%m-%d %H:%M:%S.000000'))
try:
if datetime.datetime.strptime(next_change.iloc[0]['dt'], '%Y-%m-%d %H:%M:%S.000000') <= datetime.datetime.now():
ser = serial.Serial(
port='/dev/ttyACM0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
time.sleep(5)
if next_change.iloc[0]['instruction'] == 'night on':
counter = '1'
ser.write(counter.encode())
ser.close()
elif next_change.iloc[0]['instruction'] == 'day on':
counter = '2'
ser.write(counter.encode())
ser.close()
elif next_change.iloc[0]['instruction'] == 'day off':
counter = '1'
ser.write(counter.encode())
ser.close()
elif next_change.iloc[0]['instruction'] == 'night off':
counter = '4'
ser.write(counter.encode())
ser.close()
tankConn = sqlite3.connect('/home/fish/tank.db')
tankConn.cursor().execute("""delete from suncycle where id = '""" + str(next_change.iloc[0]['id']) + """';""")
tankConn.commit()
tankConn.commit()
except:
pass