SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

kesha.modhia
Posts: 44
Joined: Fri May 13, 2022 12:36 pm

SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby kesha.modhia » Thu Sep 15, 2022 11:53 am

Hello,

I have one query regarding Ethernet disconnection

module esp32 wrover I

I am using ethernet on customized board which is having esp32 wrover-I mounted on the board.

In that getting SYSTEM_EVENT_ETH_GOT_IP, when I connect ethernet cable to the board.

but not getting below events
SYSTEM_EVENT_ETH_START
SYSTEM_EVENT_ETH_CONNECTED
and below event is also not generating upon disconnecting the cable from the board
SYSTEM_EVENT_ETH_DISCONNECTED

what could be the reason of this scenario.

ESP_ondrej
Posts: 210
Joined: Fri May 07, 2021 10:35 am

Re: SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby ESP_ondrej » Tue Sep 20, 2022 7:12 am

Could you please share more information about your code? Did you implement and register event handler function like below?

Code: Select all

static void eth_event_handler(void *arg, esp_event_base_t event_base,
                              int32_t event_id, void *event_data)
{
    uint8_t mac_addr[6] = {0};
    /* we can get the ethernet driver handle from event data */
    esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;

    switch (event_id) {
    case ETHERNET_EVENT_CONNECTED:
        esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
        ESP_LOGI(TAG, "Ethernet Link Up");
        ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
                 mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
        break;
    case ETHERNET_EVENT_DISCONNECTED:
        ESP_LOGI(TAG, "Ethernet Link Down");
        break;
    case ETHERNET_EVENT_START:
        ESP_LOGI(TAG, "Ethernet Started");
        break;
    case ETHERNET_EVENT_STOP:
        ESP_LOGI(TAG, "Ethernet Stopped");
        break;
    default:
        break;
    }
}

...


ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL));


kesha.modhia
Posts: 44
Joined: Fri May 13, 2022 12:36 pm

Re: SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby kesha.modhia » Tue Sep 20, 2022 9:13 am

Thank you for the reply, yes i have handled these event like below.

case SYSTEM_EVENT_ETH_START:
DEBUG_LOGI(UART,TAG,"SYSTEM_EVENT_ETH_START\r\n");
eth_event_status = EVENT_ETH_START;
break;

case SYSTEM_EVENT_ETH_CONNECTED:
DEBUG_LOGI(UART,TAG,"SYSTEM_EVENT_ETH_CONNECTED\r\n");
eth_event_status = EVENT_ETH_CONNECTED;
led_event(LED_NETWORK_CONNECTED);
break;

case SYSTEM_EVENT_ETH_GOT_IP:

DEBUG_LOGI(UART,TAG,"SYSTEM_EVENT_ETH_GOT_IP\r\n");
//SetStaConnectedFlag(); //SLS Change
eth_event_status = EVENT_ETH_GOT_IP;
(void) ethernet_get_ip(&ip, NULL);
ESP_LOGI(TAG, "\n~~~~~~~~~~~\n");
ESP_LOGI(TAG, "ETHIP:"IPSTR, IP2STR(&ip.ip));
ESP_LOGI(TAG, "ETHPMASK:"IPSTR, IP2STR(&ip.netmask));
ESP_LOGI(TAG, "ETHPGW:"IPSTR, IP2STR(&ip.gw));
ESP_LOGI(TAG, "\n~~~~~~~~~~~\n");

case SYSTEM_EVENT_ETH_DISCONNECTED:
DEBUG_LOGI(UART,TAG,"SYSTEM_EVENT_ETH_DISCONNECTED\r\n");
//ClearStaConnectedFlag(); //SLS change
eth_event_status = EVENT_ETH_DISCONNECTED;
DEBUG_LOGI(UART,TAG,"SYSTEM_EVENT_ETH_DISCONNECTED\r\n");

ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));

Here is my concern, as I am getting SYSTEM_EVENT_ETH_GOT_IP but other three events I am not able to get

ESP_ondrej
Posts: 210
Joined: Fri May 07, 2021 10:35 am

Re: SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby ESP_ondrej » Tue Sep 20, 2022 11:22 am

What IDF version do you use?

kesha.modhia
Posts: 44
Joined: Fri May 13, 2022 12:36 pm

Re: SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby kesha.modhia » Tue Sep 20, 2022 12:53 pm

I use idf version 4.2

ESP_ondrej
Posts: 210
Joined: Fri May 07, 2021 10:35 am

Re: SYSTEM_EVENT_ETH_DISCONNECTED event not generating upon disconnecting ethernet cable

Postby ESP_ondrej » Tue Sep 20, 2022 2:11 pm

Try to use ETHERNET_EVENT_START, ETHERNET_EVENT_STOP, ETHERNET_EVENT_CONNECTED and ETHERNET_EVENT_DISCONNECTED. Anyway, I would strongly recommend to follow Ethernet event handling demonstrated in Ethernet Basic example.

Who is online

Users browsing this forum: Bing [Bot] and 83 guests