您好
原本的MQTT Client Example Code機制為,Broker斷線後,直接LOOP_FOREVER();結束,如下:
if(BROKER_DISCONNECTION == RecvQue.event){
lRetVal = sl_ExtLib_MqttClientCtxDelete(((connect_config*)(RecvQue.hndl))->clt_ctx);
...
...
if(iConnBroker < 1)
{
//
// device not connected to any broker
//
goto end;
}
end:
sl_ExtLib_MqttClientExit();
UART_PRINT("\n\r Exiting the Application\n\r"); <------ I want to go back and try connection again from here
LOOP_FOREVER();
}
如果想要做成無須重新開機,直接Reconnect的機制又會遇到卡在底層的問題,(底下紅色字體的部分)
在net_ops->open前面打印參數,和原先第一次使用的帶入參數是一樣的,看起來沒問題。
static i32 net_connect(struct client_ctx *cl_ctx)
{
struct client_desc *client = CLIENT(cl_ctx);
if(NEED_NET_CLOSE(cl_ctx))
return MQP_ERR_NOT_DEF;
if(NULL == net_ops)
return MQP_ERR_NET_OPS;
DBG_INFO("net_connect flag=%d ,%s,%d,%d\r\n",client->nwconn_opts | DEV_NETCONN_OPT_TCP,client->server_addr,client->port_number,client->nw_security); //打印參數
cl_ctx->net = net_ops->open(client->nwconn_opts | DEV_NETCONN_OPT_TCP,
client->server_addr,
client->port_number,
&client->nw_security);
return (-1 == cl_ctx->net)? MQP_ERR_REMLSTN : 0;
}
請教一下,要如何達到Broker斷線,無須重開機的重連機制呢?
謝謝