Dec-07-2021, 02:01 PM
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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() |