MQTT

From openPicus Wiki
Jump to: navigation, search

Contents

Introduction

The MQTT is a communication protocol developed by IBM. It's not yet a standard but it is in the process of OASIS standardization.
The Message Queuing Telemetry Transport is entirely described at MQTT.org or at MQTT-IBM page.

This library is only for MQTT client and only for MQTT, not for MQTT-SN (Sensor Network, no-ip/udp devices).

DOWNLOAD

Version

V.1.1

  • Flyport GPRS is supported now
  • QWORD MQTT_Last_Response_Length()
  • BOOL MQTT_Last_Response_Ready()
  • void MQTT_Last_Response_Message(char * dest)
  • BYTE MQTT_Response_Sniffer(TCP_SOCKET socket) returns message hex-type or 0 now

V.1.0
This library is going to be constantly updated according to the feedback

Lastest library revision can be downloaded here


API List

MQTT_ConnectID

Fuction to send the CONNECT message with only the ID
returns the message length

int MQTT_ConnectID(char * dest, char * id, int keepalive, BOOL cleanflag)
Argument Description
char * dest pointer in which to store the message
char * id string with the client id
int keepalive keep alive interval in seconds
BOOL cleanflag clean session flag

MQTT_ConnectLOGIN

Fuction to send the CONNECT message with the ID and USER-PASSWORD
returns the message length

int MQTT_ConnectLOGIN(char * dest, char * id, int keepalive, BOOL cleanflag, char * user, char * password)
Argument Description
char * dest pointer in which to store the message
char * id string with the client id
int keepalive keep alive interval in seconds
BOOL cleanflag clean session flag
char * user string with the login user
char * password string with the login password

MQTT_ConnectWILL

Fuction to send the CONNECT message with the ID and WILL message
returns the message length

int MQTT_ConnectWILL(char * dest, char * id, int keepalive, BOOL cleanflag, char * willTopic, char * willMessage, BOOL willRetain, BYTE willQoS)
Argument Description
char * dest pointer in which to store the message
char * id string with the client id
int keepalive keep alive interval in seconds
BOOL cleanflag clean session flag
char * willTopic string with the will message topic
char * willMessage string with the will message
BOOL willRetain will message retain flag
BYTE willQoS will message QoS mode
  • MQTT_QOS_0
  • MQTT_QOS_1
  • MQTT_QOS_2
  • MQTT_QOS_3

MQTT_Connect

Fuction to send the CONNECT message
returns the message length

int MQTT_Connect(char * dest, char * id, int keepalive, char * user, char * password, char * willTopic, char * willMessage, BOOL cleanflag, BOOL willRetain, BYTE willQoS)
Argument Description
char * dest pointer in which to store the message
char * id string with the client id
int keepalive keep alive interval in seconds
char * user string with the login user
char * password string with the login password
char * willTopic string with the will message topic
char * willMessage string with the will message
BOOL cleanflag clean session flag
BOOL willRetain will message retain flag
BYTE willQoS will message QoS mode
  • MQTT_QOS_0
  • MQTT_QOS_1
  • MQTT_QOS_2
  • MQTT_QOS_3

MQTT_Check_Response

Function to check the server response

VOID MQTT_Check_Response(char * response)
Argument Description
char * response response message pointer

MQTT_Disconnect

Function to send the DISCONNECT message
returns the message length

int MQTT_Disconnect(char * dest)
Argument Description
char * dest pointer in which to store the message

MQTT_Publish

Function to send the PUBLISH message
returns the message length

QWORD MQTT_Publish(char * dest, char * message, char * topic, int messID, BYTE QoS)
Argument Description
char * dest pointer in which to store the message
char * message string with the message that you want to publish
char * topic string with the message topic
int messID message id number
BYTE QoS will message QoS mode
  • MQTT_QOS_0
  • MQTT_QOS_1
  • MQTT_QOS_2
  • MQTT_QOS_3

MQTT_Subscribe

Function to send the SUBSCRIBE message
returns the message length

int MQTT_Subscribe(char * dest, char * topic, int messID, BYTE QoS)
Argument Description
char * dest pointer in which to store the message
char * topic string with the message topic
int messID message id number
BYTE QoS will message QoS mode
  • MQTT_QOS_0
  • MQTT_QOS_1
  • MQTT_QOS_2
  • MQTT_QOS_3

MQTT_Puback

Function to send the PUBACK message
returns the message length

int MQTT_Puback(char * dest, int messID)
Argument Description
char * dest pointer in which to store the message
int messID message id number

MQTT_Pubrec

Function to send the PUBREC message
returns the message length

int MQTT_Pubrec(char * dest, int messID)
Argument Description
char * dest pointer in which to store the message
int messID message id number

MQTT_Pubrel

Function to send the PUBREL message
returns the message length

int MQTT_Pubrel(char * dest, int messID)
Argument Description
char * dest pointer in which to store the message
int messID message id number

MQTT_Pubcomp

Function to send the PUBCOMP message
returns the message length

int MQTT_Pubcomp(char * dest, int messID)
Argument Description
char * dest pointer in which to store the message
int messID message id number

MQTT_Unsubscribe

Function to send the UNSUBSCRIBE message
returns the message length

int MQTT_Unsubscribe(char * dest, char * topic, int messID)
Argument Description
char * dest pointer in which to store the message
char * topic string with the message topic
int messID message id number

MQTT_Pingreq

Function to send the PINGREQ message
returns the message length

int MQTT_Pingreq(char * dest)
Argument Description
char * dest pointer in which to store the message

MQTT_Response_Sniffer

Function to intercept the MQTT response
returns the hex (see defines) of MQTT message type or 0

BYTE MQTT_Response_Sniffer(TCP_SOCKET socket)
Argument Description
TCP_SOCKET socket the handle of the socket to use

MQTT_Last_Response_Message

Function to get the last MQTT response message

VOID MQTT_Last_Response_Message(char * dest)
Argument Description
char * dest pointer in which to store the message

MQTT_Last_Response_Length

Function to get the last MQTT response length
returns last MQTT response length

QWORD MQTT_Last_Response_Length()


MQTT_Last_Response_Ready

Function to get the last MQTT Ready flag
returns last MQTT ready flag

BOOL MQTT_Last_Response_Ready()

Defines

Following is a table of possible message type

  • 0x10 MQTT_CONNECT
  • 0x20 MQTT_CONNACK
  • 0x30 MQTT_PUBLISH
  • 0x40 MQTT_PUBACK
  • 0x50 MQTT_PUBREC
  • 0x60 MQTT_PUBREL
  • 0x70 MQTT_PUBCOMP
  • 0x80 MQTT_SUBSCRIBE
  • 0x90 MQTT_SUBACK
  • 0xA0 MQTT_UNSUBSCRIBE
  • 0xB0 MQTT_UNSUBACK
  • 0xC0 MQTT_PINGREQ
  • 0xD0 MQTT_PINGRESP
  • 0xE0 MQTT_DISCONNECT

The QoS (Quality of Service) parameter must be set up only using these defines

  • 0x00 MQTT_QOS_0
  • 0x01 MQTT_QOS_1
  • 0x02 MQTT_QOS_2
  • 0x03 MQTT_QOS_3

This define sets up the maximum length of the response

  • 800 MQTT_MAX_RESPONSE

MQTT_Last_Response

C structure for the last MQTT response that the client received

struct MQTT_Response
{
  BYTE 	COMMAND;
  QWORD LENGTH;
  BYTE 	RCODE;
  char  MESSAGE[MQTT_MAX_RESPONSE];
  BOOL 	READY;
  BOOL 	BUSY;
  BOOL  FLAG_128BIT;
};
 
struct MQTT_Response MQTT_Last_Response;


The values ​​of interest for the user are:

MQTT_Last_Response.COMMAND command/message type
MQTT_Last_Response.LENGTH message length
MQTT_Last_Response.RCODE result code for CONNACK
MQTT_Last_Response.MESSAGE response message
MQTT_Last_Response.READY indicates if this struct is ready
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox