MQTT client library
Macros

General Description

MQTT library preprocessor directives such as results and error codes.

Cypress middleware APIs return results of type cy_rslt_t and consist of three parts:

Result Format
           Module base         Type    Library-specific error code
   +-------------------------+------+------------------------------+
   |          0x0200         | 0x2  |           Error Code         |
   +-------------------------+------+------------------------------+
             14 bits          2 bits            16 bits

See the macro section of this document for library-specific error codes.

The data structure cy_rslt_t is part of cy_result.h. In Mbed OS, the PSoC 6 MCU target platform is located in <mbed-os/targets/TARGET_Cypress/TARGET_PSOC6/psoc6csp/core_lib/include>. In ModusToolbox environment, PSoC 6 MCU target platform is located in <core_lib/include>.

Module base: This base is derived from CY_RSLT_MODULE_MIDDLEWARE_BASE (defined in cy_result.h) and is an offset of CY_RSLT_MODULE_MIDDLEWARE_BASE. Details of the offset and the middleware base are defined in cy_result_mw.h, which is part of Github connectivity-utilities.

Type: This type is defined in cy_result.h and can be one of CY_RSLT_TYPE_FATAL, CY_RSLT_TYPE_ERROR, CY_RSLT_TYPE_WARNING, or CY_RSLT_TYPE_INFO. MQTT library error codes are of type CY_RSLT_TYPE_ERROR which is 0x2.

Library-specific error codes: These error codes are library-specific and defined in the macro section.

Helper macros used for creating library-specific results are provided as part of cy_result.h.

Note
The functions defined in this library can return errors other than the error codes listed in this section. Please decode the error using the information provided above. Based on the module base value, refer the header file of corresponding module to identify the error.

Macros

#define CY_RSLT_MQTT_ERR_BASE   CY_RSLT_CREATE( CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_AWS_BASE, 0 )
 MQTT error code base.
 
#define CY_RSLT_MODULE_MQTT_ERROR   ( CY_RSLT_MQTT_ERR_BASE + 1 )
 Generic MQTT API error.
 
#define CY_RSLT_MODULE_MQTT_BADARG   ( CY_RSLT_MQTT_ERR_BASE + 2 )
 Invalid argument.
 
#define CY_RSLT_MODULE_MQTT_NOMEM   ( CY_RSLT_MQTT_ERR_BASE + 3 )
 Out of memory.
 
#define CY_RSLT_MODULE_MQTT_INIT_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 4 )
 MQTT library Init failure.
 
#define CY_RSLT_MODULE_MQTT_DEINIT_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 5 )
 MQTT library Deinit failure.
 
#define CY_RSLT_MODULE_MQTT_CREATE_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 6 )
 MQTT library Create failure.
 
#define CY_RSLT_MODULE_MQTT_DELETE_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 7 )
 MQTT library Delete failure.
 
#define CY_RSLT_MODULE_MQTT_INVALID_HANDLE   ( CY_RSLT_MQTT_ERR_BASE + 8 )
 Invalid MQTT handle.
 
#define CY_RSLT_MODULE_MQTT_CONNECT_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 9 )
 MQTT library Connect failure.
 
#define CY_RSLT_MODULE_MQTT_DISCONNECT_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 10 )
 MQTT library Disconnect failure.
 
#define CY_RSLT_MODULE_MQTT_PUBLISH_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 11 )
 MQTT library Publish failure.
 
#define CY_RSLT_MODULE_MQTT_SUBSCRIBE_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 12 )
 MQTT library Subscribe failure.
 
#define CY_RSLT_MODULE_MQTT_UNSUBSCRIBE_FAIL   ( CY_RSLT_MQTT_ERR_BASE + 13 )
 MQTT library Unsubscribe failure.
 
#define CY_RSLT_MODULE_MQTT_NOT_CONNECTED   ( CY_RSLT_MQTT_ERR_BASE + 14 )
 MQTT client not connected.
 
#define CY_RSLT_MODULE_MQTT_CLOSED   ( CY_RSLT_MQTT_ERR_BASE + 15 )
 MQTT client connection closed.
 
#define CY_RSLT_MODULE_MQTT_ALREADY_CONNECTED   ( CY_RSLT_MQTT_ERR_BASE + 16 )
 MQTT client already connected.
 
#define CY_RSLT_MODULE_MQTT_PROTOCOL_NOT_SUPPORTED   ( CY_RSLT_MQTT_ERR_BASE + 17 )
 Protocol not supported.
 
#define CY_RSLT_MODULE_MQTT_INVALID_CREDENTIALS   ( CY_RSLT_MQTT_ERR_BASE + 18 )
 Invalid credentials.
 
#define CY_RSLT_MODULE_MQTT_HANDSHAKE_FAILED   ( CY_RSLT_MQTT_ERR_BASE + 19 )
 TLS handshake failed.
 
#define CY_RSLT_MODULE_MQTT_HANDLE_NOT_FOUND   ( CY_RSLT_MQTT_ERR_BASE + 20 )
 MQTT library handle not found.
 
#define CY_RSLT_MODULE_MQTT_VCM_ERROR   ( CY_RSLT_MQTT_ERR_BASE + 21 )
 MQTT virtual API failure due to VCM error.
 
#define CY_RSLT_MODULE_MQTT_NOT_INITIALIZED   ( CY_RSLT_MQTT_ERR_BASE + 22 )
 MQTT library not initialized.
 
#define CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE   CY_MQTT_EVENT_TYPE_SUBSCRIPTION_MESSAGE_RECEIVE
 MQTT event type for subscribed message receive event. More...
 
#define CY_MQTT_MIN_NETWORK_BUFFER_SIZE   ( 256U )
 Minimum network buffer size in bytes, for sending and receiving an MQTT packet. More...
 
#define CY_MQTT_ACK_RECEIVE_TIMEOUT_MS   ( 3000U )
 Maximum wait time in milliseconds to receive acknowledgment packet from the MQTT broker for QoS1/QoS2 Publish/Subscribe message. More...
 
#define CY_MQTT_MESSAGE_SEND_TIMEOUT_MS   ( 3000U )
 MQTT message send timeout in milliseconds. More...
 
#define CY_MQTT_MESSAGE_RECEIVE_TIMEOUT_MS   ( 500U )
 MQTT message receive timeout for the subscribed topic, represented in milliseconds. More...
 
#define CY_MQTT_MAX_RETRY_VALUE   ( 3U )
 Maximum number of retry for MQTT publish/subscribe/unsubcribe message send. More...
 
#define CY_MQTT_MAX_HANDLE   ( 2U )
 Maximum number of MQTT instances supported.
 
#define CY_MQTT_MAX_OUTGOING_PUBLISHES   ( 1U )
 Configure value of maximum number of outgoing publishes maintained in MQTT library until an ack is received from the broker.
 
#define CY_MQTT_MAX_OUTGOING_SUBSCRIBES   ( 5U )
 Configure value of maximum number of outgoing subscription topics maintained in MQTT library until an ack is received from the broker.
 
#define CY_MQTT_DESCP_MAX_LEN   ( 20 )
 Maximum length of descriptor supported.
 
#define CY_MQTT_EVENT_THREAD_STACK_SIZE   ( 1024 * 3 )
 Stack size for MQTT Event processing thread.
 

Macro Definition Documentation

◆ CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE

#define CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE   CY_MQTT_EVENT_TYPE_SUBSCRIPTION_MESSAGE_RECEIVE

MQTT event type for subscribed message receive event.

Macro is added for library backward compatibility.

Note
This macro is defined only for backward compatibility. Application should not modify this macro.

◆ CY_MQTT_MIN_NETWORK_BUFFER_SIZE

#define CY_MQTT_MIN_NETWORK_BUFFER_SIZE   ( 256U )

Minimum network buffer size in bytes, for sending and receiving an MQTT packet.

Note
This is the default value configured in the library. This value can be modified to suit the application use case requirements.

◆ CY_MQTT_ACK_RECEIVE_TIMEOUT_MS

#define CY_MQTT_ACK_RECEIVE_TIMEOUT_MS   ( 3000U )

Maximum wait time in milliseconds to receive acknowledgment packet from the MQTT broker for QoS1/QoS2 Publish/Subscribe message.

MQTT library function returns to the caller immediately, if the MQTT acknowledgment message is received before the timeout/wait time. Else, the function returns the failure status at the end of wait time.

Note
This is the default value configured in the library. This value can be modified depending on the network condition.

◆ CY_MQTT_MESSAGE_SEND_TIMEOUT_MS

#define CY_MQTT_MESSAGE_SEND_TIMEOUT_MS   ( 3000U )

MQTT message send timeout in milliseconds.

MQTT library function returns to the caller immediately, if the MQTT message is sent before the timeout/wait time. Else, the function returns the failure status at the end of wait time.

Note
This is the default value configured in the library. This value can be modified depending on the network condition.

◆ CY_MQTT_MESSAGE_RECEIVE_TIMEOUT_MS

#define CY_MQTT_MESSAGE_RECEIVE_TIMEOUT_MS   ( 500U )

MQTT message receive timeout for the subscribed topic, represented in milliseconds.

MQTT network receive function waits for this timeout value, in case if partial data is received from the network socket. If the complete data is received before this timeout value, the network receive functions returns to the caller immediately after reading the requested data from the socket.

Note
This is the default value configured in the library. This value can be modified depending on the network condition.

◆ CY_MQTT_MAX_RETRY_VALUE

#define CY_MQTT_MAX_RETRY_VALUE   ( 3U )

Maximum number of retry for MQTT publish/subscribe/unsubcribe message send.

Note
This is the default value configured in the library. This value can be modified by defining macro in application makefile.