Skip to content
Tomoaki edited this page Jun 10, 2015 · 15 revisions

MQTT, a lightweight, easy to implement protocol for M2M, has been getting a lot of attention lately.
Because of the TCP/IP that MQTT uses, keeping session is mandatory.
In order to minimize battery consumption of a client device, we need to CONNECT whenever send PUBLISH message.
On the other hand, MQTT-SN works over sessionless protocol such as UDP, CPU can be put to sleep to save power when there is no communication.
MQTT-SN can be tried out easily, let me introduce you to a library.
One of the most famous MQTT libraries is the Paho Library. However the one we will see here has a different design concept from Paho’s.
Paho provides primitive and general functions, whereas this library provides application framework and MQTT-SN gateway for a specific purpose of the MQTT-SN client. Not for high performance application. It takes more than 2 seconds to publish message with QoS2.
PUBLISH along is enough to create an client application, no need to code SUBSCRIBE, SERCHGW, GWINFO, CONNECT and REGISTER.
Non Blocking I/O enables asynchronous communication. While PUBLISH to transmit data, at the same time the subscribed topic got executed when PUBLISH takes place. This also works on Arduino Ethernet (Flash 30KB, RAM 2KB) and Arduino with XBee as well.


Supported functions

  • QoS Level 0, 1, 2
  • SEARCHGW, GWINFO
  • CONNECT, WILLTOPICREQ, WILLTOPIC, WILLMSGREQ, WILLMSG
  • PINGREQ, PINGRESP
  • CONNACK, REGISTER, REGACK, SUBACK, PUBACK, UNSUBACK
  • SUBSCRIBE, PUBLISH, UNSUBSCRIBE, DISCONNECT

Implemented control flows:
Application program executes PUBLISH() function,
Protocol flow as berrow is conducted automaticaly.

             Client              Gateway               Broker
  user coding   |                   |                    |      
                |                   |                    |    
   PUBLISH() -->| --- SERCHGW ----> |                    |  
                | <-- GWINFO  ----- |                    |  
                | --- CONNECT ----> |                    |  
                | <--WILLTOPICREQ-- |                    |  
                | --- WILLTOPIC --> |                    |  
                | <-- WILLMSGREQ -- |                    |  
                | --- WILLMSG ----> | ---- CONNECT ----> |(accepted)     
                | <-- CONNACK ----- | <--- CONNACK ----- |  
                | --- SUBSCRIBE --> | ---- SUBSCRIBE --> |     
 [set Callback] | <-- SUBACK ------ | <--- SUBACK ------ |   
                | --- REGISTER----> |                    |  
                | <-- REGACK  ----- |                    |  
                | --- PUBLISH ----> | ---- PUBLISH ----> |      
                | <-- PUBREC  ----- | <---- PUBREC ----- |    
                | --- PUBREL  ----> | ----- PUBREL ----> |    
                | <-- PUBCOMP ----- | <---- PUBCOMP----- |        
                |                   |                    |        
                //                  //                   //      
                | --- PINGREQ ----> | --- PINGREQ ---->  |         
                | <-- PINGRESP----- | <-- PINGRESP-----  |                    
                //                  //                   //    
                |                   |                    |    
                | <-- REGISTER ---- | <--- PUBLISH ----- |<-- PUBLISH  
                | --- REGACK  ----> |                    |  
[exec Callback] | <-- PUBLISH  ---- |                    |  
                | --- PUBACK   ---> | ---- PUBACK  ----> |--> PUBACK  
                |                   |                    |  
                //                  //                   //       
                |                   |                    |    
DISCONNECT() -->| ---DISCONNECT---> |                    |  
                | <--DISCONNECT---- |                    |           
Clone this wiki locally