在vscode里,按f1,顶部会弹出一个对话框,选择 ESP-IDF: Show Example Projects ,在弹出的页面里,选择 ethernet->basic ,打开介绍界面,在顶部有个蓝色提示文字 Create project using example basic点击它,选择一个自己知道的文件夹,相当于复制一份这个工程。接下去都在自己的这个文件夹里修改了。
修改的关键是:
1. 先关闭工程自带的dhcpc ;
2. 设置静态ip,需要调用esp32自带的函数 esp_ip4addr_aton来做字符串ip和uint32_t 的转换;
3. 配置上面两步,要在函数 esp_eth_start(eth_handle) 之前。
ESP_LOGI(TAG, "dhcpc_stop 1");
ESP_ERROR_CHECK(esp_netif_dhcpc_stop(eth_netif));
ESP_LOGI(TAG, "dhcpc_stop 2");
esp_netif_ip_info_t info_t;
memset(&info_t, 0, sizeof(esp_netif_ip_info_t));
info_t.ip.addr = esp_ip4addr_aton((const char *)"192.168.1.50");
info_t.netmask.addr = esp_ip4addr_aton((const char *)"255.255.255.0");
info_t.gw.addr = esp_ip4addr_aton((const char *)"192.168.1.1");
ESP_LOGI(TAG, "static ip 1");
ESP_ERROR_CHECK( esp_netif_set_ip_info(eth_netif, &info_t));
ESP_LOGI(TAG, "static ip 2");
/* start Ethernet driver state machine */
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
大神的链接
https://www.amobbs.com/forum.php ... amp;highlight=ESP32
找到的修改方法链接
https://espressif-docs.readthedo ... ework/ethernet.html