diff --git a/components/esp_wifi/src/smartconfig_ack.c b/components/esp_wifi/src/smartconfig_ack.c index db9276d8d..7dbdb993d 100644 --- a/components/esp_wifi/src/smartconfig_ack.c +++ b/components/esp_wifi/src/smartconfig_ack.c @@ -33,6 +33,8 @@ #define SC_ACK_TOUCH_SERVER_PORT 18266 /*!< ESP touch UDP port of server on cellphone */ #define SC_ACK_AIRKISS_SERVER_PORT 10000 /*!< Airkiss UDP port of server on cellphone */ +#define SC_ACK_AIRKISS_DEVICE_PORT 10001 /*!< Airkiss UDP port of server on device */ +#define SC_ACK_AIRKISS_TIMEOUT 1500 /*!< Airkiss read data timout millisecond */ #define SC_ACK_TOUCH_LEN 11 /*!< Length of ESP touch ACK context */ #define SC_ACK_AIRKISS_LEN 7 /*!< Length of Airkiss ACK context */ @@ -110,6 +112,33 @@ static void sc_ack_send_task(void *pvParameters) setsockopt(send_sock, SOL_SOCKET, SO_BROADCAST | SO_REUSEADDR, &optval, sizeof(int)); + if (ack->type == SC_TYPE_AIRKISS) { + char data = 0; + struct sockaddr_in local_addr, from; + socklen_t sockadd_len = sizeof(struct sockaddr); + struct timeval timeout = { + SC_ACK_AIRKISS_TIMEOUT / 1000, + SC_ACK_AIRKISS_TIMEOUT % 1000 * 1000 + }; + + bzero(&local_addr, sizeof(struct sockaddr_in)); + bzero(&from, sizeof(struct sockaddr_in)); + local_addr.sin_family = AF_INET; + local_addr.sin_addr.s_addr = INADDR_ANY; + local_addr.sin_port = htons(SC_ACK_AIRKISS_DEVICE_PORT); + + bind(send_sock, (struct sockaddr *)&local_addr, sockadd_len); + setsockopt(send_sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); + + recvfrom(send_sock, &data, 1, 0, (struct sockaddr *)&from, &sockadd_len); + if (from.sin_addr.s_addr != INADDR_ANY) { + memcpy(remote_ip, &from.sin_addr, 4); + server_addr.sin_addr.s_addr = from.sin_addr.s_addr; + } else { + goto _end; + } + } + while (s_sc_ack_send) { /* Send smartconfig ACK every 100ms. */ vTaskDelay(100 / portTICK_RATE_MS);