Use unique interface name.

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-05-14 11:04:16 +08:00
parent eaaf02b373
commit ec5ed309a3
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
1 changed files with 19 additions and 6 deletions

View File

@ -14,6 +14,9 @@
#define APP_WIFI_EVENT_GROUP_EVENT_CONNECTED (1 << 0U)
#define APP_WIFI_EVENT_GROUP_EVENT_FAILED (1 << 1U)
#define APP_NETIF_NAME_PREFIX "LilyGo_EPD47"
#define APP_LOG_TAG "APP_WIFI"
EventGroupHandle_t g_app_wifi_event_group;
@ -30,11 +33,20 @@ int app_wifi_init(void) {
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_sta();
esp_netif_t *sta_if = esp_netif_create_default_wifi_sta();
wifi_init_config_t wifi_init_cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_cfg));
char hostname_buf[64];
uint8_t mac_addr[6];
esp_wifi_get_mac(WIFI_IF_STA, mac_addr);
snprintf(hostname_buf, 64, APP_NETIF_NAME_PREFIX "_%02X%02X%02X", mac_addr[3], mac_addr[4], mac_addr[5]);
esp_netif_set_hostname(sta_if, hostname_buf);
esp_event_handler_instance_t inst_any_id;
esp_event_handler_instance_t inst_got_ip;
@ -71,7 +83,8 @@ int app_wifi_is_ready(void) {
}
int app_wifi_wait_ready(uint32_t msec) {
if(xEventGroupWaitBits(g_app_wifi_event_group, APP_WIFI_EVENT_GROUP_EVENT_CONNECTED, 0U, 0U, pdMS_TO_TICKS(msec)) == pdTRUE) {
if (xEventGroupWaitBits(g_app_wifi_event_group, APP_WIFI_EVENT_GROUP_EVENT_CONNECTED, 0U, 0U,
pdMS_TO_TICKS(msec)) == pdTRUE) {
return 0;
}