显示错误:
未连接错误:5
使用此代理程序时工作:
broker="iot.eclipse.org"
代码
import paho.mqtt.client as mqtt
import time
broker="m**.cloudmqtt.com"
port=1***1
username="***"
password="***"
def on_connect(client, userdata, flags, rc):
if rc==0:
print("connected ok")
else:
print("Not connected ERROR:",rc)
client = mqtt.Client('python_client_Rtb')
client.username_pw_set(username, password)
client.on_connect=on_connect
client.connect(broker,port) #connect to broker
client.loop_start() #Start loop
time.sleep(4) # Wait for connection setup to complete
print("loop started")
client.loop_stop()
实际输出:
Not connected ERROR: 5
Not connected ERROR: 5
Not connected ERROR: 5
loop started
预期输出:
connected ok