esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

Ethernet Component not working with W5500 #5781

Open AndySymons opened 5 months ago

AndySymons commented 5 months ago

The problem

I am trying to configure an AZDelivery W5500 Ethernet module.

Screenshot 2024-05-19 at 12 14 23

The configuration yaml compiles and loads correctly, but after that all requests are timed out. Attempts to reinstall the code over ethernet, or to access the module from a browser also give timeout errors.

Which version of ESPHome has the issue?

2024.4.1

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

core-2024.5.3, but I did not get as far as connecting to Home Assistant via Ethernet. It works fine when connected by WiFi.

What platform are you using?

Debian Linux (running natively)

Board

Espressif Devkit v4 AZDelivery W5500 Ethernet module

Component causing the issue

Ethernet W5500 SPI

Example YAML snippet

esphome:
  name: hardwired-alarm-interface
  friendly_name: Hardwired Alarm Interface

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "BKVgvPgWeTB9FUDehvoT8JWCH/iEcpIDnG4hGd6OACY="

ota:
  password: "1e78adf2c5aa91872a69e7594a033450"

ethernet:
  type: W5500
  cs_pin: 18
  clk_pin: 19
  mosi_pin: 21
  miso_pin: 23
  reset_pin: 22
  interrupt_pin: 36

  manual_ip:
    static_ip: 192.168.0.42
    gateway: 192.168.0.1
    subnet: 255.255.255.0

Anything in the logs that might be useful for us?

[10:11:46]ets Jul 29 2019 12:21:46
[10:11:46]
[10:11:46]rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[10:11:46]configsip: 0, SPIWP:0xee
[10:11:46]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[10:11:46]mode:DIO, clock div:2
[10:11:46]load:0x3fff0030,len:1184
[10:11:46]load:0x40078000,len:13132
[10:11:46]load:0x40080400,len:3036
[10:11:46]entry 0x400805e4
[10:11:46][I][logger:158]: Log initialized
[10:11:46][C][ota:483]: There have been 0 suspected unsuccessful boot attempts.
[10:11:46][D][esp32.preferences:114]: Saving 1 preferences to flash...
[10:11:46][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[10:11:46][I][app:029]: Running through setup()...
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL1': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL2': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL3': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL4': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL5': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL6': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL7': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control CCL8': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control Global AT': Sending initial state ON
[10:11:46][D][binary_sensor:034]: 'Hardwired Alarm Control Sounder TA': Sending initial state ON
[10:11:46][C][switch.gpio:011]: Setting up GPIO Switch 'Hardwired Alarm Control Output 1'...
[10:11:46][D][switch:016]: 'Hardwired Alarm Control Output 1' Turning OFF.
[10:11:46][D][switch:055]: 'Hardwired Alarm Control Output 1': Sending state OFF
[10:11:46][D][switch:016]: 'Hardwired Alarm Control Output 1' Turning OFF.
[10:11:46][C][switch.gpio:011]: Setting up GPIO Switch 'Hardwired Alarm Control Output 2'...
[10:11:46][D][switch:016]: 'Hardwired Alarm Control Output 2' Turning OFF.
[10:11:46][D][switch:055]: 'Hardwired Alarm Control Output 2': Sending state OFF
[10:11:46][D][switch:016]: 'Hardwired Alarm Control Output 2' Turning OFF.
[10:11:46][C][ethernet:034]: Setting up Ethernet...
[10:11:46][I][ethernet:220]: Starting ethernet connection
[10:11:46][W][component:157]: Component ethernet set Warning flag: unspecified
[10:11:46][D][esp-idf:000]: E (1591) w5500.mac: w5500_send_command(123): send command timeout

[10:11:46][D][esp-idf:000]: E (1591) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

[10:11:46][D][esp-idf:000]: E (1704) w5500.mac: w5500_send_command(123): send command timeout

[10:11:46][D][esp-idf:000]: E (1704) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

[10:11:46][I][ethernet:231]: Connected via Ethernet!
[10:11:46][C][ethernet:467]:   IP Address: 192.168.0.42
[10:11:46][C][ethernet:468]:   Hostname: 'hardwired-alarm-control'
[10:11:46][C][ethernet:469]:   Subnet: 255.255.255.0
[10:11:46][C][ethernet:470]:   Gateway: 192.168.0.1
[10:11:46][C][ethernet:475]:   DNS1: 0.0.0.0
[10:11:46][C][ethernet:476]:   DNS2: 0.0.0.0
[10:11:46][C][ethernet:493]:   MAC Address: E0:5A:1B:76:61:A3
[10:11:46][C][ethernet:498]:   Is Full Duplex: YES
[10:11:46][C][ethernet:503]:   Link Speed: 10
[10:11:46][W][component:170]: Component ethernet cleared Warning flag
[10:11:46][C][ota:096]: Over-The-Air Updates:
[10:11:46][C][ota:097]:   Address: 192.168.0.42:3232
[10:11:46][C][ota:100]:   Using Password.
[10:11:46][C][ota:103]:   OTA version: 2.
[10:11:46][C][api:025]: Setting up Home Assistant API server...
[10:11:46][I][app:062]: setup() finished successfully!
[10:11:46][W][component:157]: Component api set Warning flag: unspecified
[10:11:46][I][app:100]: ESPHome version 2024.4.1 compiled on May  6 2024, 10:08:20
[10:11:46][C][logger:166]: Logger:
[10:11:46][C][logger:167]:   Level: DEBUG
[10:11:46][C][logger:169]:   Log Baud Rate: 115200
[10:11:46][C][logger:170]:   Hardware UART: UART0
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL1'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO32
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL2'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO33
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL3'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO25
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL4'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO26
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL5'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO27
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL6'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO14
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL7'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO13
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control CCL8'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO15
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control Global AT'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO4
[10:11:46][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Hardwired Alarm Control Sounder TA'
[10:11:46][C][gpio.binary_sensor:016]:   Pin: GPIO5
[10:11:46][C][switch.gpio:068]: GPIO Switch 'Hardwired Alarm Control Output 1'
[10:11:46][C][switch.gpio:091]:   Restore Mode: always OFF
[10:11:46][C][switch.gpio:031]:   Pin: GPIO17
[10:11:46][C][switch.gpio:068]: GPIO Switch 'Hardwired Alarm Control Output 2'
[10:11:46][C][switch.gpio:091]:   Restore Mode: always OFF
[10:11:46][C][switch.gpio:031]:   Pin: GPIO16
[10:11:46][C][ethernet:294]: Ethernet:
[10:11:46][C][ethernet:467]:   IP Address: 192.168.0.42
[10:11:46][C][ethernet:468]:   Hostname: 'hardwired-alarm-control'
[10:11:46][C][ethernet:469]:   Subnet: 255.255.255.0
[10:11:46][C][ethernet:470]:   Gateway: 192.168.0.1
[10:11:46][C][ethernet:475]:   DNS1: 0.0.0.0
[10:11:46][C][ethernet:476]:   DNS2: 0.0.0.0
[10:11:46][C][ethernet:493]:   MAC Address: E0:5A:1B:76:61:A3
[10:11:46][C][ethernet:498]:   Is Full Duplex: YES
[10:11:46][C][ethernet:503]:   Link Speed: 10
[10:11:46][C][ethernet:297]:   CLK Pin: 19
[10:11:46][C][ethernet:298]:   MISO Pin: 23
[10:11:46][C][ethernet:299]:   MOSI Pin: 21
[10:11:46][C][ethernet:300]:   CS Pin: 18
[10:11:46][C][ethernet:301]:   IRQ Pin: 36
[10:11:46][C][ethernet:302]:   Reset Pin: 22
[10:11:46][C][ethernet:303]:   Clock Speed: 26 MHz
[10:11:46][C][ethernet:312]:   Type: W5500
[10:11:46][C][mdns:115]: mDNS:
[10:11:46][C][mdns:116]:   Hostname: hardwired-alarm-control
[10:11:46][C][ota:096]: Over-The-Air Updates:
[10:11:46][C][ota:097]:   Address: 192.168.0.42:3232
[10:11:46][C][ota:100]:   Using Password.
[10:11:46][C][ota:103]:   OTA version: 2.
[10:11:46][C][api:139]: API Server:
[10:11:46][C][api:140]:   Address: 192.168.0.42:6053
[10:11:46][C][api:142]:   Using noise encryption: YES
[10:11:46][D][esp-idf:000]: E (3070) w5500.mac: w5500_send_command(123): send command timeout

[10:11:46][D][esp-idf:000]: E (3070) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

[10:11:46][D][esp-idf:000]: E (4271) w5500.mac: w5500_send_command(123): send command timeout

[10:11:46][D][esp-idf:000]: E (4271) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

[10:11:52][D][esp-idf:000]: E (22658) w5500.mac: w5500_send_command(123): send command timeout

[10:11:52][D][esp-idf:000]: E (22658) w5500.mac: emac_w5500_receive(578): issue RECV command failed

[10:12:31][D][esp-idf:000]: E (61484) w5500.mac: w5500_send_command(123): send command timeout

[10:12:31][D][esp-idf:000]: E (61484) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

Additional information

During set-up I observed the following. I do not know if these are connected issues or just documentation errors.

AndySymons commented 5 months ago

I am sorry that no one has responded to this issue yet :-(

Shooting in the dark, but in an attempt to narrow down the main issue, I did several more tests and recorded the log files, which are attached.

Initial state

As in my original posting…

Test 1

I removed the definition of the interrupt pin, wondering if it is necessary because the ESPHome documentation says it is optional and the AZ-Delivery example with Arduino does not use it. Result: no new errors. Same errors as the initial state. Conclusion: not sure. Maybe there is a default? Still need to actually cut the wire (test 3).

Test 2

I removed the definition of the reset pin, wondering if it is necessary because the ESPHome documentation says it is optional, although the AZ-Delivery example with Arduino does use it. Result: ‘reset’ errors and could not load the program at all. Conclusion: reset is mandatory.

Test 3

I restored the reset pin, and physically cut the wire to the interrupt pin because the ESPHome documentation says it is optional and the AZ-Delivery example with Arduino does not use it.
(It is till not defined in the config since test 1).
Result: still fails but gives different errors [Ethernet: 237] Conclusion: inconclusive, but these errors look more serious (?), so I will continue to assume for now that the interrupt pin is mandatory.

Test 4

I restored the config to the initial state, i.e. all six pins physically connected and configured, no manual IP and default clock frequency. I ran it to get a fresh log of the errors. There are many, and it is hard to see which is the most fundamental error and which are knock-on errors. I checked by doing a manual reset after the initial load but that made no difference -- same errors again.

Test 5

I previously had the impression that the device connected better when a manual IP was specified. I tried specifying a manual IP, but it made no difference this time. The errors are the same. I therefore withdrew the manual IP again.

Test 6

I previously noted that the clock speed cannot be set to 80MHz. I verified that by putting it in the config, installing it and keeping the log file. I withdrew the clock_speed entry from the config.

CONCLUSIONS SO FAR

  1. The need for an interrupt pin is unclear. Leaving it out seems to create more serious errors, but it needs to be re-tested when a situation is reached when no other errors are being reported. In the meantime, I note that the ESPHome documentation could be clearer about the use for this pin and the consequences of not connecting and/or defining it.
  2. The reset pin is clearly important. Without reset, no program can be loaded. Perhaps there is an awkward way of manually resetting the board when necessary, but I did not pursue that. The ESPHome documentation should be much clearer on this point; ‘optional’ does not cover it!
  3. Manual IP is not necessary. I withdraw my previous comment that this appeared to be the case.
  4. The clock speed cannot be set to 80MHz. The ESPHome documentation is probably wrong about the default being 29.97MHz; the error log says “the driver always tries to find the closest frequency to your configuration”. If that is correct, setting the clock speed at all only makes sense if you want to slow it down for some reason!

NEXT STEPS?

I have cleared up some side issues, and eliminated some causes, but still not found the central problem. If no one has an answer, I would at least like some guidance on how to proceed with further diagnostics. It would help a lot if someone could tell me some more about what the error messages in the log mean. (I cannot find any list online). The following look like they may be important. They occur several times, with variations in the numbers in brackets (what do they mean?). In all cases except the removal of reset, the configuration was successfully compiled and uploaded. The error messages occur after the line ‘[C][ethernet:034]: Setting up Ethernet…’.

[D][esp-idf:000]: E (679) w5500.mac: w5500_send_command(123): send command timeout [D][esp-idf:000]: E (680) w5500.mac: emac_w5500_start(279): issue OPEN command failed [D][esp-idf:000]: E (690) w5500.mac: emac_w5500_set_link(422): w5500 start failed [D][esp-idf:000]: E (700) esp_eth: eth_on_state_changed(121): ethernet mac set link failed [D][esp-idf:000]: E (711) w5500.phy: w5500_update_link_duplex_speed(84): change link failed [D][esp-idf:000]: E (721) w5500.phy: w5500_get_link(108): update link duplex speed failed [D][esp-idf:000]: E (721) esp_eth: esp_eth_start(272): phy get link status failed [D][esp-idf:000]: E (2517) w5500.mac: emac_w5500_transmit(534): issue SEND command failed

So the problem is presumably somewhere in the Ethernet setup. But where?? I would very much appreciate any help an expert may be able to give to determine whether there is a bug in the ESPHome code or something I can do differently in the config.

Attachments

240513 0850 test 2 log - error when RST not defined.txt 240513 0901 test 3 log - error after INT wire snipped.txt 240513 0913 test 4 log - INT restored (back to original).txt 240513 0924 test 5 log - manual IP added (no difference).txt 240513 0939 test 6 log - clock speed set to 80MHz.txt

AndySymons commented 5 months ago

19 May. I tried a different W5500 component, the USR-E1 (a nice little module), this time with an ESP32-S2, and got the same result -- the program compiles and loads, the device has an IP address, but it does not respond to Ethernet signals.

Screenshot 2024-05-19 at 12 09 07

This therefore seems to be a general problem with the ESPHome Ethernet Component for W5500.

I guess either there is something missing in the libraries, or in the documentation? This is a shame because W5500 is a widely-used platform in quite cheap products.

BTW, between my original posting and this one, I got a WT32-EH01 board working with no problem at all. The Ethernet Component is great when it works!

My failed W5500 config below, and log file attached ...

esphome:
  name: hardware-alarm-interface-3
  friendly_name: Hardware Alarm Interface 3

esp32:
  board: esp32-s2-saola-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "o6O/pTaTUYUGrab9xftGr46QnvFTVvXvkpaj0UeGBN8="

ota:
  password: "73e414cd91ef846e8c757e5f02ce39d6"

ethernet:
  type: W5500
  reset_pin: GPIO8
  interrupt_pin: GPIO9
  cs_pin: GPIO10
  mosi_pin: GPIO11
  clk_pin: GPIO12
  miso_pin: GPIO13

logs_hardware-alarm-interface-3_run.txt

nagyrobi commented 5 months ago

Please contact us on the Discord channel linking to this isdue.

AndySymons commented 4 months ago

Done

nagyrobi commented 4 months ago

Works now for you?

AndySymons commented 4 months ago

Why? Has there been a fix? What version of the code do I need?

AndySymons commented 4 months ago

It looks like I accidentally closed "Update ethernet.rst #3846". I suspect that was due to inexperience in using Github? In any case my proposed document change was only to say the W5500 is not working at the moment.

I have recently got a different W5500 module working -- the USR-ES1. I will retest soon with the AZDelivery W5500 board and close this issue if it works.

dominik4545 commented 4 months ago

@AndySymons: I am thinking also to buy the module for my project. Did you get it working meanwhile?

AndySymons commented 1 month ago

I used a different solution for my project, but will re-test the AZDelivery board when I get the opportunity. The problem may be more related to the fact that I was using an ESP32-S2 processor than the AZDelivery board itself?