espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.63k stars 7.28k forks source link

我想在usb作为网卡时启用dhcp,我应该怎么做 (IDFGH-13272) #14203

Open yunfusheng33 opened 3 months ago

yunfusheng33 commented 3 months ago

Is your feature request related to a problem?

No response

Describe the solution you'd like.

我已经将usb模拟为网卡设备初始化后,将pc的网络共享给该设备,从而通过tcp client连接外部网络,但是我的网络IP是静态的,我应该怎么更改为dhcp自动获取IP?

Describe alternatives you've considered.

No response

Additional context.

No response

leeebo commented 3 months ago

@yunfusheng33 如果共享 PC 的网络给 ESP32,PC 是 DHCP server,如果我没记错的话,它会给 ESP32 设备分配一个 192.168.137.x 的 IP 地址。

你的意思是 如何让 ESP32 通过 PC 获取到一个上游路由器分配的地址?

yunfusheng33 commented 3 months ago

@leeebo 我现在分配给esp的是一个静态的192.168.137.x 的 IP 地址,然后我在pc使用了一个DHCP Server软件,将esp的虚拟网卡做HTTP(Web Server),我应该如何使用dhcp client来获取192.168.137.2-192.168.137.255之间的一个ip?

下面是我的HTTP(Web Server) c43f5eaeb8fdbc0d1630ea40e24a3ba

leeebo commented 3 months ago

@yunfusheng33 以太网接口默认配置下 DHCP Client 就是开启的,不用额外配置,你可以直接跑示例试试看 https://github.com/espressif/esp-idf/tree/master/examples/ethernet/basic

yunfusheng33 commented 3 months ago

@leeebo 这个例程我有看过,但我是想通过usb模拟为虚拟网卡使用,类似于esp-iot-solution里的usb-dongle

leeebo commented 3 months ago

@yunfusheng33 明白了。不过一般 usb-dongle 方案,ESP32 端不再跑上层网络协议栈,只做接口间转发。你的需求可以参考这个方案 https://github.com/espressif/esp-iot-bridge

yunfusheng33 commented 3 months ago

@leeebo 好的,我看下,而且我在跑上面这个以太网例程的时候,串口并没有输出获取到dhcp的信息,我的板子是esp32s3devkitC,是板子或者我的dhcps软件有问题吗?