CPU_BOOLEAN App_MQTTc_ConnPrepare (MQTTc_CONN *p_conn)
{
MQTTc_ERR err;
/* ---------------- INIT NEW CONNECTION --------------- */
MQTTc_ConnClr(p_conn, &err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
/* Set conn parameters. */
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_BROKER_NAME,
(void *)APP_MQTTc_BROKER_NAME,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CLIENT_ID_STR,
(void *)APP_MQTTc_CLIENT_ID_NAME,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_USERNAME_STR,
(void *)APP_MQTTc_USERNAME,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_PASSWORD_STR,
(void *)APP_MQTTc_PASSWORD,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_KEEP_ALIVE_TMR_SEC,
(void *)1000u,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_COMPL,
(void *)AppMQTTc_OnCmplCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_CONNECT_CMPL,
(void *)AppMQTTc_OnConnectCmplCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_PUBLISH_CMPL,
(void *)AppMQTTc_OnPublishCmplCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_SUBSCRIBE_CMPL,
(void *)AppMQTTc_OnSubscribeCmplCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_ERR_CALLBACK,
(void *)AppMQTTc_OnErrCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_PUBLISH_RX_MSG_PTR,
(void *)&AppMQTTc_MsgPublishRx,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_CALLBACK_ON_PUBLISH_RX,
(void *)AppMQTTc_OnPublishRxCallbackFnct,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
MQTTc_ConnSetParam( &AppMQTTc_Conn,
MQTTc_PARAM_TYPE_TIMEOUT_MS,
(void *)30000u,
&err);
if (err != MQTTc_ERR_NONE) {
return (DEF_FAIL);
}
return (DEF_OK);
} |