我正在尝试将大约500个标签的数据(每秒更改数据)从Paho MQTT发送到Cloud。最初接收到所有数据,但一段时间后开始丢失样本
我的部分代码
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
我希望所有的数据都以时间戳的形式发布到云上
不清楚您的
ConnectionClient()
是否每次围绕主循环打开和关闭一个连接。但是,看起来每次都要关闭连接(通过del objClient
)。如果是这样,我建议您在启动时创建一个mqtt.Client
,并连接到服务。然后每次运行主循环时,都会发送消息,在程序退出之前不要关闭连接您还可以检查服务提供者是否没有应用某些限制。每秒钟500个话题似乎相当多,除非你为服务付费
相关问题 更多 >
编程相关推荐