MQTT Subscribe

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 Shri
• 120 points
629 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.

Related Questions In Python

+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,212 views
0 votes
1 answer

Çannot implement web3.eth.subscribe on Web3 version 1.0.0-beta.27

As the error suggests, pub/sub is not ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,100 points

edited Jun 19, 2018 by Perry 2,028 views
0 votes
1 answer

MQTT protocol connection error

Ok so you need two libraries to ...READ MORE

answered Jul 6, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points

reshown Jul 6, 2018 by Vardhan 3,072 views
0 votes
1 answer

Send LoRa measures to Fiware IOT agent via MQTT

down vote I dont know if I understood ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,748 views
0 votes
1 answer

What is the maximum message length for a MQTT broker?

It's not entirely clear what you're asking ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
9,470 views
0 votes
0 answers

MQTT-Google Cloud pub/sub connection status!

Please help! So, I have a couple of ...READ MORE

Jul 20, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
834 views
0 votes
0 answers

Mosquitto Secure MQTT connection

My Question is regarding TLS/SSL MQTT connection. ...READ MORE

Jul 23, 2018 in IoT (Internet of Things) by Matt
• 2,270 points
600 views
0 votes
1 answer

MQTT connection consumes less power

HTTP(S) doesn't keep a connection open - ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
809 views
0 votes
1 answer

AWS IoT login from android MQTT client using IAM is not working

Seeing your comments and questions. I had ...READ MORE

answered Jul 24, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
2,352 views
0 votes
1 answer

Changing message format in KURA MQTT cloud client

The Eclipse Kura communicates with a MQTT ...READ MORE

answered Jul 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,177 views
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