-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_final.py
221 lines (205 loc) · 6.97 KB
/
control_final.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import os
import sys
from argparse import ArgumentParser
import subprocess
import time
from datetime import datetime
import Adafruit_DHT as dht
import requests
import cv2
import numpy as np
import threading
import boto3
up = "python3 irrp.py -p -g23 -fairconup"
down = "python3 irrp.py -p -g23 -faircondown"
onoff = "python3 irrp.py -p -g23 -fairconpower"
s3 = boto3.client('s3', '''need key'''
aws_access_key_id='',
aws_secret_access_key='')
cam = cv2.VideoCapture(0,cv2.CAP_V4L)
cam.set(3, 640) # set video widht
cam.set(4, 480) # set video height
arr = ""
myfile = ""
def print_real():
ret, img = cam.read()
now = datetime.now()
realti = str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)+str(now.second)
filename1 ='image/'+realti+'.jpg'
filename2 =realti+'.jpg'
cv2.imwrite("image/"+realti+".jpg",img)
bucket_name='objectdetection7220'
s3.upload_file(filename1,bucket_name,filename2)
def gpn():
for object in s3.list_objects(Bucket='objectdetection7220-1')['Contents']:
s3.download_file('objectdetection7220-1', object['Key'], object['Key'])
arr=object['Key']
myfile=open(arr,'r',encoding='utf-8')
mystring=myfile.read()
return int(mystring)
def check_hour():
now = datetime.now()
return now.hour
def check_month():
now = datetime.now()
month = int(now.month)
if(month==11 or month==12
or month==1 or month==2):
return 'heat'
if(month==5 or month==6
or month==7 or month==8):
return 'cool'
else:
return 'default'
def check_temp():
_,it = dht.read_retry(dht.DHT11,14)
return it
def set_temp(st,tmp):
if(st<tmp):
while(st==tmp):
if(os.system(up) != 0): '''up'''
print('up error')
break
print('temp on')
st+=1
if(tmp<st):
while(st==tmp):
if(os.system(down) != 0): '''down'''
print('down error')
break
print('temp down')
st-=1
#pn : person num
#it : indoor temp
#st : setted temp
#s : state
#sys : cool or heat
'''starting off'''
def main(init_temp):
sys=check_month()
s=0 #off
st=init_temp
if(sys=='cool'):
print('Start Cooling Control!')
print('======================')
while True:
hour=check_hour()
if(hour=='12' or hour=='17'): '''for lunchtime & closing hour'''
continue
print_real()
time.sleep(3)
pn=gpn()
time.sleep(2)
it=check_temp()
if(s==1 and (it<24 or pn==0)):
if(os.system(onoff) != 0): '''off'''
print('onoff error')
break
print('off')
s=0
else:
if(it<=26): '''꺼져있을 때 는 처음상황에서는 26도 보다 크면 on'''
continue
if(s==0 and (it==24 and 20<pn)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
'''set temp 24'''
set_temp(st,24)
elif(s==0 and (it==25 and 10<pn)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
if(10<pn<=20):
'''set temp 25'''
set_temp(st,25)
if(20<pn<=30):
'''set temp 24'''
set_temp(st,24)
elif(s==0 and (it>=26 and 0<pn)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
if(0<pn<=10):
'''set temp 26'''
set_temp(st,26)
if(10<pn<=20):
'''set temp 25'''
set_temp(st,25)
if(20<pn<=30):
'''set temp 24'''
set_temp(st,24)
else:
continue
if(sys=='heat'):
print('Start Heating Control!')
print('======================')
while True:
hour=check_hour()
if(hour=='12' or hour=='17'): '''for lunchtime & closing hour'''
continue
print_real()
time.sleep(3)
pn=gpn()
time.sleep(2)
check_temp()
if(s==1 and (it>20 or pn==0)):
if(os.system(onoff) != 0): '''off'''
print('onoff error')
break
print('off')
s=0
else:
if(it>=18): '''꺼져있을 때 켜는 처음상황에서는 18도 보다 작으면 on'''
continue
if(s==0 and (it==20 and pn<=10)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
'''set temp 20'''
set_temp(st,20)
elif(s==0 and (it==19 and pn<=20)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
if(0<pn<=10):
'''set temp 20'''
set_temp(st,20)
if(10<pn<=20):
'''set temp 19'''
set_temp(st,19)
elif(s==0 and (it<=18)):
if(os.system(onoff) != 0): '''on'''
print('onoff error')
break
print('on')
s=1
if(0<pn<=10):
'''set temp 20'''
set_temp(st,20)
if(10<pn<=20):
'''set temp 19'''
set_temp(st,19)
if(20<pn<=30):
'''set temp 18'''
set_temp(st,18)
else:
continue
else:
print("There's no need for cooling and heating!")
if __name__=='__main__':
parser = ArgumentParser(description='control Air Conditioner')
parser.add_argument("--input_initial_temp",help=" ")
args=parser.parse_args()
input_initial_temp=args.input_initial_temp
main(input_initial_temp)