-
My goal is: To connect Esp32 to the internet by using Ethernet.
-
My actions are: My code is to connect the ESP32 to the internet using an Ethernet interface.
-
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).
-
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