Commit 6d50e9e8 authored by 957dd's avatar 957dd

优化了mqtt的问题,使用了异步检查重连机制,并且添加了重连10次将不会重连

parent 05e5f38d
......@@ -116,12 +116,20 @@ void *thread_open_browser(void *arg) {
void *thread_mqtt_reconnect(void *arg) {
while(1){
if(mqtt_init() == 0){
my_zlog_warn("mqtt success");
static int reconnect_count=0;
static int remqtt_index;
remqtt_index=mqtt_init();
if(remqtt_index == 0){
my_zlog_warn("mqtt success",remqtt_index);
break;
}else {
my_zlog_warn("wait... mqtt reconect");
my_zlog_warn("wait... mqtt reconect,error:%d",remqtt_index);
delay_ms(300);
reconnect_count++;
if(reconnect_count>MAX_RECONNECT_ATTEMPTS){
send_fail_mqtt_conect();
break;
}
continue;
}
}
......
No preview for this file type
This diff is collapsed.
......@@ -8,11 +8,15 @@
#define MAX_SERVERS 10
#define MAX_RECONNECT_ATTEMPTS 10
typedef struct {
struct mosquitto *mosq;
char host[128];
int port;
char client_id[64];
int reconnect_attempts; // 新增:重连尝试次数
bool permanently_failed; // 新增:标记是否永久失败
} mqttclient;
extern mqttclient g_clients_t[MAX_SERVERS];
......@@ -34,4 +38,7 @@ int mqtt_cycle();//循环
//mqtt清理
void mqtt_clean();
//莫一个服务器连接失败发送
void send_fail_mqtt_conect();
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment