MQTT API Reference
MQTT 3.1.1 client library
iot_mqtt.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of
5  * this software and associated documentation files (the "Software"), to deal in
6  * the Software without restriction, including without limitation the rights to
7  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8  * the Software, and to permit persons to whom the Software is furnished to do so,
9  * subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 
27 #ifndef IOT_MQTT_H_
28 #define IOT_MQTT_H_
29 
30 /* The config header is always included first. */
31 #include "iot_config.h"
32 
33 /* MQTT types include. */
34 #include "types/iot_mqtt_types.h"
35 
36 /*------------------------- MQTT library functions --------------------------*/
37 
91 /* @[declare_mqtt_init] */
93 /* @[declare_mqtt_init] */
94 
108 /* @[declare_mqtt_cleanup] */
109 void IotMqtt_Cleanup( void );
110 /* @[declare_mqtt_cleanup] */
111 
123 /* @[declare_mqtt_receivecallback] */
124 void IotMqtt_ReceiveCallback( void * pNetworkConnection,
125  void * pReceiveContext );
126 /* @[declare_mqtt_receivecallback] */
127 
251 /* @[declare_mqtt_connect] */
253  const IotMqttConnectInfo_t * pConnectInfo,
254  uint32_t timeoutMs,
255  IotMqttConnection_t * const pMqttConnection );
256 /* @[declare_mqtt_connect] */
257 
288 /* @[declare_mqtt_disconnect] */
289 void IotMqtt_Disconnect( IotMqttConnection_t mqttConnection,
290  uint32_t flags );
291 /* @[declare_mqtt_disconnect] */
292 
422 /* @[declare_mqtt_subscribeasync] */
424  const IotMqttSubscription_t * pSubscriptionList,
425  size_t subscriptionCount,
426  uint32_t flags,
427  const IotMqttCallbackInfo_t * pCallbackInfo,
428  IotMqttOperation_t * const pSubscribeOperation );
429 /* @[declare_mqtt_subscribeasync] */
430 
463 /* @[declare_mqtt_subscribesync] */
465  const IotMqttSubscription_t * pSubscriptionList,
466  size_t subscriptionCount,
467  uint32_t flags,
468  uint32_t timeoutMs );
469 /* @[declare_mqtt_subscribesync] */
470 
509 /* @[declare_mqtt_unsubscribeasync] */
511  const IotMqttSubscription_t * pSubscriptionList,
512  size_t subscriptionCount,
513  uint32_t flags,
514  const IotMqttCallbackInfo_t * pCallbackInfo,
515  IotMqttOperation_t * const pUnsubscribeOperation );
516 /* @[declare_mqtt_unsubscribeasync] */
517 
546 /* @[declare_mqtt_unsubscribesync] */
548  const IotMqttSubscription_t * pSubscriptionList,
549  size_t subscriptionCount,
550  uint32_t flags,
551  uint32_t timeoutMs );
552 /* @[declare_mqtt_unsubscribesync] */
553 
642 /* @[declare_mqtt_publishasync] */
644  const IotMqttPublishInfo_t * pPublishInfo,
645  uint32_t flags,
646  const IotMqttCallbackInfo_t * pCallbackInfo,
647  IotMqttOperation_t * const pPublishOperation );
648 /* @[declare_mqtt_publishasync] */
649 
681 /* @[declare_mqtt_publishsync] */
683  const IotMqttPublishInfo_t * pPublishInfo,
684  uint32_t flags,
685  uint32_t timeoutMs );
686 /* @[declare_mqtt_publishsync] */
687 
737 /* @[declare_mqtt_wait] */
739  uint32_t timeoutMs );
740 /* @[declare_mqtt_wait] */
741 
742 /*-------------------------- MQTT helper functions --------------------------*/
743 
761 /* @[declare_mqtt_strerror] */
762 const char * IotMqtt_strerror( IotMqttError_t status );
763 /* @[declare_mqtt_strerror] */
764 
780 /* @[declare_mqtt_operationtype] */
781 const char * IotMqtt_OperationType( IotMqttOperationType_t operation );
782 /* @[declare_mqtt_operationtype] */
783 
819 /* @[declare_mqtt_issubscribed] */
820 bool IotMqtt_IsSubscribed( IotMqttConnection_t mqttConnection,
821  const char * pTopicFilter,
822  uint16_t topicFilterLength,
823  IotMqttSubscription_t * const pCurrentSubscription );
824 /* @[declare_mqtt_issubscribed] */
825 
832 #define IotMqtt_Subscribe IotMqtt_SubscribeAsync
833 #define IotMqtt_TimedSubscribe IotMqtt_SubscribeSync
834 #define IotMqtt_Unsubscribe IotMqtt_UnsubscribeAsync
835 #define IotMqtt_TimedUnsubscribe IotMqtt_UnsubscribeSync
836 #define IotMqtt_Publish IotMqtt_PublishAsync
837 #define IotMqtt_TimedPublish IotMqtt_PublishSync
838 
840 #endif /* ifndef IOT_MQTT_H_ */
IotMqtt_ReceiveCallback
void IotMqtt_ReceiveCallback(void *pNetworkConnection, void *pReceiveContext)
Network receive callback for the MQTT library.
Definition: iot_mqtt_network.c:927
IotMqtt_SubscribeSync
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:1501
IotMqtt_Cleanup
void IotMqtt_Cleanup(void)
One-time deinitialization function for the MQTT library.
Definition: iot_mqtt_api.c:951
IotMqtt_Disconnect
void IotMqtt_Disconnect(IotMqttConnection_t mqttConnection, uint32_t flags)
Closes an MQTT connection and frees resources.
Definition: iot_mqtt_api.c:1327
IotMqttError_t
IotMqttError_t
Return codes of MQTT functions.
Definition: iot_mqtt_types.h:103
IotMqttCallbackInfo_t
Information on a user-provided MQTT callback function.
Definition: iot_mqtt_types.h:516
IotMqtt_OperationType
const char * IotMqtt_OperationType(IotMqttOperationType_t operation)
Returns a string that describes an IotMqttOperationType_t.
Definition: iot_mqtt_api.c:2100
IotMqtt_PublishAsync
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 receive an asynchronous notification when the publish...
Definition: iot_mqtt_api.c:1595
IotMqttOperation_t
struct _mqttOperation * IotMqttOperation_t
Opaque handle that references an in-progress MQTT operation.
Definition: iot_mqtt_types.h:88
IotMqtt_Init
IotMqttError_t IotMqtt_Init(void)
One-time initialization function for the MQTT library.
Definition: iot_mqtt_api.c:907
IotMqtt_strerror
const char * IotMqtt_strerror(IotMqttError_t status)
Returns a string that describes an IotMqttError_t.
Definition: iot_mqtt_api.c:2036
IotMqtt_UnsubscribeAsync
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 receive an asynchronous notification when the ...
Definition: iot_mqtt_api.c:1539
IotMqttConnection_t
struct _mqttConnection * IotMqttConnection_t
Opaque handle of an MQTT connection.
Definition: iot_mqtt_types.h:66
IotMqttNetworkInfo_t
Infomation on the transport-layer network connection for the new MQTT connection.
Definition: iot_mqtt_types.h:930
IotMqtt_IsSubscribed
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:584
iot_mqtt_types.h
Types of the MQTT library.
IotMqttOperationType_t
IotMqttOperationType_t
Types of MQTT operations.
Definition: iot_mqtt_types.h:277
IotMqttSubscription_t
Information on an MQTT subscription.
Definition: iot_mqtt_types.h:550
IotMqtt_UnsubscribeSync
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:1557
IotMqtt_PublishSync
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:1866
IotMqtt_Wait
IotMqttError_t IotMqtt_Wait(IotMqttOperation_t operation, uint32_t timeoutMs)
Waits for an operation to complete.
Definition: iot_mqtt_api.c:1918
IotMqttPublishInfo_t
Information on a PUBLISH message.
Definition: iot_mqtt_types.h:397
IotMqtt_SubscribeAsync
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 receive an asynchronous notification when the subs...
Definition: iot_mqtt_api.c:1483
IotMqtt_Connect
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:975
IotMqttConnectInfo_t
Information on a new MQTT connection.
Definition: iot_mqtt_types.h:585