MQTT Client API#
MQTTc_ConfigureTaskStk()#
Description#
Configure the MQTT client task stack properties to use the parameters contained in the passed structure instead of the default parameters.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void HTTPc_ConfigureTaskStk (CPU_STK_SIZE stk_size_elements,
void *p_stk_base)Arguments#
stk_size_elements
Size of the stack, in CPU_STK elements.
p_stk_base
Pointer to base of the stack.
Returned Value#
None.
Notes / Warnings#
This function is optional. If it is called, it must be called before
MQTTc_Init(). If it is not called, default values will be used to initialize the module.
MQTTc_ConfigureMemSeg()#
Description#
Configure the memory segment that will be used to allocate internal data needed by MQTT client module instead of the default memory segment.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConfigureMemSeg (MEM_SEG *p_mem_seg)Arguments#
p_mem_seg
Pointer to the memory segment from which the internal data will be allocated. If DEF_NULL, the internal data will be allocated from the global Heap.
Returned Value#
None.
Notes / Warnings#
This function is optional. If it is called, it must be called before
MQTTc_Init(). If it is not called, default values will be used to initialize the module.
MQTTc_ConfigureQty()#
Description#
Overwrite the quantity configuration object for MQTT client.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConfigureQty (MQTTc_QTY_CFG *p_qty_cfg)Arguments#
p_qty_cfg
Pointer to structure containing the quantity parameters.
Returned Value#
None.
Notes / Warnings#
This function is optional. If it is called, it must be called before
MQTTc_Init(). If it is not called, default values will be used to initialize the module.
MQTTc_Init()#
Description#
Initializes the MQTT client module.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Init (const MQTTc_CFG *p_cfg,
const RTOS_TASK_CFG *p_task_cfg,
MEM_SEG *p_mem_seg,
RTOS_ERR *p_err)Arguments#
p_cfg
Pointer to MQTT Client Configuration Object.
p_task_cfg
Pointer to task configuration structure.
p_mem_seg
Memory segment from which internal data will be allocated. If DEF_NULL, it will be allocated from the global heap.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_SEG_OVFRTOS_ERR_OS_ILLEGAL_RUN_TIME
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_TaskPrioSet()#
Description#
Sets priority of the MQTT client task.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_TaskPrioSet (RTOS_TASK_PRIO prio,
RTOS_ERR *p_err)Arguments#
prio
New priority for the MQTT client task.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function.
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_TaskDlySet()#
Description#
Sets task delay.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_TaskDlySet (CPU_INT08U dly_ms,
RTOS_ERR *p_err)Arguments#
dly_ms
New delay in millisecond for the MQTT client task.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function.
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_InactivityTimeoutDfltSet()#
Description#
Sets default inactivity timeout in second of the MQTT client connection.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_InactivityTimeoutDfltSet (CPU_INT16U inactivity_timeout_s,
RTOS_ERR *p_err)Arguments#
inactivity_timeout_s
New default timeout in second to set on new MQTT connection.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function.
Returned Value#
None.
Notes / Warnings#
It is possible to set each connection with a different inactivity timeout by calling
MQTTc_ConnSetParam()before opening the connection.
MQTTc_ConnSetParam()#
Description#
Sets parameters related to the TCP and MQTT Client Connection.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConnSetParam (MQTTc_CONN *p_conn,
MQTTc_PARAM_TYPE type,
void *p_param,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the current MQTTc Connection.
type
Parameter type :
MQTTc_PARAM_TYPE_BROKER_IP_ADDRBroker's IP address.MQTTc_PARAM_TYPE_BROKER_NAMEBroker's name.MQTTc_PARAM_TYPE_BROKER_PORT_NBRBroker's port number.MQTTc_PARAM_TYPE_INACTIVITY_TIMEOUT_SInactivity timeout (in seconds).MQTTc_PARAM_TYPE_CLIENT_ID_STRClient ID string.MQTTc_PARAM_TYPE_USERNAME_STRClient username string.MQTTc_PARAM_TYPE_PASSWORD_STRClient password string.MQTTc_PARAM_TYPE_KEEP_ALIVE_TMR_SECKeep alive timer (in seconds).MQTTc_PARAM_TYPE_WILL_CFG_PTRConfigures a pointer, if any.MQTTc_PARAM_TYPE_CALLBACK_ON_COMPLGeneric callback on completionMQTTc_PARAM_TYPE_CALLBACK_ON_CONNECT_CMPLCallback on connection completion.MQTTc_PARAM_TYPE_CALLBACK_ON_PUBLISH_CMPLCallback on publish completion.MQTTc_PARAM_TYPE_CALLBACK_ON_SUBSCRIBE_CMPLCallback on subscribe completion.MQTTc_PARAM_TYPE_CALLBACK_ON_UNSUBSCRIBE_CMPLCallback on unsubscribe completion.MQTTc_PARAM_TYPE_CALLBACK_ON_PINGREQ_CMPLCallback on ping request completion.MQTTc_PARAM_TYPE_CALLBACK_ON_DISCONNECT_CMPLCallback on disconnectionMQTTc_PARAM_TYPE_CALLBACK_ON_PUBLISH_RXCallback once publish is received.MQTTc_PARAM_TYPE_CALLBACK_ARG_PTRPointer on an argument passed to callback.MQTTc_PARAM_TYPE_TIMEOUT_MS'Open' timeout (in milliseconds).MQTTc_PARAM_TYPE_PUBLISH_RX_MSG_PTRPointer on the message that is used to receive the publish.
p_param
Parameter's value.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_ConnClose()#
Description#
Requests to close a MQTT client Connection.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConnClose (MQTTc_CONN *p_conn,
MQTTc_FLAGS flags,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection to close.
flags
Configuration flags, reserved for future usage.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_NOT_AVAILRTOS_ERR_OS_ILLEGAL_RUN_TIMERTOS_ERR_POOL_EMPTYRTOS_ERR_BLK_ALLOC_CALLBACKRTOS_ERR_SEG_OVFRTOS_ERR_INVALID_HANDLERTOS_ERR_OS_OBJ_DELRTOS_ERR_WOULD_BLOCKRTOS_ERR_OS_SCHED_LOCKEDRTOS_ERR_ABORTRTOS_ERR_TIMEOUT
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_ConnClr()#
Description#
Clears an MQTT client Connection before its first usage.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConnClr (MQTTc_CONN *p_conn,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTTc Connection.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONE
Returned Value#
None.
Notes / Warnings#
This function MUST be called before the
MQTTc_CONNobject is used for the first time.
MQTTc_Connect()#
Description#
Sends a 'Connect' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Connect (MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection to use.
p_msg
Pointer to the MQTT client Message object to use.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_NULL_PTRRTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_ConnOpen()#
Description#
Opens a new MQTT Client connection.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_ConnOpen (MQTTc_CONN *p_conn,
MQTTc_FLAGS flags,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to open.
flags
Configuration flags, reserved for future usage.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_INVALID_TYPERTOS_ERR_BLK_ALLOC_CALLBACKRTOS_ERR_SEG_OVFRTOS_ERR_NOT_SUPPORTEDRTOS_ERR_OS_SCHED_LOCKEDRTOS_ERR_NOT_AVAILRTOS_ERR_FAILRTOS_ERR_NET_INVALID_ADDR_SRCRTOS_ERR_WOULD_OVFRTOS_ERR_NET_IF_LINK_DOWNRTOS_ERR_INVALID_HANDLERTOS_ERR_WOULD_BLOCKRTOS_ERR_INVALID_STATERTOS_ERR_ABORTRTOS_ERR_TIMEOUTRTOS_ERR_NET_OP_IN_PROGRESSRTOS_ERR_TXRTOS_ERR_ALREADY_EXISTSRTOS_ERR_NOT_FOUNDRTOS_ERR_NET_INVALID_CONNRTOS_ERR_RXRTOS_ERR_NOT_READYRTOS_ERR_POOL_EMPTYRTOS_ERR_OS_OBJ_DELRTOS_ERR_NET_ADDR_UNRESOLVEDRTOS_ERR_NET_NEXT_HOPRTOS_ERR_NET_CONN_CLOSED_FAULT
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_Disconnect()#
Description#
Sends a 'Disconnect' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Disconnect (MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_MsgClr()#
Description#
Clears the Message object members.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_MsgClr (MQTTc_MSG *p_msg,
RTOS_ERR *p_err)Arguments#
p_msg
Pointer to the message object to clear.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_MsgSetParam()#
Description#
Sets the parameter related to a given MQTT Message.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_MsgSetParam (MQTTc_MSG *p_msg,
MQTTc_PARAM_TYPE type,
void *p_param,
RTOS_ERR *p_err)Arguments#
p_msg
Pointer to a message object.
type
Parameter type :
MQTTc_PARAM_TYPE_MSG_BUF_PTRMsg's buf ptr.MQTTc_PARAM_TYPE_MSG_BUF_LENMsg's buf len.
p_param
Parameter's value.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_PingReq()#
Description#
Sends a 'PingReq' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_PingReq (MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_Publish()#
Description#
Sends a 'Publish' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Publish ( MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
const CPU_CHAR *topic_str,
CPU_INT08U qos_lvl,
CPU_BOOLEAN retain_flag,
const CPU_INT08U *p_payload,
CPU_INT32U payload_len,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
topic_str
String containing the topic on which to publish. Must stay valid until the message has been completely sent.
qos_lvl
Level of QoS at which to publish.
retain_flag
Flag that indicates if the retain flag in the PUBLISH header needs to be set.
p_payload
Pointer to the payload to publish. Must stay valid until the message has been completely sent.
payload_len
Length, in bytes, of the payload.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_Subscribe()#
Description#
Sends a 'Subscribe' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Subscribe ( MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
const CPU_CHAR *topic_str,
CPU_INT08U req_qos,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
topic_str
String containing the topic at which to subscribe. Must stay valid until the message has been completely sent.
req_qos
Requested level of QoS for this subscription.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_SubscribeMult()#
Description#
Sends a 'Subscribe' message containing multiple topics to MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_SubscribeMult ( MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
const CPU_CHAR **topic_str_tbl,
CPU_INT08U *req_qos_tbl,
CPU_INT08U topic_nbr,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
topic_str_tbl
Table containing string of all the topic(s) at which to subscribe. Must all stay valid until the message has been completely sent.
req_qos_tbl
Table of the requested level of QoS for each subscription.
topic_nbr
Number of topics and QoS' contained in tables.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_Unsubscribe()#
Description#
Sends an 'Unsubscribe' message to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_Unsubscribe ( MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
const CPU_CHAR *topic_str,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
topic_str
String containing the topic at which to unsubscribe. Must stay valid until the message has been completely sent.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.
MQTTc_UnsubscribeMult()#
Description#
Sends an 'Unsubscribe' message for multiple topics to the MQTT server.
Files#
mqtt_client.h/mqtt_client.c
Prototype#
void MQTTc_UnsubscribeMult ( MQTTc_CONN *p_conn,
MQTTc_MSG *p_msg,
const CPU_CHAR **topic_str_tbl,
CPU_INT08U topic_nbr,
RTOS_ERR *p_err)Arguments#
p_conn
Pointer to the MQTT client Connection object to use.
p_msg
Pointer to the MQTT client Message object to use.
topic_str_tbl
Table containing string of all the topic(s) at which to unsubscribe. Must stay valid until the message has been completely sent.
topic_nbr
Number of topic contained in tables.
p_err
Pointer to the variable that will receive one of the following error code(s) from this function :
RTOS_ERR_NONERTOS_ERR_WOULD_OVFRTOS_ERR_INVALID_HANDLE
Returned Value#
None.
Notes / Warnings#
None.