How do I configure the network configuration for communicating between pc and esp32?

Daniel.Kim
Posts: 9
Joined: Tue Apr 02, 2019 2:40 am

How do I configure the network configuration for communicating between pc and esp32?

Postby Daniel.Kim » Wed Apr 22, 2020 1:40 am

Hi all

I want to communicate between pc and esp32.
So I'm testing the basic from example/ethernet.
I set the pc network configuration by ip address 192.168.1.99 and netmask is 255, 255, 255, 0 , gateway 192.168.1.1.
In esp32-ethernet_kit, I set the network configuration by ip 192.168.1.2, netmask 255.255.255.0 gateway 192.168.1.1.

Below code is modified from basic.

Code: Select all

/** Event handler for IP_EVENT_ETH_GOT_IP */
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
                                 int32_t event_id, void *event_data)
{
    tcpip_adapter_ip_info_t  ip_info;
    ip_addr_t addr;

   [b] addr.type = IPADDR_TYPE_V4;
    addr.u_addr.ip4.addr = htons(0xC0A80102);
    dhcps_dns_setserver((const ip_addr_t *)&addr);

    int ret = esp_netif_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
    printf("stop dhcp ret = %d\n",ret);
    memset(&ip_info, 0, sizeof(ip_info));
    IP4_ADDR(&ip_info.ip, 192, 168, 1, 2);
    IP4_ADDR(&ip_info.gw, 192, 168, 1, 1);
    IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
    ret = esp_netif_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
    printf("fixex ip ret = %d\n",ret);[/b]

    //ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
    //const esp_netif_ip_info_t *ip_info = &event->ip_info;

    ESP_LOGI(TAG, "Ethernet Got IP Address");
    ESP_LOGI(TAG, "~~~~~~~~~~~");
    ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info.ip));
    ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info.netmask));
    ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info.gw));
    
I add the file which runs the code.
I send the ping to esp32 from pc but it isn't working.

Please help me..

Safe stay.~
Attachments
result.PNG
Result of code running.
result.PNG (19.21 KiB) Viewed 2185 times

Who is online

Users browsing this forum: lstpvtltd, runeruiter and 113 guests