Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error on compling - ethenet
#1
hello,

in my home I have several problems with WiFi so I'd like to connect via ethernet port.
So I adapted the code at this link to my needs.

This is this part of code i'm using
Code:
esphome:
  name: luci-2
  platform: ESP32
  board: esp32dev

# ethernet configuration entry
ethernet:
type: LAN8720
mdc_pin: GPIO23
mdio_pin: GPIO18
clk_mode: GPIO17_OUT
phy_addr: 0

# Optional manual IP
# manual_ip:
# static_ip: 192.168.0.199
# gateway: 192.168.1.1
# subnet: 255.255.255.0

web_server:
  port: 80

# Enable logging
logger:

captive_portal:

# Basic Config
i2c:
  sda: 4
  scl: 5
  scan: true
  id: bus_a

pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 1-8
    address: 0x24

  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x22

when I try to compile, i receive the follow error: 
C:\Users\Daddy>esphome compile c:/esphome/luci2_eth1.yaml
INFO ESPHome 2024.10.0
INFO Reading configuration c:/esphome/luci2_eth1.yaml...
INFO Unable to import component type: No module named 'esphome.components.type'
Failed config

type: [source c:/esphome/luci2_eth1.yaml:8]

  Component not found: type.
  LAN8720

Someone knows how I can solve this prolem?

many thanks
Reply
#2
if you are using KC868-A2, you can use this link of ymal file directly to test:
https://www.kincony.com/forum/showthread.php?tid=2692
Reply
#3
(10-17-2024, 11:39 PM)admin Wrote: if you are using KC868-A2, you can use this link of ymal file directly to test:
https://www.kincony.com/forum/showthread.php?tid=2692

Code:
#include "esp_system.h"  // Include for esp_read_mac
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_eth.h"
#include "esp_netif.h"
#include "esp_eth_phy.h"
// Ethernet configuration macros
#define ETH_ADDR        0
#define ETH_POWER_PIN  -1  // Eğer PHY'nin güç pini kullanılmıyorsa -1 kalabilir
#define ETH_MDC_PIN    23
#define ETH_MDIO_PIN   18
#define ETH_TYPE       ETH_PHY_LAN8720
#define ETH_CLK_MODE   ETH_CLOCK_GPIO17_OUT  // GPIO17 RMII CLK olarak yapılandırıldı
#define TAG            "ETHERNET"
void init_ethernet(void)
{
    // Eğer ETH_POWER_PIN bir GPIO ise, bu kısmı düzenleyin
    if (ETH_POWER_PIN != -1) {
        gpio_pad_select_gpio(ETH_POWER_PIN);
        gpio_set_direction(ETH_POWER_PIN, GPIO_MODE_OUTPUT);
        gpio_set_level(ETH_POWER_PIN, 1);  // PHY'yi güçlendirin
        vTaskDelay(pdMS_TO_TICKS(10));     // Güç stabilizasyonu için gecikme
    }
    // Ethernet MAC ve PHY ayarları
    eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
    eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
    phy_config.phy_addr = ETH_ADDR;
    phy_config.reset_gpio_num = -1;  // Reset pini kullanılmıyorsa -1 kalabilir
    // MAC ve PHY nesnelerini oluştur
    esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
    esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
    // Ethernet sürücüsünü yapılandır
    esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
    esp_eth_handle_t eth_handle = NULL;
    esp_err_t ret = esp_eth_driver_install(&config, &eth_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Ethernet sürücüsü kurulamadı: %s", esp_err_to_name(ret));
        return;
    }
    // Ethernet'i TCP/IP yığınına bağla
    esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_ETH();
    esp_netif_t *eth_netif = esp_netif_new(&netif_config);
    if (esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)) != ESP_OK) {
        ESP_LOGE(TAG, "Ethernet netif bağlanamadı");
        return;
    }
    // Ethernet sürücüsünü başlat
    ret = esp_eth_start(eth_handle);
    if (ret != ESP_OK) {
        ESP_LOGE(TAG, "Ethernet başlatılamadı: %s", esp_err_to_name(ret));
        return;
    }
    // IP adresini alın ve loglayın
    esp_netif_ip_info_t ip_info;
    if (esp_netif_get_ip_info(eth_netif, &ip_info) == ESP_OK) {
        ESP_LOGI(TAG, "IP Adresi: " IPSTR, IP2STR(&ip_info.ip));
        ESP_LOGI(TAG, "Alt Ağ Maskesi: " IPSTR, IP2STR(&ip_info.netmask));
        ESP_LOGI(TAG, "Ağ Geçidi: " IPSTR, IP2STR(&ip_info.gw));
    } else {
        ESP_LOGE(TAG, "IP bilgisi alınamadı");
    }
    ESP_LOGI(TAG, "Ethernet başarıyla başlatıldı.");
}
void get_esp_mac_address(void)
{
    uint8_t mac_addr[6];
    esp_read_mac(mac_addr, ESP_MAC_ETH); // ESP32'nin Ethernet MAC adresini alın
    ESP_LOGI(TAG, "ESP32 MAC Adresi: %02x:%02x:%02x:%02x:%02x:%02x",
             mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
}
My IP address is 0000, I am using esp-idf4.3.1.How can I fix that?
Reply
#4
after you downloaded firmware, need re power on of your board.
Reply
#5
(7 hours ago)admin Wrote: after you downloaded firmware, need re power on of your board.

I did but it didnt work.
Reply


Forum Jump:


Users browsing this thread: