'Subscribe callback not working with connect_async in paho-mqtt python
I've been trying to use the connect_async() method of paho-mqtt Client class. The on_connect() callback is working fine but the on_subscribe() callback is not working. How could I make it work?
import paho.mqtt.client as paho
from paho import mqtt
import time
def on_connect(client, userdata, flags, rc, properties=None):
print("On connect called!!")
def callback(client, userdata, message):
print(str(message.payload.decode("utf-8")))
def on_subscribe(client, userdata, mid, granted_ops, properties=None):
print("On subscribe called!!")
client_get = paho.Client(client_id='my_client', protocol=paho.MQTTv5)
client_get.tls_set(tls_version=mqtt.client.ssl.PROTOCOL_TLS)
client_get.on_connect = on_connect
client_get.username_pw_set("USERNAME", "PASSWORD")
client_get.connect_async('HOST_URL', 8883)
client_get.on_message = callback
client_get.on_subscribe = on_subscribe
client_get.loop_start()
client_get.subscribe("test/#", qos=1)
while True:
print("1")
time.sleep(10)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
