smartconfig: fix the issue of sending failure and exit

This commit is contained in:
muhaidong 2023-03-03 19:15:52 +08:00
parent 60c57ade1d
commit d52d1fc443

View File

@ -92,6 +92,7 @@ static void sc_ack_send_task(void *pvParameters)
port_bit = 0;
}
remote_port = SC_ACK_TOUCH_V2_SERVER_PORT(port_bit);
memset(remote_ip, 0xFF, sizeof(remote_ip));
} else {
remote_port = SC_ACK_AIRKISS_SERVER_PORT;
}
@ -165,15 +166,24 @@ static void sc_ack_send_task(void *pvParameters)
memcpy(remote_ip, &from.sin_addr, 4);
server_addr.sin_addr.s_addr = from.sin_addr.s_addr;
} else {
goto _end;
server_addr.sin_addr.s_addr = INADDR_BROADCAST;
}
}
uint32_t ip_addr = server_addr.sin_addr.s_addr;
while (s_sc_ack_send) {
/* Send smartconfig ACK every 100ms. */
vTaskDelay(100 / portTICK_RATE_MS);
sendlen = sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size);
if (ip_addr != INADDR_BROADCAST) {
sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size);
server_addr.sin_addr.s_addr = INADDR_BROADCAST;
sendlen = sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size);
server_addr.sin_addr.s_addr = ip_addr;
} else {
sendlen = sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size);
}
if (sendlen <= 0) {
err = sc_ack_send_get_errno(send_sock);
ESP_LOGD(TAG, "send failed, errno %d", err);