嵌入式技术论坛
直播中

郑成枝

7年用户 1273经验值
私信 关注
[问答]

mqtt线程卡死导致publish消息无反应是什么原因导致的?

硬件平台: STM32F407+LAN8740A
软件平台:4.0.3+pahomqtt1.1.0
复现方法:断开路由器外网网线
问题现象:mqtt线程卡死,导致publish消息无反应,ping百度正常,说明外网通信正常
调试发现publish线程卡死,mqtt0线程也卡死,不确定好卡在哪里
publish代码如下:
    while(1){
        Retry = 10;
        rt_memset(msg_ptr,0,sizeof(PubData_t));
        if (rt_mq_recv(&MQTTPubMQ, msg_ptr, sizeof(PubData_t),RT_WAItiNG_FOREVER) == RT_EOK){
            while(Retry--){
                easyblink(LED_Communication, 1, LED_SHORTDUTY>>1, LED_SHORTCYCLE>>1);
                msg_ptr->timestamp+=28800;
                LOG_D("%.*s", 25, ctime(&msg_ptr->timestamp));
                list_mem();
                itoa(msg_ptr->timestamp,Filename,10);
                rt_memcpy(Filename+strlen(Filename),".jsonx00",6);
                if(!MqttClient.isonline){
                    LOG_E("Wait MQTT Connect");
                }
                while(!MqttClient.isonline ){
                    rt_thread_delay(1000);
                }
                while(Socket_Busy== RT_TRUE){
                    rt_thread_delay(1000);
                }
                Socket_Busy = RT_TRUE ;
                if(paho_mqtt_publish(&MqttClient, msg_ptr->PUB_QOS, msg_ptr->Topic, msg_ptr->PayLoad)){
                    LOG_E("PUB %s Fail",msg_ptr->Topic,msg_ptr->PayLoad);
                }
                else{
                    LOG_I("PUB %s %s Success",msg_ptr->Topic,msg_ptr->PayLoad);
                    break;
                }
            }
        }
    }
}

回帖(1)

贾永世

2022-5-24 15:15:12

找到问题了,这里超时时间2000秒,在网络不通的时候会等待2000秒的超时
举报

更多回帖

发帖
×
20
完善资料,
赚取积分