- Conexion funcando pendite de prueba total

parent 754f3408
Showing with 11 additions and 19 deletions
...@@ -83,8 +83,8 @@ class Conexion: ...@@ -83,8 +83,8 @@ class Conexion:
print("Desconectado") print("Desconectado")
def desubscribir(self,topic): def desubscribir(self,topic):
self.client.unsubscribe(topic) #self.client.unsubscribe(topic)
#print(f"Desubscrito topic : {topic}") print("Desubscrito topic : ",topic)
def checkMensages(self): def checkMensages(self):
self.client.check_msg() self.client.check_msg()
......
...@@ -6,31 +6,22 @@ from umqtt.robust import MQTTClient ...@@ -6,31 +6,22 @@ from umqtt.robust import MQTTClient
import conexion as cn import conexion as cn
"""
def sub_cp(topic, msg): def sub_cp(topic, msg):
print("Recibido topic", topic.decode(), " mensage ", msg.decode()) print("Recibido topic", topic.decode(), " mensage ", msg.decode())
subs = ["A3-467/GrupoL/Robot","A3-467/GrupoL/SincRobot"] subs = ["A3-467/GrupoL/Robot","A3-467/GrupoL/SincRobot"]
send = ["A3-467/GrupoL/Interfaz","A3-467/GrupoL/SincInterfaz"] send = ["A3-467/GrupoL/Interfaz","A3-467/GrupoL/SincInterfaz"]
#cx = cn.Conexion(subs,on_msg=sub_cp)
#cx.publicar(send[0],"BBBBBBBBBB")
cx = cn.Conexion(subs,sub_cp)
print("Creado")
while True:
cx.checkMensages()
"""
import mensajeRobot as m import mensajeRobot as m
mR = m.MensajeRobot() mR = m.MensajeRobot()
print("Creado")
print("creada conexion") print("creada conexion")
mapa = mR.getMapa() mapa = mR.getMapa()
print(mapa) print(mapa)
pos = (4,4) pos = (4,4)
mR.sendPosicion(pos) mR.sendPosicion(pos)
"""
""" """
robot = Robot() robot = Robot()
...@@ -43,4 +34,3 @@ robot.recorreRuta(mov,cas) ...@@ -43,4 +34,3 @@ robot.recorreRuta(mov,cas)
robot.recogePaquete() robot.recogePaquete()
"""
\ No newline at end of file
...@@ -11,12 +11,12 @@ class MensajeRobot: ...@@ -11,12 +11,12 @@ class MensajeRobot:
print("Inicizlizando") print("Inicizlizando")
def sub_cp(topic,msg): def sub_cp(topic, msg):
print("Recibido topic", topic, " mensage ", msg) print("Recibido topic", topic.decode(), " mensage ", msg.decode())
if(topic == self.topicSubs[-2]): if(topic.decode() == self.topicSubs[-1]):
self.sinc = True self.sinc = True
else: else:
self.mensaje = str(msg.decode('utf-8')) self.mensaje = str(msg.decode())
def on_message_default(client,userdata,message): def on_message_default(client,userdata,message):
...@@ -66,6 +66,7 @@ class MensajeRobot: ...@@ -66,6 +66,7 @@ class MensajeRobot:
def __sincronizacion(self): def __sincronizacion(self):
while(not self.sinc): while(not self.sinc):
self.conex.checkMensages()
self.conex.publicar(self.topicSend[-1],self.prefMsg['sinc']) self.conex.publicar(self.topicSend[-1],self.prefMsg['sinc'])
time.sleep(2) time.sleep(2)
print("SINCRONIZADO") print("SINCRONIZADO")
...@@ -78,6 +79,7 @@ class MensajeRobot: ...@@ -78,6 +79,7 @@ class MensajeRobot:
while(self.mensaje.split(self.sepMsg)[0] != self.prefMsg['mapa']): while(self.mensaje.split(self.sepMsg)[0] != self.prefMsg['mapa']):
self.conex.checkMensages()
time.sleep(2) time.sleep(2)
return self.mensaje.split(self.sepMsg)[1] return self.mensaje.split(self.sepMsg)[1]
...@@ -87,6 +89,7 @@ class MensajeRobot: ...@@ -87,6 +89,7 @@ class MensajeRobot:
self.conex.publicar(self.topicSend[0],self.prefMsg['pedido'] + self.sepMsg) self.conex.publicar(self.topicSend[0],self.prefMsg['pedido'] + self.sepMsg)
while(self.mensaje.split(self.sepMsg)[0] != self.prefMsg['pedido']): while(self.mensaje.split(self.sepMsg)[0] != self.prefMsg['pedido']):
self.conex.checkMensages()
#print(f"Esperando Pedido - {self.mensaje.split(self.sepMsg)[0],self.prefMsg['pedido']}") #print(f"Esperando Pedido - {self.mensaje.split(self.sepMsg)[0],self.prefMsg['pedido']}")
time.sleep(1) time.sleep(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment