Subscribing to Topics Using the Python MQTT Client

Video is ready, Click Here to View ×



We look at the subscribe process and examples of successful and unsuccessful subscription using a simple python demo script.
We look at the mid values and how then can be used to track subscripts. We also look success and failure codes.
The documentation for the client is here:

Other videos and Tutorials

Introduction to MQTT

————————
How to Use the Paho Python MQTT Client for Beginners

———-
Publish and Subscribe to a Cloudmqtt Broker

———–
Python MQTT Client The Loop and Callbacks explained

Have a question Use the comments or if you want help then use

If you find these videos useful then you might want to consider buying me a coffee

android eclipse tutorial for beginners

5 Comments on “Subscribing to Topics Using the Python MQTT Client”

  1. can u help me with this

    i am using paho MQTT Client for Arduino but i can only get message on topic1 i want to subscribe to multiple topic

    void subscribe(){

    client.subscribe(topic1, MQTT::QOS2, messageArrived1);

    client.subscribe(topic1, MQTT::QOS2, messageArrived2);

    }

    void messageArrived1(MQTT::MessageData& md)
    {
    MQTT::Message &message = md.message;

    Serial.print("Message ");
    Serial.print(++arrivedcount);
    Serial.print(" arrived: qos ");
    Serial.print(message.qos);
    Serial.print(", retained ");
    Serial.print(message.retained);
    Serial.print(", dup ");
    Serial.print(message.dup);
    Serial.print(", packetid ");
    Serial.println(message.id);
    Serial.print("Payload ");
    Serial.println((char*)message.payload);
    }

    void messageArrived2 (MQTT::MessageData& Md)
    {
    MQTT::Message &message = Md.message;

    Serial.print("Message ");
    Serial.print(++arrivedcount);
    Serial.print(" arrived: qos ");
    Serial.print(message.qos);
    Serial.print(", retained ");
    Serial.print(message.retained);
    Serial.print(", dup ");
    Serial.print(message.dup);
    Serial.print(", packetid ");
    Serial.println(message.id);
    Serial.print("Payload ");
    Serial.println((char*)message.payload);
    }

  2. Hey there, it's me (the one who asked the question on your website)!
    I'm not understanding how this function fits in (where it's called from) with the code that's not in the video:

    def on_subscribe(client,userdata,mid,granted_qos):

    I don't see it in the video code listing, so I assume (as you said) it relates to code that wasn't strictly needed to demonstrate comparing mid arguments?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.