ESP32设置以太网静态IP方法

在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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值