Unable to publish to MQTT

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

I am trying to add MQTT to a project. I am using Wiced 4.1.1 and an LSR Sterling 00950. I am trying to run the snip.secure_mqtt as an example. Running the example using the preconfigured test using mosquito works. The snip subscribes to the topic, publishes a message, and receives the message back. When switching to our broker an error is thrown when a publish is attempted. By commenting out the publish attempt I was able to subscribe to a topic and receive messages on that topic, so I know that I am in fact connecting to the broker and receiving messages from the broker. Knowing that publishing is the problem, I began to try to debug. I have determined the error happens in mqqtt_wait_for(). There is a check to see if event matches expected event. The event is WICED_MQTT_EVENT_TYPE_PUBLISHED but for some reason the expected event is WICED_MQTT_EVENT_TYPE_DISCONNECTED. I believe the error is deeper in the code but I can't determine what is causing the disconnect because the expected event is being set in mqtt_connection_event_cb() and wiced_mqtt_publish() is returning success. I haven't been able to isolate what is causing the disconnection and triggering the callback.

0 Likes
1 Solution
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

In the secure_mqtt.c snip, the MQTT publish and subscribe have used WICED_MQTT_QOS_DELIVER_EXACTLY_ONCE which is QOS 2. I was going through the RabbitMQ documentation and I found this link https://www.rabbitmq.com/mqtt.html where it is clear that the RabbitMQ MQTT Adapter does not support QOS2 in MQTT 3.1.1. So why did the mqtt_app_subscribe() work? In this blog http://www.rabbitmq.com/blog/2012/09/12/mqtt-adapter/ the author has stated that "While clients are permitted to request QoS 2 subscriptions, the adapter will only grant subscriptions up to QoS 1." This basically means that RabbitMQ downgrades the QOS 2 subscribers to QOS 1 that is why there was no error in mqtt_app_subscribe(). However, the author has said that "AMQP 0-9-1 does not define "exactly once" semantics for message delivery. For this reason the MQTT adapter does not support publishing messages at the QoS 2 (exactly once) level, or exchanging PUBREC, PUBREL or PUBCOMP messages with clients." This could probably be the reason why MQTT publish failed. Change the QOS in MQTT publish to QOS 1 and it should work correctly.

View solution in original post

1 Reply
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

In the secure_mqtt.c snip, the MQTT publish and subscribe have used WICED_MQTT_QOS_DELIVER_EXACTLY_ONCE which is QOS 2. I was going through the RabbitMQ documentation and I found this link https://www.rabbitmq.com/mqtt.html where it is clear that the RabbitMQ MQTT Adapter does not support QOS2 in MQTT 3.1.1. So why did the mqtt_app_subscribe() work? In this blog http://www.rabbitmq.com/blog/2012/09/12/mqtt-adapter/ the author has stated that "While clients are permitted to request QoS 2 subscriptions, the adapter will only grant subscriptions up to QoS 1." This basically means that RabbitMQ downgrades the QOS 2 subscribers to QOS 1 that is why there was no error in mqtt_app_subscribe(). However, the author has said that "AMQP 0-9-1 does not define "exactly once" semantics for message delivery. For this reason the MQTT adapter does not support publishing messages at the QoS 2 (exactly once) level, or exchanging PUBREC, PUBREL or PUBCOMP messages with clients." This could probably be the reason why MQTT publish failed. Change the QOS in MQTT publish to QOS 1 and it should work correctly.