-
Notifications
You must be signed in to change notification settings - Fork 3
/
AppSocket.py
82 lines (66 loc) · 1.51 KB
/
AppSocket.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
cnt1 = 0
cnt2 = 0
cnt3 = 0
import socket
from imp import reload
import os
import RPi.GPIO as GPIO
import time
HOST = "192.168.2.5"
PORT = 8888
global face_id
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ('socket create')
s.bind ((HOST, PORT))
print ('socket bind complete')
s.listen(2)
print ('socket now listening')
def do_some(input_button):
global cnt1
global cnt2
global cnt3
global face_id
while True:
#도어락 제어
if input_button == "open":
input_button = "open"
GPIO.setmode(GPIO.BCM)
door = 24
GPIO.setup(door,GPIO.OUT,initial=GPIO.LOW)
GPIO.output(door,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(door,GPIO.LOW)
#새로운 사용자 등록
elif input_button == "new":
if cnt1 == 0:
import newUser
face_id = newUser.face_id
print newUser.face_id
cnt1 = 1
else:
global newUser
reload(newUser)
face_id = newUser.face_id
input_button = "new"
#얼굴인식
elif input_button == "recog":
if cnt3 == 0:
import UserRecognition
cnt3 = 1
else:
global UserRecognition
reload(UserRecognition)
input_button = "server"
return input_button
while True:
conn, addr = s.accept()
print ("Connected by ",addr)
data = conn.recv(1024)
data = data.decode("utf-8").strip()
if not data: break
print ("doit: "+ data)
res = do_some(data)
print ("do :" + res)
conn.sendall(res.encode("utf-8"))
conn.close()
s.close()