The `on_message` method of the `paho.mqtt.client.Client` class in Python is a callback function that is triggered when a message is received on a subscribed topic from an MQTT broker. This method is typically overridden by the user to define custom behavior for handling the received message. The `on_message` method takes the following parameters: - `client`: The client instance for which the message was received. - `userdata`: Any user-defined data that was previously set in the client. - `message`: An instance of the `MQTTMessage` class that contains details about the received message, such as the topic, payload, QoS, and retained flag.
Within the `on_message` method, the user can perform specific actions based on the received message, such as processing the payload, updating variables, or triggering other functions. It is important to note that the `on_message` method should be kept as short and non-blocking as possible, to avoid blocking the MQTT client's event loop.
Python Client.on_message - 32 examples found. These are the top rated real world Python examples of paho.mqtt.client.Client.on_message extracted from open source projects. You can rate examples to help us improve the quality of examples.