-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
95 lines (84 loc) · 2.8 KB
/
main.py
File metadata and controls
95 lines (84 loc) · 2.8 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
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
from bottle import route, run, response, get, post, request, HTTPResponse
from cv2 import merge
from firebase_admin import initialize_app, storage
from firebase_admin import storage as admin_storage, credentials, firestore
from numpy import true_divide
import Face
import Storage
import Motores
import Nfc
import os.path
import serial,time
import json
import requests
import Dispensar as DispensarDosis
from datetime import datetime
import subprocess
ser = serial.Serial('/dev/ttyACM0',9600, timeout = 1)
subprocess.run("lxterminal -e bash -c 'python3 Alarmas.py ; read v'", shell=True)
time.sleep(1)
@post('/RegisterFace')
def RegisterFace():
fileName = request.body.getvalue().decode('utf-8') + ".xml" #Comunicación desde APP a Python
time.sleep(1)
if os.path.exists(fileName):
return HTTPResponse(body="False")
else:
if Storage.checkModel(fileName) == False:
print("No existe modelo")
Face.capture(fileName)
Face.train(fileName)
Storage.uploadFile(fileName)
print("awa")
return HTTPResponse(body="True") #Comunicación desde Python a APP
@post('/DeleteFace')
def DeleteFace():
fileName = request.body.getvalue().decode('utf-8') + ".xml"
print(fileName)
time.sleep(1)
if os.path.exists(fileName):
os.remove(fileName)
if Storage.checkModel(fileName):
Storage.delete(fileName)
return HTTPResponse(body=True)
@post('/RegisterNfc')
def RegisterNfc():
UID = Nfc.registrar(ser)
return HTTPResponse(UID) #regresar el UID
@post('/RecognizeNfc')
def RecognizeNfc():
Value = request.body.getvalue().decode('utf-8')
if(Nfc.reconocer(Value,ser)):
return HTTPResponse("True")
else:
ser.write(b'6')
time.sleep(3)
ser.write(Value[0][5].encode())
return HTTPResponse("False")
@post('/MoverMotores')
def MoverMotores():
value = request.body.getvalue().decode('utf-8')
value = chr(ord('@')+int(value))
Motores.mover(value,ser)
return HTTPResponse("True")
@post('/OpenDispensar')
def OpenDispensar():
value = request.body.getvalue().decode('utf-8')
value= json.loads(value)
name = value[0]
pills = json.loads(value[1])
hourmin = value[2]
alarm_repetir = value[3]
dosis_Id = value[4]
dosis_Seguridad = value[5]
numstring = value[6]
result = DispensarDosis.Dispensar(name,pills,hourmin,alarm_repetir,dosis_Id,dosis_Seguridad,numstring)
return HTTPResponse(str(result))
@post('/EnviarMensajes')
def EnviarMensajes():
value = request.body.getvalue().decode('utf-8')
value= json.loads(value)
ser.write(b'X')
time.sleep(3)
ser.write(str(value).encode())
run(host='localhost', port=8080, debug=True)