MQTT subscribe message

0 votes
Hello, this is my code where i am trying to subscribe to mqtt topic and receive the messages. It works fine and I am able to receive the message. My question here is if i am able to receive the message i need to return something like PASS and if not receiving the message FAIL or ERROR . Any suggestions on how this can be achieved
 

def on_connect(client, userdata, flags, rc):

    if rc == 0:

        print("Connected")

    else:

        print("Failed to connect,return code %d\n",rc)

def on_subscribe(client,userdata,msg):

    print(msg.topic+""+str(msg.qos)+""+str(msg.payload))

def on_message(client, userdata, msg):

    print("Message Received " + msg.topic + " " + str(msg.payload))

client = mqtt.Client()

client.on_connect = on_connect

client.on_message = on_message

client.connect('127.0.0.1', 1883)

client.subscribe("test/temp")

client.loop_forever()
Dec 9, 2021 in Python by Shiri

edited 5 days ago 10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP