MQTT-SN TopicIdType flag

111 views
Skip to first unread message

AlemV

unread,
Feb 17, 2014, 4:01:24 AM2/17/14
to mq...@googlegroups.com
I am a little bit confused with the TopicIdType flag.

Due to MQTT-SN Protocol Specification (5.3.4 Flags) TopicIdType means:
0x00 - normal topic id
0x01 - pre-defined topic id
0x02 - short topic name

Paragraph 3 tells that:
Predefined topic ids are also a two-byte long replacement of the topic name, their mapping to the topic names is however known in advance by both the client’s application and the gateway/server.

So imagine a situation where a sensor registers any topic with the REGISTER message and receives the REGACK message with the registered topic_id value. Then the sensor wants to subscribe and publish to this topic. What TopicIdType flag should I use in the SUBSCRIBE and PUBLISH messages?

PUBLISH has no TopicName field, so should I set TopicIdType to "normal" or "pre-defined" to use already received topic_id value?
SUBSCRIBE has "TopicName or TopicId" field, so should I set TopicIdType to "pre-defined" to use already received topic_id value(I don't want to use topic name string)?

And what means "known in advance by both the client’s application and the gateway/server"? Hard-coded or after the client sent the REGISTER message?

Thanks,
Vladimir Alemasov

Seth Hoenig

unread,
Feb 17, 2014, 9:47:29 AM2/17/14
to mq...@googlegroups.com
Once you register a topic, you receive a topic_id that will from then on be associated with it. Use that topic_id, along with topicIdType=0x00 (normal topic id) to publish/subscribe to that topic.

Short topic name can be used only if you are subscribing/publishing to a 2 byte long topic - and want to avoid the registration step. In that case you can set topicIdType=0x02 and use the 2 bytes reserved for the topic to be the actual topic string.

A predefined topic name is something hard coded into both your gateway and your client - there is no registration or dynamic configuration. There are also no predefined topic names mandated in the MQTT-SN spec, so anything you implement is up to you. To use one, set topicIdType=0x01. Most likely, you'll want to configure some predefined topic names for interesting topics in the $SYS/ tree (which many MQTT brokers support only by convention).

Seth


--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQ Telemetry Transport" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/groups/opt_out.

AlemV

unread,
Feb 17, 2014, 12:45:47 PM2/17/14
to mq...@googlegroups.com

Once you register a topic, you receive a topic_id that will from then on be associated with it. Use that topic_id, along with topicIdType=0x00 (normal topic id) to publish/subscribe to that topic.


Ok, I can use topicIdType=0x00 (normal topic id) in the Publish message, but how to use it in the Subscribe message is not clear for me.

"5.4.15 SUBSCRIBE" tells:
TopicIdType: indicates the type of information included at the end of the message, namely “0b00” topic name, “0b01” pre-defined topic id, “0b10” short topic name, and “0b11” reserved.

There is no "normal topic id" option. When I choose topicIdType=0x00 I should use a topic name instead of the registered topic id.

 
Short topic name can be used only if you are subscribing/publishing to a 2 byte long topic - and want to avoid the registration step. In that case you can set topicIdType=0x02 and use the 2 bytes reserved for the topic to be the actual topic string.

A predefined topic name is something hard coded into both your gateway and your client - there is no registration or dynamic configuration. There are also no predefined topic names mandated in the MQTT-SN spec, so anything you implement is up to you. To use one, set topicIdType=0x01. Most likely, you'll want to configure some predefined topic names for interesting topics in the $SYS/ tree (which many MQTT brokers support only by convention).


Ok, thanks. It's clear for me.

Vladimir Alemasov

Seth Hoenig

unread,
Feb 17, 2014, 1:37:48 PM2/17/14
to mq...@googlegroups.com
I'm sorry, you are right. In the SUBSCRIBE (and UNSUBSCRIBE) case, you do not use REGISTER to attain a "normal topic id" association first. You simply set TopicIdType=0x00, and the full topic name you wish to subscribe to.

I believe the reasoning for this is to minimize the number of messages going across the network - it's an unusual case for a client to both publish and subscribe to the same topic, and using the REGISTER protocol just to set yourself up for a  SUBSCRIBE would just involve sending extra messages that aren't really necessary.

Seth


AlemV

unread,
Feb 18, 2014, 3:32:10 AM2/18/14
to mq...@googlegroups.com
Seth,

Thank you for your comments. They are very useful to me.

Vladimir
Reply all
Reply to author
Forward
0 new messages