AWS IoT Device SDK C: MQTT
MQTT 3.1.1 client library
Return to main page ↑
iot_mqtt.h
Go to the documentation of this file.
1 /*
2  * IoT MQTT V2.1.0
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef IOT_MQTT_H_
29 #define IOT_MQTT_H_
30 
31 /* The config header is always included first. */
32 #include "iot_config.h"
33 
34 /* MQTT types include. */
35 #include "types/iot_mqtt_types.h"
36 
37 /*------------------------- MQTT library functions --------------------------*/
38 
92 /* @[declare_mqtt_init] */
94 /* @[declare_mqtt_init] */
95 
109 /* @[declare_mqtt_cleanup] */
110 void IotMqtt_Cleanup( void );
111 /* @[declare_mqtt_cleanup] */
112 
124 /* @[declare_mqtt_receivecallback] */
125 void IotMqtt_ReceiveCallback( IotNetworkConnection_t pNetworkConnection,
126  void * pReceiveContext );
127 /* @[declare_mqtt_receivecallback] */
128 
280 /* @[declare_mqtt_connect] */
282  const IotMqttConnectInfo_t * pConnectInfo,
283  uint32_t timeoutMs,
284  IotMqttConnection_t * const pMqttConnection );
285 /* @[declare_mqtt_connect] */
286 
317 /* @[declare_mqtt_disconnect] */
318 void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
319  uint32_t flags );
320 /* @[declare_mqtt_disconnect] */
321 
451 /* @[declare_mqtt_subscribeasync] */
453  const IotMqttSubscription_t * pSubscriptionList,
454  size_t subscriptionCount,
455  uint32_t flags,
456  const IotMqttCallbackInfo_t * pCallbackInfo,
457  IotMqttOperation_t * const pSubscribeOperation );
458 /* @[declare_mqtt_subscribeasync] */
459 
492 /* @[declare_mqtt_subscribesync] */
494  const IotMqttSubscription_t * pSubscriptionList,
495  size_t subscriptionCount,
496  uint32_t flags,
497  uint32_t timeoutMs );
498 /* @[declare_mqtt_subscribesync] */
499 
538 /* @[declare_mqtt_unsubscribeasync] */
540  const IotMqttSubscription_t * pSubscriptionList,
541  size_t subscriptionCount,
542  uint32_t flags,
543  const IotMqttCallbackInfo_t * pCallbackInfo,
544  IotMqttOperation_t * const pUnsubscribeOperation );
545 /* @[declare_mqtt_unsubscribeasync] */
546 
574 /* @[declare_mqtt_unsubscribesync] */
576  const IotMqttSubscription_t * pSubscriptionList,
577  size_t subscriptionCount,
578  uint32_t flags,
579  uint32_t timeoutMs );
580 /* @[declare_mqtt_unsubscribesync] */
581 
670 /* @[declare_mqtt_publishasync] */
672  const IotMqttPublishInfo_t * pPublishInfo,
673  uint32_t flags,
674  const IotMqttCallbackInfo_t * pCallbackInfo,
675  IotMqttOperation_t * const pPublishOperation );
676 /* @[declare_mqtt_publishasync] */
677 
709 /* @[declare_mqtt_publishsync] */
711  const IotMqttPublishInfo_t * pPublishInfo,
712  uint32_t flags,
713  uint32_t timeoutMs );
714 /* @[declare_mqtt_publishsync] */
715 
766 /* @[declare_mqtt_wait] */
768  uint32_t timeoutMs );
769 /* @[declare_mqtt_wait] */
770 
771 /*-------------------------- MQTT helper functions --------------------------*/
772 
790 /* @[declare_mqtt_strerror] */
791 const char * IotMqtt_strerror( IotMqttError_t status );
792 /* @[declare_mqtt_strerror] */
793 
809 /* @[declare_mqtt_operationtype] */
810 const char * IotMqtt_OperationType( IotMqttOperationType_t operation );
811 /* @[declare_mqtt_operationtype] */
812 
847 /* @[declare_mqtt_issubscribed] */
848 bool IotMqtt_IsSubscribed( IotMqttConnection_t mqttConnection,
849  const char * pTopicFilter,
850  uint16_t topicFilterLength,
851  IotMqttSubscription_t * const pCurrentSubscription );
852 /* @[declare_mqtt_issubscribed] */
853 
860 #define IotMqtt_Subscribe IotMqtt_SubscribeAsync
861 #define IotMqtt_TimedSubscribe IotMqtt_SubscribeSync
862 #define IotMqtt_Unsubscribe IotMqtt_UnsubscribeAsync
863 #define IotMqtt_TimedUnsubscribe IotMqtt_UnsubscribeSync
864 #define IotMqtt_Publish IotMqtt_PublishAsync
865 #define IotMqtt_TimedPublish IotMqtt_PublishSync
866 
868 #endif /* ifndef IOT_MQTT_H_ */
IotMqttError_t IotMqtt_SubscribeAsync(IotMqttConnection_t mqttConnection, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, IotMqttOperation_t *const pSubscribeOperation)
Subscribes to the given array of topic filters and optionally receive an asynchronous notification wh...
Definition: iot_mqtt_api.c:1510
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:106
MQTT callback function and context.
Definition: iot_mqtt_types.h:518
IotMqttError_t IotMqtt_Connect(const IotMqttNetworkInfo_t *pNetworkInfo, const IotMqttConnectInfo_t *pConnectInfo, uint32_t timeoutMs, IotMqttConnection_t *const pMqttConnection)
Establish a new MQTT connection.
Definition: iot_mqtt_api.c:1229
IotMqttError_t IotMqtt_Wait(IotMqttOperation_t operation, uint32_t timeoutMs)
Waits for an operation to complete.
Definition: iot_mqtt_api.c:1810
MQTT library types.
IotMqttError_t IotMqtt_UnsubscribeAsync(IotMqttConnection_t mqttConnection, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, IotMqttOperation_t *const pUnsubscribeOperation)
Unsubscribes from the given array of topic filters and optionally receive an asynchronous notificatio...
Definition: iot_mqtt_api.c:1575
void IotMqtt_ReceiveCallback(IotNetworkConnection_t pNetworkConnection, void *pReceiveContext)
Network receive callback for the MQTT library.
Definition: iot_mqtt_network.c:828
_IotNetworkConnection_t IotNetworkConnection_t
bool IotMqtt_IsSubscribed(IotMqttConnection_t mqttConnection, const char *pTopicFilter, uint16_t topicFilterLength, IotMqttSubscription_t *const pCurrentSubscription)
Check if an MQTT connection has a subscription for a topic filter.
Definition: iot_mqtt_subscription.c:652
const char * IotMqtt_OperationType(IotMqttOperationType_t operation)
Returns a string that describes an IotMqttOperationType_t.
Definition: iot_mqtt_api.c:1938
void IotMqtt_Cleanup(void)
One-time deinitialization function for the MQTT library.
Definition: iot_mqtt_api.c:1203
IotMqttError_t IotMqtt_PublishAsync(IotMqttConnection_t mqttConnection, const IotMqttPublishInfo_t *pPublishInfo, uint32_t flags, const IotMqttCallbackInfo_t *pCallbackInfo, IotMqttOperation_t *const pPublishOperation)
Publishes a message to the given topic name and optionally receive an asynchronous notification when ...
Definition: iot_mqtt_api.c:1645
Information on a PUBLISH message.
Definition: iot_mqtt_types.h:395
struct _mqttConnection * IotMqttConnection_t
Opaque handle of an MQTT connection.
Definition: iot_mqtt_types.h:67
MQTT subscription.
Definition: iot_mqtt_types.h:553
MQTT connection details.
Definition: iot_mqtt_types.h:589
IotMqttError_t IotMqtt_PublishSync(IotMqttConnection_t mqttConnection, const IotMqttPublishInfo_t *pPublishInfo, uint32_t flags, uint32_t timeoutMs)
Publish a message to the given topic name with a timeout.
Definition: iot_mqtt_api.c:1762
IotMqttError_t IotMqtt_SubscribeSync(IotMqttConnection_t mqttConnection, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint32_t flags, uint32_t timeoutMs)
Subscribes to the given array of topic filters with a timeout.
Definition: iot_mqtt_api.c:1541
IotMqttError_t IotMqtt_UnsubscribeSync(IotMqttConnection_t mqttConnection, const IotMqttSubscription_t *pSubscriptionList, size_t subscriptionCount, uint32_t flags, uint32_t timeoutMs)
Unsubscribes from a given array of topic filters with a timeout.
Definition: iot_mqtt_api.c:1611
IotMqttError_t IotMqtt_Init(void)
One-time initialization function for the MQTT library.
Definition: iot_mqtt_api.c:1165
struct _mqttOperation * IotMqttOperation_t
Opaque handle that references an in-progress MQTT operation.
Definition: iot_mqtt_types.h:90
MQTT network connection details.
Definition: iot_mqtt_types.h:1013
IotMqttOperationType_t
Types of MQTT operations.
Definition: iot_mqtt_types.h:280
void IotMqtt_Disconnect(IotMqttConnection_t mqttConnection, uint32_t flags)
Closes an MQTT connection and frees resources.
Definition: iot_mqtt_api.c:1369
const char * IotMqtt_strerror(IotMqttError_t status)
Returns a string that describes an IotMqttError_t.
Definition: iot_mqtt_api.c:1874