如何在Python的后台运行MQTT客户端?

时间:2019-02-26 00:31:16

标签: python mosquitto dronekit-python

我正在尝试连接到DroneKit-SITL并保持MQTT-Broker与loop_forever()一起运行。每当我通过MQTT收到消息时,我都希望通过dronekit python API将命令发送到无人机。同时,我想每5秒通过MQTT将无人机数据发送给其他客户端。

如何让我的dronekit-sitl类和mqtt-broker类相互交互?它们中的每一个都应该在线程或进程中运行吗?

1 个答案:

答案 0 :(得分:0)

我通过在这样的单独线程中运行循环来解决此问题:

clientloop_thread = Thread(target=self.connect)
clientloop_thread.start()

def connect(self):
    self._client.loop_forever()