Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
JuanCamiloUsecheRodriguez committed May 9, 2018
2 parents 30d1e7e + 32ab617 commit f876492
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 70 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@

*.xml
*.xml
.idea/workspace.xml
*.xml
*.xml
**/*.xml
2 changes: 1 addition & 1 deletion .idea/201810_01_softsecurity.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
60 changes: 60 additions & 0 deletions EntidadVirtual/API_REST/test_cerradura.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from flask import Flask, request, jsonify


import paho.mqtt.client as paho
app = Flask(__name__)
topico = "conjunto1/residencia1/cerradura"
client = paho.Client()
client.connect("broker.mqtt-dashboard.com", 1883)

#Insertar una cerradura
@app.route("/cerradura", methods=["POST"])
def insert_cerradura():
password = request.json['password']
posicion = request.json['posicion']
hora_inicio = request.json['hora_inicio']
hora_fin = request.json['hora_fin']

nuevo_candado = "0;"+password+";"+posicion;

#hl.agregar_candado(hora_inicio, hora_fin, posicion)
client.publish("horariocandado", hora_inicio+";"+hora_fin+";"+posicion)
client.publish(topico, nuevo_candado)
return jsonify(nuevo_candado)


@app.route("/cerradura", methods=["PUT"])
def update_cerradura():
password = request.json['password']
posicion = request.json['posicion']
nuevo_candado = "1;"+password+";"+posicion;
client.publish(topico, nuevo_candado)
return jsonify(nuevo_candado)


@app.route("/cerradura", methods=["DELETE"])
def delete_cerradura():
posicion = request.json['posicion']
nuevo_candado = "2;" + posicion
client.publish(topico, nuevo_candado)
return jsonify(nuevo_candado)



@app.route("/cerradura_all", methods=["DELETE"])
def delete_all_cerraduras():
mensaje = "3"
client.publish(topico,mensaje)
return jsonify(mensaje)


@app.route("/cerraduraHorario", methods = ["PUT"])
def change_state_cerradura():
posicion = request.json['posicion']
mensaje = "4;"+posicion

if __name__ == '__main__':
app.run(debug=True)



76 changes: 36 additions & 40 deletions EntidadVirtual/horarios/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Binary file not shown.
Binary file modified EntidadVirtual/horarios/__pycache__/horariosLogic.cpython-36.pyc
Binary file not shown.
50 changes: 28 additions & 22 deletions EntidadVirtual/horarios/horariosLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,20 @@
import threading
import time

from click._compat import _force_correct_text_reader

posicion = 0
hora_inicio = 0
hora_fin = 0

def on_publish(client, userdata, mid):
print("mid: "+str(mid))


"""def on_subscribe(client, userdata, mid, granted_qos):
def on_subscribe(client, userdata, mid, granted_qos):
print("Subscribed: " + str(mid) + " " + str(granted_qos))
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
"""
client = paho.Client()
client.on_subscribe = on_subscribe
client.on_publish = on_publish
"""client.on_subscribe = on_subscribe
client.on_message = on_message"""
client.connect("broker.mqtt-dashboard.com", 1883)
"""client.subscribe("conjunto1/residencia1/alerta")
#client.loop_forever()"""
topic = "conjunto1/residencia1/cerradura"

client.connect("broker.mqtt-dashboard.com", 1883)

class Candado(object):
def __init__(self, hora_inicio, hora_fin, index, estado):
Expand Down Expand Up @@ -62,15 +52,14 @@ def actualizar_estado(self):


candados = []
candado1 = Candado(10, 15, 1, True)
candado2 = Candado(13, 18, 2, True)
candados.append(candado1)
candados.append(candado2)


def agregar_candado(hora_inicio, hora_fin, index, estado):
cand = Candado(hora_inicio, hora_fin, index, estado)
def agregar_candado(hora_inicio, hora_fin, index):
cand = Candado(hora_inicio, hora_fin, index, True)
candados.insert(index, cand)
print("candado agregado")
c = agregar_candado(11,15,3)
c2 = agregar_candado(13,17,2)


def borrar_candado(index):
Expand All @@ -83,12 +72,29 @@ def borrar_todos():


def actualizador():
print("aacr")
while True:
time.sleep(60)
for c in candados:
time.sleep(10)
c.actualizar_estado()

def on_message(client, userdata, msg):
global hora_inicio,hora_fin,posicion
x=str(msg.payload)
x=x[2:-1]
print(x)
hora_inicio, hora_fin, posicion = x.split(";")
agregar_candado(int(hora_inicio),int(hora_fin),int(posicion))
client.on_message = on_message
a = threading.Thread(target=actualizador())
a.start()

client.subscribe("horariocandado")
client.loop_forever()




print("end")

2 changes: 1 addition & 1 deletion EntidadVirtual/notificadores/listenerHeartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def on_message(client, userdata, msg):
client.on_subscribe = on_subscribe
client.on_message = on_message
client.on_connect = on_connect
client.connect("broker.mqttdashboard.com", 1883)
client.connect("broker.mqtt-dashboard.com", 1883)
client.subscribe("conjunto1/residencia1/alerta")
client.loop_forever()

Expand Down

0 comments on commit f876492

Please sign in to comment.