Reputation: 19
I am trying to send data of around 500 tags (changing data per second) from Paho MQTT to Cloud. Initially all data is received, but after some time it starts losing samples.
Part of my code
def queue_consumer(queue):
global TestCount
global responseList
while True:
TestCount=0
for items in range(0, queue.qsize()):
responseList.append(queue.get_nowait())
queue.task_done()
item1="topicName"
if item1 is None:
print("BREAKKK")
break
else:
mqttmessage1 = json.dumps(responseList)
objClient = ConnectionClient()
objClient.client.publish("topicName", mqttmessage1 , qos=1)
responseList=[]
del objClient
time.sleep(1) # time after which the next items in queue
# would be processed for publishing
I expect all data to be published to the cloud with timestamp.
Upvotes: 1
Views: 395
Reputation: 33213
It is not clear if your ConnectionClient()
opens and closes a connection for each time around the main loop. However, it looks like you close the connection each time (via the del objClient
). If so, I suggest you create an mqtt.Client
on startup and connect to the service. Then each time you run your main loop send the messages and do not close the connection until your program exits.
You might also check that the service provider is not applying some limits. 500 topics every second seems like quite a lot unless you are paying for the service.
Upvotes: 1