mikroSDK Reference Manual
mqtt_common.h
Go to the documentation of this file.
1
31#ifndef _MQTT_COMMON_H
32#define _MQTT_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36
37//MQTT port number
38#define MQTT_PORT 1883
39//MQTT over TLS port number
40#define MQTT_TLS_PORT 8883
41
42//MQTT 3.1 protocol name
43#define MQTT_PROTOCOL_NAME_3_1 "MQIsdp"
44//MQTT 3.1.1 protocol name
45#define MQTT_PROTOCOL_NAME_3_1_1 "MQTT"
46
47//Minimum size of MQTT header
48#define MQTT_MIN_HEADER_SIZE 2
49//Maximum size of MQTT header
50#define MQTT_MAX_HEADER_SIZE 5
51
52//C++ guard
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57
67
68
73typedef enum
74{
75 MQTT_TRANSPORT_PROTOCOL_TCP = 1,
80
81
92
93
116
117
122typedef enum
123{
124 MQTT_CONNECT_FLAG_CLEAN_SESSION = 0x02,
125 MQTT_CONNECT_FLAG_WILL = 0x04,
126 MQTT_CONNECT_FLAG_WILL_QOS_0 = 0x00,
127 MQTT_CONNECT_FLAG_WILL_QOS_1 = 0x08,
128 MQTT_CONNECT_FLAG_WILL_QOS_2 = 0x10,
129 MQTT_CONNECT_FLAG_WILL_RETAIN = 0x20,
130 MQTT_CONNECT_FLAG_PASSWORD = 0x40,
131 MQTT_CONNECT_FLAG_USERNAME = 0x80
133
134
139typedef enum
140{
141 MQTT_CONNECT_ACK_FLAG_SESSION_PRESENT = 0x01
143
144
149typedef enum
150{
151 MQTT_CONNECT_RET_CODE_ACCEPTED = 0,
152 MQTT_CONNECT_RET_CODE_UNACCEPTABLE_VERSION = 1,
153 MQTT_CONNECT_RET_CODE_ID_REJECTED = 2,
154 MQTT_CONNECT_RET_CODE_SERVER_UNAVAILABLE = 3,
155 MQTT_CONNECT_RET_CODE_BAD_USER_NAME = 4,
156 MQTT_CONNECT_RET_CODE_NOT_AUTHORIZED = 5
158
159
160//CodeWarrior or Win32 compiler?
161#if defined(__CWCC__) || defined(_WIN32)
162 #pragma pack(push, 1)
163#endif
164
165
171{
172#if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
173 uint8_t type : 4; //0
174 uint8_t dup : 1;
175 uint8_t qos : 2;
176 uint8_t retain : 1;
177#else
178 uint8_t retain : 1; //0
179 uint8_t qos : 2;
180 uint8_t dup : 1;
181 uint8_t type : 4;
182#endif
183 uint8_t length[]; //1
184} MqttPacketHeader;
185
186
191typedef __packed_struct
192{
193 uint16_t length; //0-1
194 uint8_t data[]; //2
195} MqttString;
196
197
198//CodeWarrior or Win32 compiler?
199#if defined(__CWCC__) || defined(_WIN32)
200 #pragma pack(pop)
201#endif
202
203//C++ guard
204#ifdef __cplusplus
205}
206#endif
207
208#endif
MqttConnectFlags
Connect flags.
Definition mqtt_common.h:123
MqttConnectAckFlags
Connect Acknowledge flags.
Definition mqtt_common.h:140
MqttQosLevel
Quality of service level.
Definition mqtt_common.h:87
@ MQTT_QOS_LEVEL_2
Exactly once delivery.
Definition mqtt_common.h:90
@ MQTT_QOS_LEVEL_1
At least once delivery.
Definition mqtt_common.h:89
@ MQTT_QOS_LEVEL_0
At most once delivery.
Definition mqtt_common.h:88
MqttTransportProtocol
Transport protocol.
Definition mqtt_common.h:74
@ MQTT_TRANSPORT_PROTOCOL_WSS
WebSocket protocol.
Definition mqtt_common.h:78
@ MQTT_TRANSPORT_PROTOCOL_TLS
TCP protocol.
Definition mqtt_common.h:76
@ MQTT_TRANSPORT_PROTOCOL_WS
TLS protocol.
Definition mqtt_common.h:77
typedef __packed_struct
Fixed header.
Definition mqtt_common.h:171
MqttVersion
MQTT protocol level.
Definition mqtt_common.h:63
@ MQTT_VERSION_3_1
MQTT version 3.1.
Definition mqtt_common.h:64
@ MQTT_VERSION_3_1_1
MQTT version 3.1.1.
Definition mqtt_common.h:65
MqttConnectRetCode
Connect return codes.
Definition mqtt_common.h:150
MqttPacketType
MQTT control packet type.
Definition mqtt_common.h:99
@ MQTT_PACKET_TYPE_DISCONNECT
Client is disconnecting.
Definition mqtt_common.h:114
@ MQTT_PACKET_TYPE_SUBACK
Subscribe acknowledgment.
Definition mqtt_common.h:109
@ MQTT_PACKET_TYPE_PUBACK
Publish acknowledgment.
Definition mqtt_common.h:104
@ MQTT_PACKET_TYPE_SUBSCRIBE
Client subscribe request.
Definition mqtt_common.h:108
@ MQTT_PACKET_TYPE_UNSUBSCRIBE
Unsubscribe request.
Definition mqtt_common.h:110
@ MQTT_PACKET_TYPE_CONNACK
Connect acknowledgment.
Definition mqtt_common.h:102
@ MQTT_PACKET_TYPE_PINGRESP
Ping response.
Definition mqtt_common.h:113
@ MQTT_PACKET_TYPE_PUBCOMP
Publish complete (assured delivery part 3)
Definition mqtt_common.h:107
@ MQTT_PACKET_TYPE_INVALID
Invalid packet.
Definition mqtt_common.h:100
@ MQTT_PACKET_TYPE_PUBREC
Publish received (assured delivery part 1)
Definition mqtt_common.h:105
@ MQTT_PACKET_TYPE_PINGREQ
Ping request.
Definition mqtt_common.h:112
@ MQTT_PACKET_TYPE_CONNECT
Client request to connect to server.
Definition mqtt_common.h:101
@ MQTT_PACKET_TYPE_PUBLISH
Publish message.
Definition mqtt_common.h:103
@ MQTT_PACKET_TYPE_UNSUBACK
Unsubscribe acknowledgment.
Definition mqtt_common.h:111
@ MQTT_PACKET_TYPE_PUBREL
Publish release (assured delivery part 2)
Definition mqtt_common.h:106
TCP/IP stack core.