diff --git a/components/eth_interface/CMakeLists.txt b/components/eth_interface/CMakeLists.txt deleted file mode 100644 index 7bed892..0000000 --- a/components/eth_interface/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(SRCS "eth_interface.c" - INCLUDE_DIRS "include" - REQUIRES driver esp_eth esp_netif) diff --git a/components/eth_interface/include/eth_interface.h b/components/eth_interface/include/eth_interface.h deleted file mode 100644 index 5fc6bcc..0000000 --- a/components/eth_interface/include/eth_interface.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "esp_eth_driver.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void eth_init(void); - -#ifdef __cplusplus -} -#endif diff --git a/components/improv_wifi/CMakeLists.txt b/components/improv_wifi/CMakeLists.txt index 5c41231..aca4905 100644 --- a/components/improv_wifi/CMakeLists.txt +++ b/components/improv_wifi/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.15) SRCS "improvWifi.cpp" "improv_wrapper.cpp" "wifi_provisioning.c" PRIV_INCLUDE_DIRS "Improv-WiFi-Library/src" "priv_include" INCLUDE_DIRS "include" - PRIV_REQUIRES driver esp_wifi wifi_interface + PRIV_REQUIRES driver network_interface #SRCS "Improv-WiFi-Library/src/ImprovWiFiLibrary.cpp" "wifi_provisioning.c" #INCLUDE_DIRS "Improv-WiFi-Library/src" "include" ) diff --git a/components/improv_wifi/wifi_provisioning.c b/components/improv_wifi/wifi_provisioning.c index d34d5c4..1519b51 100644 --- a/components/improv_wifi/wifi_provisioning.c +++ b/components/improv_wifi/wifi_provisioning.c @@ -5,8 +5,6 @@ * Author: karl */ -#include "wifi_provisioning.h" - #include #include "driver/uart.h" diff --git a/components/net_functions/CMakeLists.txt b/components/net_functions/CMakeLists.txt index 64011a1..90e2c5c 100644 --- a/components/net_functions/CMakeLists.txt +++ b/components/net_functions/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "net_functions.c" INCLUDE_DIRS "include" - REQUIRES mdns wifi_interface driver) + REQUIRES mdns network_interface driver) diff --git a/components/net_functions/net_functions.c b/components/net_functions/net_functions.c index 31dabfc..8741d4f 100644 --- a/components/net_functions/net_functions.c +++ b/components/net_functions/net_functions.c @@ -12,13 +12,11 @@ #include "esp_netif.h" #include "esp_sntp.h" #include "esp_system.h" -#include "esp_wifi.h" #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" #include "freertos/task.h" #include "mdns.h" #include "netdb.h" -#include "wifi_interface.h" static const char *TAG = "NETF"; @@ -106,31 +104,31 @@ void sntp_cb(struct timeval *tv) { ESP_LOGI(TAG, "sntp_cb called :%s", strftime_buf); } -void set_time_from_sntp() { - xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, false, true, - portMAX_DELAY); - // ESP_LOGI(TAG, "clock %"); - ESP_LOGI(TAG, "Initializing SNTP"); - sntp_setoperatingmode(SNTP_OPMODE_POLL); - sntp_setservername(0, CONFIG_SNTP_SERVER); - sntp_init(); - // sntp_set_time_sync_notification_cb(sntp_cb); - setenv("TZ", SNTP_TIMEZONE, 1); - tzset(); - - time_t now = 0; - struct tm timeinfo = {0}; - int retry = 0; - const int retry_count = 10; - while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { - ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, - retry_count); - vTaskDelay(2000 / portTICK_PERIOD_MS); - time(&now); - localtime_r(&now, &timeinfo); - } - char strftime_buf[64]; - - strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); - ESP_LOGI(TAG, "The current date/time in UTC is: %s", strftime_buf); -} +// void set_time_from_sntp() { +// xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, false, true, +// portMAX_DELAY); +// // ESP_LOGI(TAG, "clock %"); +// ESP_LOGI(TAG, "Initializing SNTP"); +// sntp_setoperatingmode(SNTP_OPMODE_POLL); +// sntp_setservername(0, CONFIG_SNTP_SERVER); +// sntp_init(); +// // sntp_set_time_sync_notification_cb(sntp_cb); +// setenv("TZ", SNTP_TIMEZONE, 1); +// tzset(); +// +// time_t now = 0; +// struct tm timeinfo = {0}; +// int retry = 0; +// const int retry_count = 10; +// while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { +// ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, +// retry_count); +// vTaskDelay(2000 / portTICK_PERIOD_MS); +// time(&now); +// localtime_r(&now, &timeinfo); +// } +// char strftime_buf[64]; +// +// strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); +// ESP_LOGI(TAG, "The current date/time in UTC is: %s", strftime_buf); +// } diff --git a/components/network_interface/CMakeLists.txt b/components/network_interface/CMakeLists.txt new file mode 100644 index 0000000..d369f27 --- /dev/null +++ b/components/network_interface/CMakeLists.txt @@ -0,0 +1,4 @@ +idf_component_register(SRCS "network_interface.c" "eth_interface.c" "wifi_interface.c" + INCLUDE_DIRS "include" + PRIV_REQUIRES driver esp_eth esp_netif esp_timer nvs_flash + REQUIRES esp_wifi) diff --git a/components/eth_interface/Kconfig.projbuild b/components/network_interface/Kconfig.projbuild similarity index 91% rename from components/eth_interface/Kconfig.projbuild rename to components/network_interface/Kconfig.projbuild index be5c544..9211499 100644 --- a/components/eth_interface/Kconfig.projbuild +++ b/components/network_interface/Kconfig.projbuild @@ -247,3 +247,33 @@ menu "Snapclient Ethernet Configuration" Set the second SPI Ethernet module PHY address according your board schematic. endif # SNAPCLIENT_USE_SPI_ETHERNET endmenu + + +menu "Wifi Configuration" + config ENABLE_WIFI_PROVISIONING + bool "enable WiFi provisioning" + default n + help + Enable WiFi provisioning through improv WiFi (https://github.com/improv-wifi), try it using https://web.esphome.io/ + + config WIFI_SSID + string "WiFi SSID" + default "myssid" + depends on !ENABLE_WIFI_PROVISIONING + help + SSID (network name) for the example to connect to. + + config WIFI_PASSWORD + string "WiFi Password" + default "mypassword" + depends on !ENABLE_WIFI_PROVISIONING + help + WiFi password (WPA or WPA2) for the example to use. + + config WIFI_MAXIMUM_RETRY + int "Maximum connection retry" + default 5 + help + Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. + Set to 0 if unlimited reconnections are preferred. +endmenu diff --git a/components/eth_interface/eth_interface.c b/components/network_interface/eth_interface.c similarity index 89% rename from components/eth_interface/eth_interface.c rename to components/network_interface/eth_interface.c index 460b1fa..fcf8e03 100644 --- a/components/eth_interface/eth_interface.c +++ b/components/network_interface/eth_interface.c @@ -3,8 +3,6 @@ * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ -#include "eth_interface.h" - #include #include @@ -23,16 +21,11 @@ #include "driver/spi_master.h" #endif -static const char *TAG = "snapclient_eth_init"; +#include "network_interface.h" -/* The event group allows multiple bits for each event, but we only care about - * two events: - * - we are connected to the AP with an IP - * - we failed to connect after the maximum amount of retries */ -#define ETH_CONNECTED_BIT BIT0 -#define ETH_FAIL_BIT BIT1 +static const char *TAG = "ETH_IF"; -static EventGroupHandle_t s_eth_event_group; +static uint8_t eth_port_cnt = 0; #if CONFIG_SNAPCLIENT_SPI_ETHERNETS_NUM #define SPI_ETHERNETS_NUM CONFIG_SNAPCLIENT_SPI_ETHERNETS_NUM @@ -272,9 +265,10 @@ err: } #endif // CONFIG_SNAPCLIENT_USE_SPI_ETHERNET -/** Original init function in the example */ -esp_err_t original_eth_init(esp_eth_handle_t *eth_handles_out[], - uint8_t *eth_cnt_out) { +/** + */ +static esp_err_t eth_init(esp_eth_handle_t *eth_handles_out[], + uint8_t *eth_cnt_out) { esp_err_t ret = ESP_OK; esp_eth_handle_t *eth_handles = NULL; uint8_t eth_cnt = 0; @@ -364,7 +358,6 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base, break; case ETHERNET_EVENT_DISCONNECTED: ESP_LOGI(TAG, "Ethernet Link Down"); - xEventGroupSetBits(s_eth_event_group, ETH_FAIL_BIT); break; case ETHERNET_EVENT_START: ESP_LOGI(TAG, "Ethernet Started"); @@ -381,30 +374,35 @@ static void eth_event_handler(void *arg, esp_event_base_t event_base, static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; - const esp_netif_ip_info_t *ip_info = &event->ip_info; - ESP_LOGI(TAG, "Ethernet Got IP Address"); - ESP_LOGI(TAG, "~~~~~~~~~~~"); - ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip)); - ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask)); - ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw)); - ESP_LOGI(TAG, "~~~~~~~~~~~"); + for (int i = 0; i < eth_port_cnt; i++) { + char if_desc_str[10]; + char num_str[3]; - xEventGroupSetBits(s_eth_event_group, ETH_CONNECTED_BIT); + itoa(i, num_str, 10); + strcat(strcpy(if_desc_str, NETWORK_INTERFACE_DESC_ETH), num_str); + + if (network_is_our_netif(if_desc_str, event->esp_netif)) { + const esp_netif_ip_info_t *ip_info = &event->ip_info; + + ESP_LOGI(TAG, "Ethernet Got IP Address"); + ESP_LOGI(TAG, "~~~~~~~~~~~"); + ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip)); + ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask)); + ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw)); + ESP_LOGI(TAG, "~~~~~~~~~~~"); + + break; + } + } } /** Init function that exposes to the main application */ -void eth_init(void) { +void eth_start(void) { // Initialize Ethernet driver - uint8_t eth_port_cnt = 0; esp_eth_handle_t *eth_handles; - ESP_ERROR_CHECK(original_eth_init(ð_handles, ð_port_cnt)); - // Initialize TCP/IP network interface aka the esp-netif (should be called - // only once in application) - ESP_ERROR_CHECK(esp_netif_init()); - // Create default event loop that running in background - ESP_ERROR_CHECK(esp_event_loop_create_default()); + ESP_ERROR_CHECK(eth_init(ð_handles, ð_port_cnt)); // Create instance(s) of esp-netif for Ethernet(s) if (eth_port_cnt == 1) { @@ -429,7 +427,7 @@ void eth_init(void) { for (int i = 0; i < eth_port_cnt; i++) { itoa(i, num_str, 10); strcat(strcpy(if_key_str, "ETH_"), num_str); - strcat(strcpy(if_desc_str, "eth"), num_str); + strcat(strcpy(if_desc_str, NETWORK_INTERFACE_DESC_ETH), num_str); esp_netif_config.if_key = if_key_str; esp_netif_config.if_desc = if_desc_str; esp_netif_config.route_prio -= i * 5; @@ -451,12 +449,4 @@ void eth_init(void) { for (int i = 0; i < eth_port_cnt; i++) { ESP_ERROR_CHECK(esp_eth_start(eth_handles[i])); } - - /* Waiting until either the connection is established (ETH_CONNECTED_BIT) or - * connection failed for the maximum number of re-tries (ETH_FAIL_BIT). The - * bits are set by event_handler() (see above) */ - s_eth_event_group = xEventGroupCreate(); - // EventBits_t bits = - xEventGroupWaitBits(s_eth_event_group, ETH_CONNECTED_BIT, pdFALSE, pdFALSE, - portMAX_DELAY); } diff --git a/components/network_interface/include/eth_interface.h b/components/network_interface/include/eth_interface.h new file mode 100644 index 0000000..6c52b5e --- /dev/null +++ b/components/network_interface/include/eth_interface.h @@ -0,0 +1,15 @@ + +#ifndef COMPONENTS_NETWORK_INTERFACE_INCLUDE_ETH_INTERFACE_H +#define COMPONENTS_NETWORK_INTERFACE_INCLUDE_ETH_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void eth_start(void); + +#ifdef __cplusplus +} +#endif + +#endif // COMPONENTS_NETWORK_INTERFACE_INCLUDE_ETH_INTERFACE_H diff --git a/components/network_interface/include/network_interface.h b/components/network_interface/include/network_interface.h new file mode 100644 index 0000000..7190f03 --- /dev/null +++ b/components/network_interface/include/network_interface.h @@ -0,0 +1,21 @@ +/* + * network_interface.h + * + * Created on: Jan 22, 2025 + * Author: karl + */ + +#ifndef COMPONENTS_NETWORK_INTERFACE_INCLUDE_NETWORK_INTERFACE_H_ +#define COMPONENTS_NETWORK_INTERFACE_INCLUDE_NETWORK_INTERFACE_H_ + +#include + +#include "esp_netif.h" + +#define NETWORK_INTERFACE_DESC_STA "sta" +#define NETWORK_INTERFACE_DESC_ETH "eth" + +bool network_is_our_netif(const char *prefix, esp_netif_t *netif); +void network_init(void); + +#endif /* COMPONENTS_NETWORK_INTERFACE_INCLUDE_NETWORK_INTERFACE_H_ */ diff --git a/components/wifi_interface/include/wifi_interface.h b/components/network_interface/include/wifi_interface.h similarity index 97% rename from components/wifi_interface/include/wifi_interface.h rename to components/network_interface/include/wifi_interface.h index 5cf12e1..5db002d 100644 --- a/components/wifi_interface/include/wifi_interface.h +++ b/components/network_interface/include/wifi_interface.h @@ -26,7 +26,7 @@ #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 -void wifi_init(void); +void wifi_start(void); esp_netif_t *get_current_netif(void); #endif /* _WIFI_INTERFACE_H_ */ diff --git a/components/network_interface/network_interface.c b/components/network_interface/network_interface.c new file mode 100644 index 0000000..078bad6 --- /dev/null +++ b/components/network_interface/network_interface.c @@ -0,0 +1,56 @@ +/* + * network_interface.c + * + * Created on: Jan 22, 2025 + * Author: karl + */ + +/* + * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include +#include + +#include "esp_event.h" +#include "esp_log.h" +#include "esp_mac.h" +#include "esp_netif.h" +#include "esp_wifi_types.h" +#include "freertos/FreeRTOS.h" +#include "freertos/event_groups.h" +#include "freertos/task.h" +#include "include/eth_interface.h" +#include "sdkconfig.h" + +#if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ + CONFIG_SNAPCLIENT_USE_SPI_ETHERNET +#include "eth_interface.h" +#endif + +#include "wifi_interface.h" + +static const char *TAG = "NET_IF"; + +/** + * @brief Checks the netif description if it contains specified prefix. + * All netifs created withing common connect component are prefixed with the + * module TAG, so it returns true if the specified netif is owned by this module + */ +bool network_is_our_netif(const char *prefix, esp_netif_t *netif) { + return strncmp(prefix, esp_netif_get_desc(netif), strlen(prefix) - 1) == 0; +} + +void network_init(void) { + esp_netif_init(); + ESP_ERROR_CHECK(esp_event_loop_create_default()); + +#if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ + CONFIG_SNAPCLIENT_USE_SPI_ETHERNET + eth_start(); +#endif + + wifi_start(); +} diff --git a/components/wifi_interface/wifi_interface.c b/components/network_interface/wifi_interface.c similarity index 68% rename from components/wifi_interface/wifi_interface.c rename to components/network_interface/wifi_interface.c index 7aaac3f..e95f30f 100644 --- a/components/wifi_interface/wifi_interface.c +++ b/components/network_interface/wifi_interface.c @@ -4,14 +4,16 @@ Must be taken over/merge with wifi provision */ + #include "wifi_interface.h" -// #include "esp_event.h" #include "esp_event.h" #include "esp_log.h" #include "esp_mac.h" +#include "esp_netif_types.h" #include "esp_timer.h" #include "esp_wifi.h" +#include "network_interface.h" #include "nvs_flash.h" #if ENABLE_WIFI_PROVISIONING @@ -73,49 +75,57 @@ static void event_handler(void *arg, esp_event_base_t event_base, int event_id, void *event_data) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { esp_wifi_connect(); - } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { - ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; - ESP_LOGI(TAG, "Connected with IP Address:" IPSTR, - IP2STR(&event->ip_info.ip)); - - s_retry_num = 0; - // Signal main application to continue execution - xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if ((s_retry_num < WIFI_MAXIMUM_RETRY) || (WIFI_MAXIMUM_RETRY == 0)) { esp_wifi_connect(); s_retry_num++; ESP_LOGI(TAG, "retry to connect to the AP"); - } else { - xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); } + ESP_LOGI(TAG, "connect to the AP fail"); } } -void wifi_init(void) { - s_wifi_event_group = xEventGroupCreate(); +/** Event handler for IP_EVENT_ETH_GOT_IP */ +static void got_ip_event_handler(void *arg, esp_event_base_t event_base, + int32_t event_id, void *event_data) { + ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; + if (!network_is_our_netif(NETWORK_INTERFACE_DESC_STA, event->esp_netif)) { + return; + } - ESP_ERROR_CHECK(esp_netif_init()); + const esp_netif_ip_info_t *ip_info = &event->ip_info; - ESP_ERROR_CHECK(esp_event_loop_create_default()); + ESP_LOGI(TAG, "Wifi Got IP Address"); + ESP_LOGI(TAG, "~~~~~~~~~~~"); + ESP_LOGI(TAG, "WIFIIP:" IPSTR, IP2STR(&ip_info->ip)); + ESP_LOGI(TAG, "WIFIMASK:" IPSTR, IP2STR(&ip_info->netmask)); + ESP_LOGI(TAG, "WIFIGW:" IPSTR, IP2STR(&ip_info->gw)); + ESP_LOGI(TAG, "~~~~~~~~~~~"); - ESP_ERROR_CHECK(esp_event_handler_register( - WIFI_EVENT, ESP_EVENT_ANY_ID, (esp_event_handler_t)&event_handler, NULL)); - ESP_ERROR_CHECK( - esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, - (esp_event_handler_t)&event_handler, NULL)); - - esp_wifi_netif = esp_netif_create_default_wifi_sta(); + s_retry_num = 0; +} +/** + */ +void wifi_start(void) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); - // esp_wifi_set_bandwidth (WIFI_IF_STA, WIFI_BW_HT20); - esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT40); - esp_wifi_set_protocol( - WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); + esp_netif_inherent_config_t esp_netif_config = + ESP_NETIF_INHERENT_DEFAULT_WIFI_STA(); + // Warning: the interface desc is used in tests to capture actual connection + // details (IP, gw, mask) + esp_netif_config.if_desc = NETWORK_INTERFACE_DESC_STA; + esp_netif_config.route_prio = 128; + esp_wifi_netif = esp_netif_create_wifi(WIFI_IF_STA, &esp_netif_config); + esp_wifi_set_default_wifi_sta_handlers(); + + ESP_ERROR_CHECK(esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT40)); + + ESP_ERROR_CHECK(esp_wifi_set_protocol( + WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N)); // esp_wifi_set_ps(WIFI_PS_MIN_MODEM); // esp_wifi_set_ps(WIFI_PS_NONE); @@ -191,39 +201,17 @@ void wifi_init(void) { /* Start Wi-Fi station */ ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); + + ESP_ERROR_CHECK(esp_event_handler_register( + WIFI_EVENT, ESP_EVENT_ANY_ID, (esp_event_handler_t)&event_handler, NULL)); + ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, + &got_ip_event_handler, NULL)); + ESP_ERROR_CHECK(esp_wifi_start()); - ESP_LOGI(TAG, "wifi_init_sta finished."); + ESP_LOGI(TAG, "wifi_init_sta finished. Trying to connect to %s", + wifi_config.sta.ssid); #endif - - /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or - * connection failed for the maximum number of re-tries (WIFI_FAIL_BIT). The - * bits are set by event_handler() (see above) */ - EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, - WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, - pdFALSE, pdFALSE, portMAX_DELAY); - - /* xEventGroupWaitBits() returns the bits before the call returned, hence we - * can test which event actually happened. */ - if (bits & WIFI_CONNECTED_BIT) { - ESP_LOGI(TAG, "connected to ap SSID: %s", wifi_config.sta.ssid); - } else if (bits & WIFI_FAIL_BIT) { - ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", - wifi_config.sta.ssid, wifi_config.sta.password); - } else { - ESP_LOGE(TAG, "UNEXPECTED EVENT"); - } - - uint8_t base_mac[6]; - // Get MAC address for WiFi station - esp_read_mac(base_mac, ESP_MAC_WIFI_STA); - sprintf(mac_address, "%02X:%02X:%02X:%02X:%02X:%02X", base_mac[0], - base_mac[1], base_mac[2], base_mac[3], base_mac[4], base_mac[5]); - - // ESP_ERROR_CHECK(esp_event_handler_unregister(IP_EVENT, - // IP_EVENT_STA_GOT_IP, &event_handler)); - // ESP_ERROR_CHECK(esp_event_handler_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, - // &event_handler)); vEventGroupDelete(s_wifi_event_group); } esp_netif_t *get_current_netif(void) { return esp_wifi_netif; } diff --git a/components/ota_server/CMakeLists.txt b/components/ota_server/CMakeLists.txt index 98bb8b9..d0adbba 100644 --- a/components/ota_server/CMakeLists.txt +++ b/components/ota_server/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "ota_server.c" INCLUDE_DIRS "include" - REQUIRES app_update dsp_processor wifi_interface lightsnapcast) + REQUIRES app_update dsp_processor network_interface lightsnapcast) diff --git a/components/wifi_interface/CMakeLists.txt b/components/wifi_interface/CMakeLists.txt deleted file mode 100644 index 4f1b439..0000000 --- a/components/wifi_interface/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(SRCS "wifi_interface.c" - INCLUDE_DIRS "include" - REQUIRES wifi_provisioning esp_event esp_wifi esp_hw_support nvs_flash improv_wifi) diff --git a/components/wifi_interface/Kconfig.projbuild b/components/wifi_interface/Kconfig.projbuild deleted file mode 100644 index f75d244..0000000 --- a/components/wifi_interface/Kconfig.projbuild +++ /dev/null @@ -1,28 +0,0 @@ -menu "Wifi Configuration" - config ENABLE_WIFI_PROVISIONING - bool "enable WiFi provisioning" - default n - help - Enable WiFi provisioning through improv WiFi (https://github.com/improv-wifi), try it using https://web.esphome.io/ - - config WIFI_SSID - string "WiFi SSID" - default "myssid" - depends on !ENABLE_WIFI_PROVISIONING - help - SSID (network name) for the example to connect to. - - config WIFI_PASSWORD - string "WiFi Password" - default "mypassword" - depends on !ENABLE_WIFI_PROVISIONING - help - WiFi password (WPA or WPA2) for the example to use. - - config WIFI_MAXIMUM_RETRY - int "Maximum connection retry" - default 5 - help - Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. - Set to 0 if unlimited reconnections are preferred. -endmenu diff --git a/components/wifi_interface/component.mk b/components/wifi_interface/component.mk deleted file mode 100644 index 306fb05..0000000 --- a/components/wifi_interface/component.mk +++ /dev/null @@ -1 +0,0 @@ -COMPONENT_SRCDIRS := . diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c4d9741..06a3340 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRCS "main.c" INCLUDE_DIRS "." - PRIV_REQUIRES esp_timer esp_wifi nvs_flash wifi_interface audio_board audio_hal audio_sal net_functions opus flac ota_server - ui_http_server improv_wifi eth_interface + PRIV_REQUIRES esp_timer esp_wifi nvs_flash audio_board audio_hal audio_sal net_functions opus flac ota_server + ui_http_server network_interface ) diff --git a/main/main.c b/main/main.c index 7cf48ad..ab62973 100644 --- a/main/main.c +++ b/main/main.c @@ -24,11 +24,7 @@ #endif #include "nvs_flash.h" -#include "wifi_interface.h" - -// Minimum ESP-IDF stuff only hardware abstraction stuff -#include - +// #include "wifi_interface.h" #include "board.h" #include "es8388.h" #include "esp_netif.h" @@ -40,6 +36,7 @@ #include "lwip/sys.h" #include "mdns.h" #include "net_functions.h" +#include "network_interface.h" // Web socket server // #include "websocket_if.h" @@ -2532,20 +2529,24 @@ void app_main(void) { gpio_set_level(pin_config0.ws_io_num, 0); } -#if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ - CONFIG_SNAPCLIENT_USE_SPI_ETHERNET - eth_init(); - // pass "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF" - init_http_server_task("ETH_DEF"); -#else - // Enable and setup WIFI in station mode and connect to Access point setup in - // menu config or set up provisioning mode settable in menuconfig - wifi_init(); - ESP_LOGI(TAG, "Connected to AP"); - // http server for control operations and user interface - // pass "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF" - init_http_server_task("WIFI_STA_DEF"); -#endif + /* + #if CONFIG_SNAPCLIENT_USE_INTERNAL_ETHERNET || \ + CONFIG_SNAPCLIENT_USE_SPI_ETHERNET + eth_init(); + // pass "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF" + init_http_server_task("ETH_DEF"); + #else + // Enable and setup WIFI in station mode and connect to Access point setup + in + // menu config or set up provisioning mode settable in menuconfig + wifi_init(); + ESP_LOGI(TAG, "Connected to AP"); + // http server for control operations and user interface + // pass "WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF" + init_http_server_task("WIFI_STA_DEF"); + #endif + */ + network_init(); // Enable websocket server // ESP_LOGI(TAG, "Setup ws server");