Sample MQTT SUBSCRIBE MESSAGE

Asked by Venkates Velayutham

Hi,
We are writing lightweight C Mqtt client which communicates with MQTT broker. We are sending SUBSCRIBE message in the following format:

1st byte - MQTT_SUBSCRIBE_COMMAND (0x82)
2nd - Remaining length
3rd and 4th byte - message id
remaining bytes - topic
last byte - 0

The subscribe command is not working using the above mentioned format. Can you provide us few sample SUBSCRIBE message that were used for mosquitto testing? This will really help us.

Regards,

Venky

Question information

Language:
English Edit question
Status:
Solved
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Solved by:
Venkates Velayutham
Solved:
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

Are you specifying the length of the topic string? That's the only bit I can see that's missing.

You can use test/packet-gen.c to get example command packets. I've just modified it to do subscribe commands. You'll have to get the latest code from the repository at http://bitbucket.org/oojah/mosquitto - see specifically http://bitbucket.org/oojah/mosquitto/src/tip/test/packet-gen.c

Revision history for this message
Venkates Velayutham (venky) said :
#2

Thanks Roger. When we tried to compile http://bitbucket.org/oojah/mosquitto/src/5a33eb4c0979/test/packet-gen.c using the Makefile in http://bitbucket.org/oojah/mosquitto/src/5a33eb4c0979/test/, we received the error undefined reference for functions _mosquitto_send_connect and _mosquitto_send_subscribe. It appears they are not exported in the shared library as they are meant for internal use. We replaced the above mentioned functions with mosquitto_connect and mosquitto_subscribe and compilation was successful. Just thought we mentioned this to you.

Thanks for your help.

Regards,

Venky