MQTT连接服务器返回2

/*********************************************************************************
 *                          MQTT连接服务器返回2
 * 说明:
 *     MQTT Client总是连接不上服务器,返回值是2。
 *
 *                                              2017-12-1 深圳 南山平山村 曾剑锋
 ********************************************************************************/


一、参考文档:
    1. Python Paho/MQTT : Detecting Connect error
        https://stackoverflow.com/questions/42451427/python-paho-mqtt-detecting-connect-error
    2. paho-mqtt 1.3.1
        https://pypi.python.org/pypi/paho-mqtt

二、connection result
    The value of rc indicates success or not:
        0: Connection successful 
        1: Connection refused - incorrect protocol version 
        2: Connection refused - invalid client identifier 
        3: Connection refused - server unavailable 
        4: Connection refused - bad username or password 
        5: Connection refused - not authorised 
        6-255: Currently unused.

三、解决方法:
    设置一下Client Id就行了。
原文地址:https://www.cnblogs.com/zengjfgit/p/7942257.html