Ethernet shows connected but no IP Address is getting assigned

#1
  1. My goal is: To connect Esp32 to the internet by using Ethernet.

  2. My actions are: My code is to connect the ESP32 to the internet using an Ethernet interface.

  3. The result I see is: In MOS Console It shows Ethernet is connected but no IP Address got assigned(Cross checked in Advance IP Scanner).

  4. My expectation & question is: To connect the ESP32 to the internet by using an Ethernet interface and To know that is the IP Address got assigned when it is connected through ethernet.

Ethernet Interface I am using is LAN8720A.

CODE:

main.c

#include "mgos.h"

#include "mgos_net.h"

#define MGOS_EVENT_GRP_NET MGOS_EVENT_BASE('N', 'E', 'T')

static void my_net_ev_handler(int ev, void *evd, void *arg)

{

    struct mgos_net_ip_info ip_info;

    char ethernet_ip[16];

    if (ev == MGOS_NET_EV_IP_ACQUIRED)

    {

        LOG(LL_INFO, ("Just got IP!"));

        if (mgos_net_get_ip_info(MGOS_NET_IF_TYPE_ETHERNET, 0, &ip_info))

        {

            mgos_net_ip_to_str(&ip_info.ip, ethernet_ip);

            printf("Ethernet Ip: %s", ethernet_ip);

        }

    }

    else {

        printf("Ethernet is connected but no IP is Assigned");

    }

    (void)evd;

    (void)arg;

}

// App Initilization

enum mgos_app_init_result mgos_app_init(void)

{

    mgos_event_add_group_handler(MGOS_EVENT_GRP_NET, my_net_ev_handler, NULL);

    return MGOS_APP_INIT_SUCCESS;

}

mos.yml

author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0

libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

# Optional. List of tags for online search.
tags:
  - c

sources:
  - src

filesystem:
  - fs

config_schema:
  - ["wifi.ap.enable", false]
  - ["wifi.sta.enable", false]
  - ["eth.enable", true]
  - ["eth.clk_mode", 1]



libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-uart
  - origin: https://github.com/mongoose-os-libs/ethernet # Ethernet Library

# Used by the mos tool to catch mos binaries incompatible with this file format
manifest_version: 2017-09-29
#2

Your program will printf("Ethernet is connected but no IP is Assigned"); for every ev != MGOS_NET_EV_IP_ACQUIRED.

Does your module have a power on pin?

This is not needed in your code

#define MGOS_EVENT_GRP_NET MGOS_EVENT_BASE('N', 'E', 'T')
#3

@nliviu Thank you for quick replay, our module doesn’t have power on pin.

#4

What messages do you you see in the console regarding ethernet?
mgos_ethernet_init logs Ethernet init failed or the MAC.

If init failed, maybe you have to adjust the pins and/or the clk_mode

#5

@nliviu It shows Ethernet connected but no IP Address is assigned.

#6

This does not come from the ethernet library. It comes from your program and it’s not a relevant message because it will be output for every event which is not MGOS_NET_EV_IP_ACQUIRED. Check your own code.

  if (ev == MGOS_NET_EV_IP_ACQUIRED) {
    LOG(LL_INFO, ("Just got IP!"));
    if (mgos_net_get_ip_info(MGOS_NET_IF_TYPE_ETHERNET, 0, &ip_info)) {
      mgos_net_ip_to_str(&ip_info.ip, ethernet_ip);
      printf("Ethernet Ip: %s", ethernet_ip);
    }
  } else {
    printf("Ethernet is connected but no IP is Assigned");
  }

You should see either Ethernet init failed or ETH: MAC ...

#7

I’m curious, how do you expect to get an IP address ? Do you have a DHCP server in your network ? Have you sniffed your network ? Did you see the DHCP request coming out ? Or did you setup a static address ? In such a case, try to enable the gratuitous ARP so you can see an ARP coming out on startup.