Error while trying to connect to Cloud-mqtt broker.

Showing Error:

Not connected ERROR: 5

Working while using this broker:

broker="iot.eclipse.org"

code

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()

Actual Output:

Not connected ERROR: 5
Not connected ERROR: 5
Not connected ERROR: 5
loop started

Expected Output:

connected ok

0 Answers