-
Notifications
You must be signed in to change notification settings - Fork 5
/
Relay_server.py
75 lines (63 loc) · 2.91 KB
/
Relay_server.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
__author__ = 'Voronin Denis Albertovich'
import Server
import Relay_control
from SysLog import AddToLog
import Tempered
count_relay = 4
class Relay_client_thread(Server.ClientThread):
Relay = Relay_control.Relay(count_relay)
Tmpr = Tempered.TemperatureSensor
def run(self):
#self.get_session_info()
try:
while True:
if self.type_input_data() == 'data':
self.get_data()
except Exception:
AddToLog('Unknown reserving data type')
def get_data(self):
try:
AddToLog(self.sess.ip + '---' + 'Reserve main data...<-- ' + self.sess.data[5:])
self.sess.sql_ins_data()
AddToLog(self.sess.ip + '---' + 'Send confirm data... --> ' + self.details[0])
self.data_parse()
except Exception:
AddToLog(self.sess.ip + '---' + 'Connection refuse...' + self.details[0])
def data_parse(self):
s = 'data//'
if self.sess.data == 'data//status\r\n':
for i in range(1, count_relay + 1):
s += 'R' + str(i)+'-'+ self.Relay.Position[i - 1]
self.channel.send(bytes(s,'utf-8'))
AddToLog(s)
for i in range(1, count_relay + 1):
if self.sess.data == 'data//R'+ str(i) +'-on\r\n':
self.Relay.setPositionRelay(i,'on')
self.channel.send(bytes('R'+ str(i) +'-' + self.Relay.Position[i - 1]+"\r\n", 'utf-8'))
AddToLog('R'+str(i)+'-' + self.Relay.Position[i - 1])
self.sess.data = ''
if self.sess.data == 'data//R'+ str(i) +'-off\r\n':
self.Relay.setPositionRelay(i,'off')
self.channel.send(bytes('R'+ str(i) +'-' + self.Relay.Position[i - 1]+"\r\n", 'utf-8'))
AddToLog('R'+str(i)+'-' + self.Relay.Position[i - 1])
self.sess.data = ''
if self.sess.data == 'data//relays-off\r\n':
self.Relay.setPositionAll('off')
AddToLog('data//relays-off')
self.channel.send(bytes('relays-off', 'utf-8'))
self.sess.data = ''
if self.sess.data == 'data//relays-on\r\n':
self.Relay.setPositionAll('on')
AddToLog('data//relays-on')
self.channel.send(bytes('relays-on', 'utf-8'))
self.sess.data = ''
if self.sess.data == 'data//temp\r\n':
self.channel.send(bytes(self.Tmpr.GetTempandVlaga,'utf-8'))
AddToLog(self.Tmpr.GetTempandVlaga)
for i in range(count_relay):
if self.sess.data == 'data//R'+str(i)+'-status\r\n':
self.channel.send(bytes('data//R'+str(i)+'-' + self.Relay.Position[i-1]+"\r\n", 'utf-8'))
AddToLog('data//R'+str(i)+'-' + self.Relay.Position[i-1])
self.sess.data = ''
ServRel = Server.Server('192.168.1.4', 1800, Relay_client_thread)
ServRel.start_server()