使用ESP32获取DHCP选项
我已经处理了ESP32模块(ESP-IDF),试图通过WiFi和以太网连接到DHCP服务器。关键是,我正在尝试获得DHCP选项,但是我失败了...
我尝试使用LWIP和ESP-NETIF。 (我还必须猜测什么是xxxx和yyyy)
// Create an esp_netif pointer to store current interface
esp_netif_t* ifscan = esp_netif_next(NULL);
// Stores the unique interface descriptor, such as "PP1", etc
char ifdesc[7];
ifdesc[6] = 0; // Ensure null terminated string
uint32_t value = 0;
while (ifscan != NULL)
{
esp_netif_get_netif_impl_name(ifscan, ifdesc);
Serial.printf("IF NAME: %s\n", ifdesc);
esp_err_t code = esp_netif_dhcpc_option(ifscan, ESP_NETIF_OP_GET, ESP_NETIF_DOMAIN_NAME_SERVER, XXXX, YYYY);
Serial.printf("RES: %s - OPTION: %s\n", esp_err_to_name(code), XXXXX);
// Get the next interface
ifscan = esp_netif_next(ifscan);
}
Serial.printf("Done listing network interfaces");
有人有一个示例的示例示例,显示如何在连接后获得选项?
先感谢您。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码中只有几个DHCP选项。
检查对于
ESP_NETIF_DHCPC_OPTION
。esp_netif_domain_name_server
eq不是。对于
ESP_NETIF_OP_GET
仅有ESP_NETIF_IP_REQUEST_RETRY_TIME
和ESP_NETIF_VENDOR_VENDOR_SPECIFIC_INFO
实现。否则,您将获得
ESP_ERR_ERS_ESP_NETIF_INVALID_PARAMS
(20481 0x5001
)。我在我的ESP32结果上尝试了您的代码和选项
224
:
There are only a couple of DHCP options implemented in code.
Check the source code (github) for
esp_netif_dhcpc_option
.ESP_NETIF_DOMAIN_NAME_SERVER
e.q. is not.For
ESP_NETIF_OP_GET
there is onlyESP_NETIF_IP_REQUEST_RETRY_TIME
andESP_NETIF_VENDOR_SPECIFIC_INFO
implemented.Otherwise you get
ESP_ERR_ESP_NETIF_INVALID_PARAMS
(20481 0x5001
) as a result.I tried with your code and option
224
on my ESP32Result: