eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.13k stars 723 forks source link

Wildcard subscriptions not receiving anything (jwt auth for broker) #762

Open MacherelR opened 7 months ago

MacherelR commented 7 months ago

Hi, I've deployed an EMQX cluster with the auth JWT plugin. Everything seems to work well as my client programm (written in python using paho.mqtt library) is able to connect to the broker and subscribe to a wildcard topic (in my case: E01/COMMANDS/#). Now the problem I'm facing is that whenever I publish a message on i.e E01/COMMANDS/REGISTER, the message is correctly received by the broker (see figure)

Screenshot 2023-11-27 at 3 31 02 PM

But those messages are never consumed by the client and therefore commands not treated... I was wondering whether anyone has faced this problem? My subscription is handled the following way:

self.mqtt_username = DEVICE_ID
self.mqtt_password = response.json()['accessToken']
self.mqtt_broker_url = MQTT_BROKER_URL
self.mqtt_broker_port = MQTT_BROKER_PORT
self.mqtt_client = mqtt.Client(MQTT_CLIENT_ID, clean_session=False)
self.mqtt_client.username_pw_set(self.mqtt_username, self.mqtt_password)
self.mqtt_client.on_connect = self.on_connect
self.mqtt_client.on_message = self.on_message
self.mqtt_client.on_disconnect = self.on_disconnect
""" FOR Now, unused callbacks"""
self.mqtt_client.on_publish = self.on_publish
self.mqtt_client.on_subscribe = self.on_subscribe
self.mqtt_client.on_log = self.on_log
## Sets last will and testament to indicate if the is offline due to deconnection
self.mqtt_client.will_set(STATUS_TOPIC, payload="offline", qos=2, retain=True)
... 
...
self.mqtt_client.connect(self.mqtt_broker_url,
                                     port=self.mqtt_broker_port,
                                     keepalive=60,
                                     session_expiry=60)
self.mqtt_client.loop_start()
self._logger.info(f"MQTT client connected to broker {self.mqtt_broker_url}:{self.mqtt_broker_port}")

And the subscription is set in on_connect callback as following:

def on_connect(self,mqttc, obj, flags, rc):
        mqttc.subscribe(COMMAND_TOPIC,qos=1)
        self.mqtt_connection_on = True
        print("rc: " + str(rc))

Where COMMAND_TOPIC is 'E01/COMMANDS/#'

petersilva commented 7 months ago

you're not providing enough information for anyone to say anything useful.