diff --git a/components/smartconfig_ack/include/smartconfig_ack.h b/components/smartconfig_ack/include/smartconfig_ack.h index be49fd3bd1..39f7636ebd 100644 --- a/components/smartconfig_ack/include/smartconfig_ack.h +++ b/components/smartconfig_ack/include/smartconfig_ack.h @@ -24,6 +24,8 @@ extern "C" { #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 timeout millisecond */ #define SC_ACK_TOUCH_LEN 11 /*!< Length of ESP touch ACK context */ #define SC_ACK_AIRKISS_LEN 7 /*!< Length of Airkiss ACK context */ diff --git a/components/smartconfig_ack/smartconfig_ack.c b/components/smartconfig_ack/smartconfig_ack.c index 746535d804..91edc7b2ad 100644 --- a/components/smartconfig_ack/smartconfig_ack.c +++ b/components/smartconfig_ack/smartconfig_ack.c @@ -86,6 +86,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_ACK_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);