The Cayenne MQTT mbed Library provides functions to easily connect to the Cayenne IoT project builder.

Dependents:   Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTConnect.h Source File

MQTTConnect.h

00001 /*******************************************************************************
00002  * Copyright (c) 2014 IBM Corp.
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Ian Craggs - initial API and implementation and/or initial documentation
00015  *    Xiang Rong - 442039 Add makefile to Embedded C client
00016  *******************************************************************************/
00017 
00018 #ifndef MQTTCONNECT_H_
00019 #define MQTTCONNECT_H_
00020 
00021 #if !defined(DLLImport)
00022   #define DLLImport 
00023 #endif
00024 #if !defined(DLLExport)
00025   #define DLLExport
00026 #endif
00027 
00028 
00029 typedef union
00030 {
00031     unsigned char all;  /**< all connect flags */
00032 #if defined(REVERSED)
00033     struct
00034     {
00035         unsigned int username : 1;          /**< 3.1 user name */
00036         unsigned int password : 1;          /**< 3.1 password */
00037         unsigned int willRetain : 1;        /**< will retain setting */
00038         unsigned int willQoS : 2;               /**< will QoS value */
00039         unsigned int will : 1;              /**< will flag */
00040         unsigned int cleansession : 1;    /**< clean session flag */
00041         unsigned int : 1;                 /**< unused */
00042     } bits;
00043 #else
00044     struct
00045     {
00046         unsigned int : 1;                           /**< unused */
00047         unsigned int cleansession : 1;    /**< cleansession flag */
00048         unsigned int will : 1;              /**< will flag */
00049         unsigned int willQoS : 2;               /**< will QoS value */
00050         unsigned int willRetain : 1;        /**< will retain setting */
00051         unsigned int password : 1;          /**< 3.1 password */
00052         unsigned int username : 1;          /**< 3.1 user name */
00053     } bits;
00054 #endif
00055 } MQTTConnectFlags; /**< connect flags byte */
00056 
00057 
00058 
00059 /**
00060  * Defines the MQTT "Last Will and Testament" (LWT) settings for
00061  * the connect packet.
00062  */
00063 typedef struct
00064 {
00065     /** The eyecatcher for this structure.  must be MQTW. */
00066     char struct_id[4];
00067     /** The version number of this structure.  Must be 0 */
00068     int struct_version;
00069     /** The LWT topic to which the LWT message will be published. */
00070     MQTTString topicName;
00071     /** The LWT payload. */
00072     MQTTString message;
00073     /**
00074       * The retained flag for the LWT message (see MQTTAsync_message.retained).
00075       */
00076     unsigned char retained;
00077     /**
00078       * The quality of service setting for the LWT message (see
00079       * MQTTAsync_message.qos and @ref qos).
00080       */
00081     char qos;
00082 } MQTTPacket_willOptions;
00083 
00084 
00085 #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 }
00086 
00087 
00088 typedef struct
00089 {
00090     /** The eyecatcher for this structure.  must be MQTC. */
00091     char struct_id[4];
00092     /** The version number of this structure.  Must be 0 */
00093     int struct_version;
00094     /** Version of MQTT to be used.  3 = 3.1 4 = 3.1.1
00095       */
00096     unsigned char MQTTVersion;
00097     MQTTString clientID;
00098     unsigned short keepAliveInterval;
00099     unsigned char cleansession;
00100     unsigned char willFlag;
00101     MQTTPacket_willOptions will;
00102     MQTTString username;
00103     MQTTString password;
00104 } MQTTPacket_connectData;
00105 
00106 typedef union
00107 {
00108     unsigned char all;  /**< all connack flags */
00109 #if defined(REVERSED)
00110     struct
00111     {
00112         unsigned int sessionpresent : 1;    /**< session present flag */
00113         unsigned int : 7;                 /**< unused */
00114     } bits;
00115 #else
00116     struct
00117     {
00118         unsigned int : 7;                   /**< unused */
00119         unsigned int sessionpresent : 1;    /**< session present flag */
00120     } bits;
00121 #endif
00122 } MQTTConnackFlags; /**< connack flags byte */
00123 
00124 #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
00125         MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
00126 
00127 DLLExport int MQTTSerialize_connect(unsigned char* buf, size_t buflen, MQTTPacket_connectData* options);
00128 DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, size_t len);
00129 
00130 DLLExport int MQTTSerialize_connack(unsigned char* buf, size_t buflen, unsigned char connack_rc, unsigned char sessionPresent);
00131 DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, size_t buflen);
00132 
00133 DLLExport int MQTTSerialize_disconnect(unsigned char* buf, size_t buflen);
00134 DLLExport int MQTTSerialize_pingreq(unsigned char* buf, size_t buflen);
00135 
00136 #endif /* MQTTCONNECT_H_ */