Espressif ESP32-S2 Programming Manual page 185

Table of Contents

Advertisement

Chapter 2. API Reference
switch
(event_id) {
case
ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ESP_LOGI(TAG,
ESP_LOGI(TAG,
addr[4], mac_addr[5]);
break;
case
ETHERNET_EVENT_DISCONNECTED:
ESP_LOGI(TAG,
break;
case
ETHERNET_EVENT_START:
ESP_LOGI(TAG,
break;
case
ETHERNET_EVENT_STOP:
ESP_LOGI(TAG,
break;
default:
break;
}
}
esp_event_loop_create_default();
background
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler,
// register Ethernet event handler (to deal with user specific stuffs when
like link up/down happened)
Start Ethernet Driver
After driver installation, we can start Ethernet immediately.
esp_eth_start(eth_handle);
Connect Driver to TCP/IP Stack
(Open System Interconnection), we're still on level 2 (i.e. Data Link Layer). We can detect link up and down event,
we can gain MAC address in user space, but we can't obtain IP address, let alone send HTTP request. The TCP/IP
stack used in ESP-IDF is called LwIP, for more information about it, please refer to LwIP.
To connect Ethernet driver to TCP/IP stack, these three steps need to follow:
1. Create network interface for Ethernet driver
2. Attach the network interface to Ethernet driver
3. Register IP event handlers
More information about network interface, please refer to
/** Event handler for IP_EVENT_ETH_GOT_IP */
static
void got_ip_event_handler(void
{
ip_event_got_ip_t *event
const
esp_netif_ip_info_t *ip_info
ESP_LOGI(TAG,
"Ethernet Got IP
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG,
"ETHIP:"
ESP_LOGI(TAG,
"ETHMASK:"
ESP_LOGI(TAG,
"ETHGW:"
ESP_LOGI(TAG, "~~~~~~~~~~~");
}
Espressif Systems
"Ethernet Link
Up");
"Ethernet HW Addr
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_
"Ethernet Link
Down");
"Ethernet
Started");
"Ethernet
Stopped");
// create a default event loop that running
// start Ethernet driver state machine
Up until now, we have installed the Ethernet driver. From the view of OSI
*arg, esp_event_base_t event_base,
int32_t
=
(ip_event_got_ip_t *) event_data;
=
Address");
IPSTR, IP2STR(&ip_info->ip));
IPSTR, IP2STR(&ip_info->netmask));
IPSTR, IP2STR(&ip_info->gw));
Submit Document Feedback
%02x:%02x:%02x:%02x:%02x:%02x",
Network
Interface.
event_id,
void
*event_data)
&event->ip_info;
174
(continued from previous page)
in␣
NULL);␣
event␣
(continues on next page)
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents

Save PDF