IOT ETH Ethernet
iot_eth provides a complete solution for connecting 4G modules to Ethernet, offering an abstraction layer for the underlying hardware and a default network interface based on LWIP. It also supports user-defined network interfaces.
Features
- Advanced factory mode, supporting various underlying connection methods 
- Default support for LWIP network interface, also supports user-defined network interfaces 
User Guide
- First, initialize the driver layer to provide lower-level hardware abstraction 
iot_usbh_rndis_config_t rndis_cfg = {
    .auto_detect = true,  // auto detect 4G module
    .auto_detect_timeout = pdMS_TO_TICKS(1000),  // auto detect timeout
};
iot_eth_driver_t *rndis_handle = NULL;
esp_err_t ret = iot_eth_new_usb_rndis(&rndis_cfg, &rndis_handle);
if (ret != ESP_OK || rndis_handle == NULL) {
    ESP_LOGE(TAG, "Failed to create USB RNDIS driver");
    return;
}
- Initialize the iot_eth layer 
iot_eth_config_t eth_cfg = {
    .driver = rndis_handle,
    .stack_input = NULL,
    .user_data = NULL,
};
iot_eth_handle_t eth_handle = NULL;
ret = iot_eth_install(ð_cfg, ð_handle);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "Failed to install USB RNDIS driver");
    return;
}
- Start the iot_eth layer 
ret = iot_eth_start(eth_handle);
if (ret != ESP_OK) {
    ESP_LOGE(TAG, "Failed to start USB RNDIS driver");
    return;
}
Using Other Network Interfaces
- Transmission: Call iot_eth_transmit to send data. 
- Reception: Configure the stack_input callback function in iot_eth_config_t. This callback is called when data is received. 
- Get the MAC address of the 4G module: Call iot_eth_get_addr to retrieve the MAC address. 
Supported Network Interfaces
- USB interface-based RNDIS USB RNDIS Host Driver 
- USB interface-based PPP USB PPP 
- USB interface-based ECM USB ECM Host Driver 
API Reference
Header File
Functions
- 
esp_err_t iot_eth_install(iot_eth_config_t *config, iot_eth_handle_t *handle)
- 
esp_err_t iot_eth_uninstall(iot_eth_handle_t handle)
- 
esp_err_t iot_eth_start(iot_eth_handle_t handle)
- 
esp_err_t iot_eth_stop(iot_eth_handle_t handle)
- 
esp_err_t iot_eth_transmit(iot_eth_handle_t handle, void *data, size_t len)
- 
esp_err_t iot_eth_get_addr(iot_eth_handle_t handle, uint8_t *mac)
- 
esp_err_t iot_eth_update_input_path(iot_eth_handle_t handle, static_input_cb_t stack_input, void *user_data)
Structures
- 
struct iot_eth_config_t
- Ethernet configuration structure. - This structure holds the configuration for initializing an Ethernet instance. - Public Members - 
iot_eth_driver_t *driver
- Pointer to the Ethernet driver 
 - 
static_input_cb_t stack_input
- Function pointer for stack input 
 - 
void *user_data
- User data for callbacks 
 
- 
iot_eth_driver_t *driver
Type Definitions
- 
typedef void *iot_eth_handle_t
- iot_eth event base declaration - Ethernet handle type - This is a handle to an Ethernet instance, used for managing Ethernet operations. 
- 
typedef esp_err_t (*static_input_cb_t)(iot_eth_handle_t handle, uint8_t *data, size_t len, void *user_data)
- Static input callback function type. - This type defines a function pointer for a static input callback. It takes an Ethernet handle, a pointer to data, the length of the data, and a user data pointer as arguments.