commit c7738b7b2222926e35f56add9afe8801d786943e
parent 1e4c310f45356e1adc19894b2f97643706d52042
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Fri, 27 Sep 2024 12:26:34 -0300
Merge remote-tracking branch 'origin'
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/tps/2C2024/1/scripts/subscriber.py b/tps/2C2024/1/scripts/subscriber.py
@@ -4,7 +4,7 @@ import paho.mqtt.client as mqtt
broker = "broker.hivemq.com"
#broker = "mqtt-dashboard.com"
-topic = "tp1/kloeckner"
+topic = "tp1/klockner"
output_file = 'output.txt'
received_fragments = {}
last_fragment = False
@@ -14,22 +14,22 @@ def on_subscribe(self, mqttc, obj, mid, granted_qos):
def on_message(client, userdata, msg):
global last_fragment
-
-
+
# Decodificar mensaje: número de fragmento, tamaño, bandera de último fragmento, y contenido
payload = msg.payload.decode('utf-8')
fragment_info, fragment = payload.rsplit('|', 1)
fragment_number, fragment_size, is_last = map(int, fragment_info.split('|')[:3])
-
+
received_fragments[fragment_number] = (fragment_size, fragment)
- print(f"Fragmento recibido {fragment_number} (size: {fragment_size})")
+ print(f"Fragmento recibido {fragment_number} (size: {fragment_size})")
if is_last == 1:
last_fragment = True
-
+
# Reensamblar si es el último fragmento
if last_fragment:
reassemble_file(output_file)
- quit()
+ # quit()
+ last_fragment = False
def reassemble_file(filename):
with open(filename, 'w') as file:
@@ -47,4 +47,4 @@ client.connect(broker, 1883, 60)
client.subscribe(topic, qos=2)
# Mantener el cliente en funcionamiento
-client.loop_forever()
-\ No newline at end of file
+client.loop_forever()