esp_wifi: add esptouch v2

Closes https://github.com/espressif/esp-idf/issues/1311
This commit is contained in:
zhangyanjiao
2020-08-18 10:34:29 +08:00
committed by liuzhifu
parent 317c882133
commit 1da9d9c356
6 changed files with 80 additions and 32 deletions

View File

@@ -34,12 +34,14 @@
#define SC_ACK_TASK_PRIORITY 2 /*!< Priority of sending smartconfig ACK task */
#define SC_ACK_TASK_STACK_SIZE 2048 /*!< Stack size of sending smartconfig ACK task */
#define SC_ACK_TOUCH_SERVER_PORT 18266 /*!< ESP touch UDP port of server on cellphone */
#define SC_ACK_TOUCH_DEVICE_PORT 7001 /*!< ESPTouch UDP port of server on device */
#define SC_ACK_TOUCH_SERVER_PORT 18266 /*!< ESPTouch UDP port of server on cellphone */
#define SC_ACK_TOUCH_V2_SERVER_PORT(i) (18266+i*10000) /*!< ESPTouch v2 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_TOUCH_LEN 11 /*!< Length of ESPTouch ACK context */
#define SC_ACK_AIRKISS_LEN 7 /*!< Length of Airkiss ACK context */
#define SC_ACK_MAX_COUNT 30 /*!< Maximum count of sending smartconfig ACK */
@@ -77,7 +79,6 @@ static void sc_ack_send_task(void *pvParameters)
esp_netif_ip_info_t local_ip;
uint8_t remote_ip[4];
memcpy(remote_ip, ack->ctx.ip, sizeof(remote_ip));
int remote_port = (ack->type == SC_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT;
struct sockaddr_in server_addr;
socklen_t sin_size = sizeof(server_addr);
int send_sock = -1;
@@ -88,6 +89,19 @@ static void sc_ack_send_task(void *pvParameters)
int err;
int ret;
int remote_port = 0;
if (ack->type == SC_TYPE_ESPTOUCH) {
remote_port = SC_ACK_TOUCH_SERVER_PORT;
} else if (ack->type == SC_TYPE_ESPTOUCH_V2) {
uint8_t port_bit = ack->ctx.token;
if(port_bit > 3) {
port_bit = 0;
}
remote_port = SC_ACK_TOUCH_V2_SERVER_PORT(port_bit);
} else {
remote_port = SC_ACK_AIRKISS_SERVER_PORT;
}
bzero(&server_addr, sizeof(struct sockaddr_in));
server_addr.sin_family = AF_INET;
memcpy(&server_addr.sin_addr.s_addr, remote_ip, sizeof(remote_ip));
@@ -101,7 +115,7 @@ static void sc_ack_send_task(void *pvParameters)
/* Get local IP address of station */
ret = esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &local_ip);
if ((ESP_OK == ret) && (local_ip.ip.addr != INADDR_ANY)) {
/* If ESP touch, smartconfig ACK contains local IP address. */
/* If ESPTouch, smartconfig ACK contains local IP address. */
if (ack->type == SC_TYPE_ESPTOUCH) {
memcpy(ack->ctx.ip, &local_ip.ip.addr, 4);
}
@@ -128,7 +142,11 @@ static void sc_ack_send_task(void *pvParameters)
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);
if (ack->type == SC_TYPE_AIRKISS) {
local_addr.sin_port = htons(SC_ACK_AIRKISS_DEVICE_PORT);
} else {
local_addr.sin_port = htons(SC_ACK_TOUCH_DEVICE_PORT);
}
bind(send_sock, (struct sockaddr *)&local_addr, sockadd_len);
setsockopt(send_sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));