Re: Enabling WiFi & Ethernet together
Posted: Tue Aug 14, 2018 7:22 am
Hard to say without looking at the code. Have you tried decoding the backtrace, see where it ends up?
Hi ESP_Sprite,ESP_Sprite wrote:Hard to say without looking at the code. Have you tried decoding the backtrace, see where it ends up?
Hi ESP_angusESP_Angus wrote:Hi mertkahyaoglu,
From the software side, this is possible at the moment if you enable both WiFi and Ethernet in the "Component Config" section of IDF config. (At the moment, due to a bug, you have enable both in configuration but you don't have to use both.)
The two interfaces will be treated as independent in the LWIP TCP/IP library (ie you can bind sockets to either interface, and outgoing packets should be routed based IP packet destination address). We don't have support for source based routing or routing packets between the interfaces (ie there's no support for the ESP32 to act as a tiny WiFi router), although I think this could be technically possible.
There also isn't an example for this configuration in IDF yet, but you can make one by combining the code from one of the WiFi-based examples with the Ethernet example. Let us know if you have any trouble making this work.
From the hardware side, we don't have an official ethernet reference design yet but one will be available.
Angus
That's right, ESP-IDF supports the BSD socket interface of LWIP, so you can use the bind() API call to bind a socket to a local address, before using it.lnunez wrote:i was wondering, how can you bind a socket with an interface?, I haven´t found yet any function in the API to do this. Maybe the sending interface is selected based on inteface´s ip?
I think ESP32 supports both BSD Sockets and Netconn Sockets to create communication using TCP Layer sockets.ESP_Angus wrote:That's right, ESP-IDF supports the BSD socket interface of LWIP, so you can use the bind() API call to bind a socket to a local address, before using it.lnunez wrote:i was wondering, how can you bind a socket with an interface?, I haven´t found yet any function in the API to do this. Maybe the sending interface is selected based on inteface´s ip?
Depending on the local address supplied, you can bind to a particular interface.
Code: Select all
// The IP address that we want our device to have.
#define DEVICE_IP "192.168.10.254"
// The Gateway address where we wish to send packets.
// This will commonly be our access point.
#define DEVICE_GW "192.168.10.1"
// The netmask specification.
#define DEVICE_NETMASK "255.255.0.0"
static void initialise_ethernet(void)
{
esp_err_t ret = ESP_OK;
tcpip_adapter_ip_info_t ipInfo;
inet_pton(AF_INET, DEVICE_IP, &ipInfo.ip);
inet_pton(AF_INET, DEVICE_GW, &ipInfo.gw);
inet_pton(AF_INET, DEVICE_NETMASK, &ipInfo.netmask);
tcpip_adapter_init();
ret = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
ESP_LOGI(TAG, "dhcp client stop RESULT: %d", ret);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &ipInfo);
eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG;
// Set the PHY address in the example configuration
config.phy_addr = CONFIG_PHY_ADDRESS;
config.gpio_config = eth_gpio_config_rmii;
// config.tcpip_input = tcpip_adapter_eth_input_sta_output; // for bridge mode
config.tcpip_input = tcpip_adapter_eth_input; // for ethernet mode
#ifdef CONFIG_PHY_USE_POWER_PIN
// Replace the default 'power enable' function with an example-specific
// one that toggles a power GPIO.
config.phy_power_enable = phy_device_power_enable_via_gpio;
#endif
esp_eth_init(&config);
//esp_eth_init_internal(&config);
esp_eth_enable();
}
Hello Espressif Developers,bhakti wrote: ↑Tue Mar 12, 2019 12:17 pmIn ethernet and wifi bridge condition , Can we use ethernet as independent interface as well?
I tried it in this code https://github.com/espressif/esp-iot-so ... s/eth2wifi by assigning static ip address to ethernet but either it is working in bridge mode or as independent interface using static ip.
Board : ESP32-EVB Rev.D (Olimex)Code: Select all
// The IP address that we want our device to have. #define DEVICE_IP "192.168.10.254" // The Gateway address where we wish to send packets. // This will commonly be our access point. #define DEVICE_GW "192.168.10.1" // The netmask specification. #define DEVICE_NETMASK "255.255.0.0" static void initialise_ethernet(void) { esp_err_t ret = ESP_OK; tcpip_adapter_ip_info_t ipInfo; inet_pton(AF_INET, DEVICE_IP, &ipInfo.ip); inet_pton(AF_INET, DEVICE_GW, &ipInfo.gw); inet_pton(AF_INET, DEVICE_NETMASK, &ipInfo.netmask); tcpip_adapter_init(); ret = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH); ESP_LOGI(TAG, "dhcp client stop RESULT: %d", ret); tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &ipInfo); eth_config_t config = DEFAULT_ETHERNET_PHY_CONFIG; // Set the PHY address in the example configuration config.phy_addr = CONFIG_PHY_ADDRESS; config.gpio_config = eth_gpio_config_rmii; // config.tcpip_input = tcpip_adapter_eth_input_sta_output; // for bridge mode config.tcpip_input = tcpip_adapter_eth_input; // for ethernet mode #ifdef CONFIG_PHY_USE_POWER_PIN // Replace the default 'power enable' function with an example-specific // one that toggles a power GPIO. config.phy_power_enable = phy_device_power_enable_via_gpio; #endif esp_eth_init(&config); //esp_eth_init_internal(&config); esp_eth_enable(); }