Reputation: 91
I am trying to send messages from one client to another using MQTT, both are publishers and subscribers. When QoS = 1, the messages are sent but sometimes duplicated. However, when I use QoS = 2, the messages are apparently not sent. Each client sends 4 messages each round, the payload is a chunk of a biggest bytearray.
Code for the publisher:
def publish_model(model):
SliceLength, FinalSlice, ByteArray, ArrayLength,SlicesNumber = get_lengths(model)
mqttc.publish("home/AWS1", ByteArray[ArrayLength - FinalSlice:ArrayLength], qos=2)
sleep(0.2)
for i in range(SlicesNumber-1,0,-1):
if i != 1:
print(SliceLength*(i-1)-SliceLength*i)
mqttc.publish("home/AWS1", ByteArray[SliceLength*(i-1):SliceLength*i], qos=2)
mqttc.loop()
print("model sent: home/AWS1")
else: ###The final chunk
mqttc.publish("home/AWS2", ByteArray[SliceLength*(i-1):SliceLength*i], qos=2)
mqttc.loop()
print("model sent: home/AWS2")
sleep(0.2)
Code for the subscriber:
mqttc.subscribe("home/AWS1", 2)
mqttc.subscribe("home/AWS2", 2)
while 1 == 1:
if connflag == True:
p = 1 ##line that does nothing only waits
else:
print("waiting for connection...")
I would like to emphasize that both are subscribers and publishers
The publisher just keeps : MQTT sending when sending the messages
Upvotes: 2
Views: 1039
Reputation: 1109
AWS IoT doesn't support QoS 2. When QoS level 2 is requested, the message broker doesn't send a PUBACK or SUBACK.
As a workaround, you can either
Or
Upvotes: 3
Reputation: 91
The problem here is that AWS IoT Core only allows QoS 0 and 1. Therefore the messages won't be sent if they have QoS=2.
Upvotes: 2