forked from emintopal1905/Sera-Otomasyonu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sera.py
198 lines (161 loc) · 6.49 KB
/
sera.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
from EmulatorGUI import GPIO
#import RPi.GPIO as GPIO
import time
import traceback
import sqlite3
con =sqlite3.connect("degerler.db");
cursor = con.cursor();
def Sıcaklıknormalguncelle():
cursor.execute("SELECT * FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=30 WHERE isim='Sıcaklık'")
cursor.execute("UPDATE sera SET Durum='Normal' WHERE isim='Sıcaklık'")
con.commit()
def Sıcaklıkdikkatguncelle():
cursor.execute("SELECT deger FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=45 WHERE isim='Sıcaklık'")
cursor.execute("UPDATE sera SET Durum='Dikkat' WHERE isim='Sıcaklık'")
con.commit()
def hadi():
cursor.execute("SELECT deger FROM sera WHERE isim='Motor' ")
data=cursor.fetchall()
con.commit()
return data
def Nemnormalguncelle():
cursor.execute("SELECT * FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=50 WHERE isim='Nem'")
cursor.execute("UPDATE sera SET Durum='Normal' WHERE isim='Nem'")
print("SOn deger---")
for i in data:
print(i)
con.commit()
def Nemdikkatguncelle():
cursor.execute("SELECT * FROM sera")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=3 WHERE isim='Nem'")
cursor.execute("UPDATE sera SET Durum='Dikkat' WHERE isim='Nem'")
print("SOn deger---")
for i in data:
print(i)
con.commit()
def Motordurguncelle():
cursor.execute("SELECT * FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=0 WHERE isim='Motor'")
cursor.execute("UPDATE sera SET Durum='Duruyor' WHERE isim='Motor'")
print("SOn deger---")
for i in data:
print(i)
con.commit()
def Motorcalısguncelle():
print (cursor.execute("SELECT deger FROM sera where isim='Motor'"))
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=1 WHERE isim='Motor'")
cursor.execute("UPDATE sera SET Durum='Calısıyor' WHERE isim='Motor'")
def Sudurguncelle():
cursor.execute("SELECT * FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=0 WHERE isim='Su Pompası'")
cursor.execute("UPDATE sera SET Durum='Duruyor' WHERE isim='Su Pompası'")
print("SOn deger---")
for i in data:
print(i)
con.commit()
def Sucalısguncelle():
cursor.execute("SELECT * FROM sera ")
data=cursor.fetchall()
cursor.execute("UPDATE sera SET deger=1 WHERE isim='Su Pompası'")
cursor.execute("UPDATE sera SET Durum='Calısıyor' WHERE isim='Su Pompası'")
print("SOn deger---")
for i in data:
print(i)
con.commit()
def Main():
try:
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Su ver manuel
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Her Şeyi kapat
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Havalandırma motorunu aç manuel
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Sıcaklık 36 altı ve normal
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Sıcaklık 36 ve üstü
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Nem normal
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Nem fazla
GPIO.setup(4, GPIO.OUT, initial=GPIO.HIGH) # Su verilme durumu
GPIO.setup(17, GPIO.OUT, initial=GPIO.HIGH) # Motor çalışma durumu
GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW) # Sıcaklık Kontrolü altı
GPIO.setup(19, GPIO.OUT, initial=GPIO.LOW) # Nem kontrol
while(True):
data= hadi()
if(data==[(1,)]):
print("Motor Açık, Hava Üfleniyor..")
GPIO.output(17,GPIO.LOW)
Motorcalısguncelle()
time.sleep(7)
print("Sıcaklık Normale döndü..")
Sıcaklıknormalguncelle()
GPIO.output(9,GPIO.LOW)
time.sleep(5)
GPIO.output(17,GPIO.HIGH)
print("Motor Kapatıldı..")
Motordurguncelle()
time.sleep(1)
if (GPIO.input(14) == True):
print("Su Veriliyor..")
GPIO.output(4,GPIO.LOW)
Sucalısguncelle()
time.sleep(7)
print("NEm Normale döndü..")
GPIO.output(19,GPIO.LOW)
Nemnormalguncelle()
time.sleep(5)
GPIO.output(4,GPIO.HIGH)
print("Su Kapatıldı..")
Sudurguncelle()
time.sleep(1)
if (GPIO.input(18) == True):
print("Motor Açık, Hava Üfleniyor..")
GPIO.output(17,GPIO.LOW)
Motorcalısguncelle()
time.sleep(7)
print("Sıcaklık Normale döndü..")
Sıcaklıknormalguncelle()
GPIO.output(9,GPIO.LOW)
time.sleep(5)
GPIO.output(17,GPIO.HIGH)
print("Motor Kapatıldı..")
Motordurguncelle()
time.sleep(1)
if (GPIO.input(15) == True):
print("Motor ve Su Kapalı..")
GPIO.output(17,GPIO.HIGH)
GPIO.output(4,GPIO.HIGH)
time.sleep(1)
if (GPIO.input(25) == True):
print("Sıcaklık 36 derece altı (Normal)..")
GPIO.output(9,GPIO.LOW)
Sıcaklıknormalguncelle()
time.sleep(1)
if (GPIO.input(8) == True):
print("Sıcaklık 36 derece üstü DİKKAT!..")
GPIO.output(9,GPIO.HIGH)
Sıcaklıkdikkatguncelle()
time.sleep(1)
if (GPIO.input(16) == True):
print("Nem (Normal)..")
GPIO.output(19,GPIO.LOW)
Nemnormalguncelle()
time.sleep(1)
if (GPIO.input(20) == True):
print("Nem çok azaldı. Su veriniz.")
GPIO.output(19,GPIO.HIGH)
Nemdikkatguncelle()
time.sleep(1)
con.close()
except Exception as ex:
traceback.print_exc()
finally:
GPIO.cleanup()
Main()