diff --git a/components/smartconfig_ack/include/smartconfig_ack.h b/components/smartconfig_ack/include/smartconfig_ack.h index 8594b5d9..1f037a57 100644 --- a/components/smartconfig_ack/include/smartconfig_ack.h +++ b/components/smartconfig_ack/include/smartconfig_ack.h @@ -54,6 +54,14 @@ typedef struct sc_ack { } ctx; } sc_ack_t; +/** + * @brief Smartconfig parameters passed sc_callback call. + */ +typedef struct sc_callback_ack { + uint8_t ip[4]; /*!< IP address of cellphone */ + sc_ack_type_t type; /*!< Smartconfig ACK type */ +} sc_callback_data_t; + /** * @brief Send smartconfig ACK to cellphone. * diff --git a/components/smartconfig_ack/smartconfig_ack.c b/components/smartconfig_ack/smartconfig_ack.c index 0a5c8ed1..3a022556 100644 --- a/components/smartconfig_ack/smartconfig_ack.c +++ b/components/smartconfig_ack/smartconfig_ack.c @@ -53,8 +53,14 @@ static void sc_ack_send_task(void *pvParameters) { sc_ack_t *ack = (sc_ack_t *)pvParameters; tcpip_adapter_ip_info_t local_ip; + sc_callback_data_t sc_callback_data; uint8_t remote_ip[4]; + memset(&sc_callback_data, 0x0, sizeof(sc_callback_data_t)); + if (ack->type == SC_ACK_TYPE_ESPTOUCH) { + memcpy(sc_callback_data.ip, ack->ctx.ip, sizeof(sc_callback_data.ip)); + } memcpy(remote_ip, ack->ctx.ip, sizeof(remote_ip)); + sc_callback_data.type = ack->type; int remote_port = (ack->type == SC_ACK_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT; struct sockaddr_in server_addr; socklen_t sin_size = sizeof(server_addr); @@ -117,7 +123,7 @@ static void sc_ack_send_task(void *pvParameters) server_addr.sin_addr.s_addr = from.sin_addr.s_addr; } else { if (ack->cb) { - ack->cb(SC_STATUS_LINK_OVER, remote_ip); + ack->cb(SC_STATUS_LINK_OVER, &sc_callback_data); } goto _end; } @@ -140,7 +146,7 @@ static void sc_ack_send_task(void *pvParameters) *ack->link_flag = 1; } if (ack->cb) { - ack->cb(SC_STATUS_LINK_OVER, remote_ip); + ack->cb(SC_STATUS_LINK_OVER, &sc_callback_data); } goto _end; } diff --git a/examples/wifi/smart_config/main/smartconfig_main.c b/examples/wifi/smart_config/main/smartconfig_main.c index db4d005b..0839c4ce 100644 --- a/examples/wifi/smart_config/main/smartconfig_main.c +++ b/examples/wifi/smart_config/main/smartconfig_main.c @@ -19,6 +19,7 @@ #include "nvs_flash.h" #include "tcpip_adapter.h" #include "esp_smartconfig.h" +#include "smartconfig_ack.h" /* FreeRTOS event group to signal when we are connected & ready to make a request */ static EventGroupHandle_t wifi_event_group; @@ -88,9 +89,19 @@ static void sc_callback(smartconfig_status_t status, void *pdata) case SC_STATUS_LINK_OVER: ESP_LOGI(TAG, "SC_STATUS_LINK_OVER"); if (pdata != NULL) { - uint8_t phone_ip[4] = { 0 }; - memcpy(phone_ip, (uint8_t* )pdata, 4); - ESP_LOGI(TAG, "Phone ip: %d.%d.%d.%d\n", phone_ip[0], phone_ip[1], phone_ip[2], phone_ip[3]); + sc_callback_data_t *sc_callback_data = (sc_callback_data_t *)pdata; + switch (sc_callback_data->type) { + case SC_ACK_TYPE_ESPTOUCH: + ESP_LOGI(TAG, "Phone ip: %d.%d.%d.%d", sc_callback_data->ip[0], sc_callback_data->ip[1], sc_callback_data->ip[2], sc_callback_data->ip[3]); + ESP_LOGI(TAG, "TYPE: ESPTOUCH"); + break; + case SC_ACK_TYPE_AIRKISS: + ESP_LOGI(TAG, "TYPE: AIRKISS"); + break; + default: + ESP_LOGE(TAG, "TYPE: ERROR"); + break; + } } xEventGroupSetBits(wifi_event_group, ESPTOUCH_DONE_BIT); break; @@ -102,7 +113,7 @@ static void sc_callback(smartconfig_status_t status, void *pdata) void smartconfig_example_task(void * parm) { EventBits_t uxBits; - ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) ); + ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS) ); ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) ); while (1) { uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);