Paho MQTT client connection reliability (reconnect on disconnection)

前端 未结 1 877
感情败类
感情败类 2021-02-06 01:28

What is the most reliable way to use the Python Paho MQTT client? I want to be able to handle connection interruptions due to WiFi drops and keep trying to reconnect until it\'s

相关标签:
1条回答
  • 2021-02-06 02:17
    1. Set a client_id so it's the same across reconnects
    2. Set the clean_session=false connection option
    3. Subscribe at QOS greater than 0

    These options will help ensure that any messages published while disconnected will be delivered once the connection is restored.

    You can set the client_id and clean_session flag in the constructor

    client = mqtt.Client(client_id="foo123", clean_session=False)
    

    And set the QOS of the subscription after the topic

    client.subscribe(topic, qos=1)
    
    0 讨论(0)
提交回复
热议问题