Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to use ethernet and wifi simultaneously by ESPHome
#1
Code:
esphome:
  name: a16v3
  friendly_name: A16v3 Dual Network Demo
  platformio_options:
    board_build.flash_mode: dio

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

logger:
  hardware_uart: USB_SERIAL_JTAG

api:

ota:
  - platform: esphome

# Both network interfaces work simultaneously.
# Ethernet is the preferred default network.
# WiFi is the automatic fallback network.
network:
  enable_ipv6: false
  priority:
    - ethernet
    - wifi

# WiFi configuration
wifi:
  ssid: "KinCony"
  password: "a12345678"
  power_save_mode: none

# W5500 Ethernet configuration
ethernet:
  id: eth
  type: W5500
  clk_pin: GPIO42
  mosi_pin: GPIO43
  miso_pin: GPIO44
  cs_pin: GPIO15
  interrupt_pin: GPIO2
  reset_pin: GPIO1

# I2C bus for SSD1306
i2c:
  id: bus_a
  sda: GPIO9
  scl: GPIO10
  scan: true
  frequency: 400kHz

# Read IP addresses from each interface independently
text_sensor:
  - platform: wifi_info
    ip_address:
      name: "WiFi IP Address"
      id: wifi_ip

  - platform: ethernet_info
    ip_address:
      name: "Ethernet IP Address"
      id: eth_ip

# OLED font
font:
  - file: "gfonts://Roboto"
    id: font_small
    size: 9

# SSD1306 OLED display
display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    address: 0x3C
    update_interval: 1s

    lambda: |-
      // Title
      it.printf(0, 0, id(font_small), "A16v3 Dual Network");

      // WiFi IP address
      const char *wifi_addr =
        id(wifi_ip).state.empty() ?
        "Connecting..." : id(wifi_ip).state.c_str();

      it.printf(0, 13, id(font_small),
                "WiFi: %s", wifi_addr);

      // Ethernet IP address
      const char *eth_addr =
        id(eth_ip).state.empty() ?
        "Connecting..." : id(eth_ip).state.c_str();

      it.printf(0, 26, id(font_small),
                "ETH : %s", eth_addr);

      // Show current default network
      if (id(eth).is_connected()) {
        it.printf(0, 39, id(font_small),
                  "DEFAULT: ETHERNET");
      } else if (!id(wifi_ip).state.empty() &&
                 id(wifi_ip).state != "0.0.0.0") {
        it.printf(0, 39, id(font_small),
                  "DEFAULT: WIFI");
      } else {
        it.printf(0, 39, id(font_small),
                  "DEFAULT: WAITING");
      }

      // Ethernet cable status
      it.printf(0, 52, id(font_small),
                "ETH LINK: %s",
                id(eth).is_connected() ? "UP" : "DOWN");
demo yaml download:

.txt   A16v3-Dual-Network-Demo-HA.txt (Size: 2.51 KB / Downloads: 1)
   
more details in ESPHome: https://esphome.io/components/network/#m...ce-support
Reply


Forum Jump:


Users browsing this thread: