Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
MQTTConnect.h
00001 /******************************************************************************* 00002 * Copyright (c) 2014, 2015 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 * Ian Craggs - add connack return code definitions 00016 *******************************************************************************/ 00017 00018 #ifndef MQTTCONNECT_H_ 00019 #define MQTTCONNECT_H_ 00020 00021 enum connack_return_codes 00022 { 00023 MQTT_CONNECTION_ACCEPTED = 0, 00024 MQTT_UNNACCEPTABLE_PROTOCOL = 1, 00025 MQTT_CLIENTID_REJECTED = 2, 00026 MQTT_SERVER_UNAVAILABLE = 3, 00027 MQTT_BAD_USERNAME_OR_PASSWORD = 4, 00028 MQTT_NOT_AUTHORIZED = 5, 00029 }; 00030 00031 00032 typedef union 00033 { 00034 unsigned char all; /**< all connect flags */ 00035 #if defined(REVERSED) 00036 struct 00037 { 00038 unsigned int username : 1; /**< 3.1 user name */ 00039 unsigned int password : 1; /**< 3.1 password */ 00040 unsigned int willRetain : 1; /**< will retain setting */ 00041 unsigned int willQoS : 2; /**< will QoS value */ 00042 unsigned int will : 1; /**< will flag */ 00043 unsigned int cleansession : 1; /**< clean session flag */ 00044 unsigned int : 1; /**< unused */ 00045 } bits; 00046 #else 00047 struct 00048 { 00049 unsigned int : 1; /**< unused */ 00050 unsigned int cleansession : 1; /**< cleansession flag */ 00051 unsigned int will : 1; /**< will flag */ 00052 unsigned int willQoS : 2; /**< will QoS value */ 00053 unsigned int willRetain : 1; /**< will retain setting */ 00054 unsigned int password : 1; /**< 3.1 password */ 00055 unsigned int username : 1; /**< 3.1 user name */ 00056 } bits; 00057 #endif 00058 } MQTTConnectFlags; /**< connect flags byte */ 00059 00060 00061 00062 /** 00063 * Defines the MQTT "Last Will and Testament" (LWT) settings for 00064 * the connect packet. 00065 */ 00066 typedef struct 00067 { 00068 /** The eyecatcher for this structure. must be MQTW. */ 00069 char struct_id[4]; 00070 /** The version number of this structure. Must be 0 */ 00071 int struct_version; 00072 /** The LWT topic to which the LWT message will be published. */ 00073 MQTTString topicName; 00074 /** The LWT payload. */ 00075 MQTTString message; 00076 /** 00077 * The retained flag for the LWT message (see MQTTAsync_message.retained). 00078 */ 00079 unsigned char retained; 00080 /** 00081 * The quality of service setting for the LWT message (see 00082 * MQTTAsync_message.qos and @ref qos). 00083 */ 00084 char qos; 00085 } MQTTPacket_willOptions; 00086 00087 00088 #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 } 00089 00090 00091 typedef struct 00092 { 00093 /** The eyecatcher for this structure. must be MQTC. */ 00094 char struct_id[4]; 00095 /** The version number of this structure. Must be 0 */ 00096 int struct_version; 00097 /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1 00098 */ 00099 unsigned char MQTTVersion; 00100 MQTTString clientID; 00101 unsigned short keepAliveInterval; 00102 unsigned char cleansession; 00103 unsigned char willFlag; 00104 MQTTPacket_willOptions will; 00105 MQTTString username; 00106 MQTTString password; 00107 } MQTTPacket_connectData; 00108 00109 typedef union 00110 { 00111 unsigned char all; /**< all connack flags */ 00112 #if defined(REVERSED) 00113 struct 00114 { 00115 unsigned int sessionpresent : 1; /**< session present flag */ 00116 unsigned int : y; /**< unused */ 00117 } bits; 00118 #else 00119 struct 00120 { 00121 unsigned int : 7; /**< unused */ 00122 unsigned int sessionpresent : 1; /**< session present flag */ 00123 } bits; 00124 #endif 00125 } MQTTConnackFlags; /**< connack flags byte */ 00126 00127 #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \ 00128 MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} } 00129 00130 int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options); 00131 int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len); 00132 00133 int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent); 00134 int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen); 00135 00136 int MQTTSerialize_disconnect(unsigned char* buf, int buflen); 00137 int MQTTSerialize_pingreq(unsigned char* buf, int buflen); 00138 00139 #endif /* MQTTCONNECT_H_ */
Generated on Tue Jul 12 2022 21:37:29 by
1.7.2