HASwitchPlate / openHASP

HomeAutomation Switchplate based on lvgl for ESP32
https://www.openhasp.com
MIT License
703 stars 182 forks source link

Testing of Ethernet build with W5500 #381

Closed nagyrobi closed 7 months ago

nagyrobi commented 2 years ago

Perform all steps below and tick them with [x]

Describe the bug

Using Ben Suffolk's Ethernet base with a Lanbon L8 rev 1.17 (originally shipped with an AU dimmer base), the following behavior is observed (v0.6.4-dev_7f4e079):

To Reproduce

Built locally by uncommenting lanbon_l8_eth in platformio_override.ini.

Expected behavior

N/A

Screenshots or video

N/A

fvanroie commented 2 years ago

with Ethernet it connects with the same MAC as with the WiFi? Surprising.

The W5500 doesn't have an assigned MAC-address, so in this implementation it was opted to re-use the WiFi MAC address. It is possible to change to esp_read_mac(mac, ESP_MAC_ETH) instead, if this is required.

it's really slow

Most of the issues seem to revolve around the speed of the interface. I noticed by default the ETHSPI is run at 12MHz by default. The W5500 chip supports up to 80MHz and so does the ESP32. Try adding ETHSPI_CLOCK_MHZ to the config and set it incrementally to 20, 40, 60 or 80 (unit is MHz so don't go beyond 80).

See if this improves screenshot performance, Web UI issues and/or Ping replies.

%ip% variable is not populated when node boots on the messagebox. Would be nice to have it like it was in the WiFi times.

This is not implemented at the moment. Currently %ip% and %ssid% are only available when using WiFi.

nagyrobi commented 2 years ago

I've set ETHSPI_CLOCK_MHZ to 80, plate boots but does not connect at all. Brick...

fvanroie commented 2 years ago

How about 20, 40, 60 MHz? Or multiples of 12 Mhz.

nagyrobi commented 2 years ago

I'll try in the week-end.

fvanroie commented 1 year ago

Does this issue still apply?

nagyrobi commented 1 year ago

Well, unfortunately it still does, no real success achieved. Still very slow, far from usable.

fvanroie commented 1 year ago

Thanks. Since this is user contributed code, I'll leave it to @bensuffolk to give some pointers here. I'm currently busy with S3 and Arduino_GFX integration, so this will be low priority at this time.

bensuffolk commented 1 year ago

Sorry, been a bit busy with other things, but am hoping to spent some time in the Christmas holidays back on this project.

I have a feeling I had a play around with different value for the spi speed and had issues with it running faster than 12. But everything seems ok for me at that speed. The only thing not working for me is the file viewer but I expect that’s a not enabled type thing I need to look at.

I will look over it all though and comment / make changes as needed shortly

fvanroie commented 1 year ago

Well, unfortunately it still does, no real success achieved. Still very slow, far from usable.

From this information, it seems W5500 on ESP32 is limited to ~10Mbit/s. Maybe it's possible to benchmark the speed with a sketch so there is actual data to compare. From what I gather, other chips provide better throughput but can pose other limitations (more pins, bigger physical size, etc).

A perfect solution seems hard to find.

nagyrobi commented 1 year ago

10Mbit/s is more than enough for IoT applications in 99% of the cases. W5500 has the big advantage that it requires less pins, and it's bus can be shared with other peripherals - which is a big advantage on high I/O pin number applications, which seem to be quite often.

bensuffolk commented 1 year ago

I have another project which uses W5500 and ESP32 -WROVER-E and I did some testing (so I can see debug output etc, which I can't get on the lanbon).

I can get the ETHSPI_CLOCK_MHZ up to 32 without causing timeout errors, but after that it always errors.

I have not yet tried to up the speed on the lanbon module, but you can clearly not get anywhere near 80.

fantasmisiciliani commented 1 year ago

I built the 0.7.0-rc2 (until 3ab88a3) for my WT32-SC01 Plus with a W5500 Lite and I don't have any of the mentioned issues, except the unpopulated %ip% variable. Tested only at 32Mhz. I will do some further test with higher frequencies and report here.

I soldered a small LDO board to the W5500 Lite and connected it to the 5V pin of the I/O connector to get 3.3V.

SPI2_HOST default pins are exposed in the I/O onboard connector, so no need of the GPIO Matrix, but I had to modify SPI pin definitions according to the ESP32-S3 pinout.

Because of some difference in the Arduino framework between the ESP32 and the ESP32-S3, I had to define CONFIG_ETH_SPI_ETHERNET_W5500 and add the following files from the ESP-IDF v4.4 to compile successfully: esp_eth_mac_w5500.c, esp_eth_phy_w5500.c, w5500.h

I also added a static IP configuration in src/sys/net/hasp_ethernet_esp32.cpp. Setting no gateway (0.0.0.0), the console doesn't show the ethernet interface's info and the web server doesn't start, but MQTT works. Is it mandatory?

My build flags become:

    ${wt32-sc01-plus.build_flags}
    -D HASP_USE_WIFI=0
    -D HASP_USE_ETHERNET=1
    -D HASP_USE_ETHSPI=1
    -D CONFIG_ETH_SPI_ETHERNET_W5500=1
    -D ETHSPI_MOSI_GPIO=11
    -D ETHSPI_MISO_GPIO=13
    -D ETHSPI_SCLK_GPIO=12
    -D ETHSPI_INT_GPIO=14
    -D ETHSPI_CS_GPIO=10
    -D ETHSPI_CLOCK_MHZ=32
    -D ETHSPI_IP=192,168,117,45
    -D ETHSPI_GW=192,168,117,1

@fvanroie @bensuffolk would you fix ETHSPI for the S3 and add a static IP configuration? I modified void ethernetSetup() as the following, but I'm not a developer:

void ethernetSetup()
{
#if HASP_USE_WIFI == 0
    // Need to make sure we get the Ethernet Events
    WiFi.begin();
    WiFi.mode(WIFI_OFF);
#endif

    WiFi.onEvent(EthernetEvent);
#if HASP_USE_ETHSPI > 0

    if(HASP_ETHERNET.begin(ETHSPI_MOSI_GPIO, ETHSPI_MISO_GPIO, ETHSPI_SCLK_GPIO, ETHSPI_CS_GPIO, ETHSPI_INT_GPIO,
                                  ETHSPI_HOST)) LOG_TRACE(TAG_ETH, F("ETHSPI Started "));

// Setting a static IP if defined. If the other parameters are missing, we set them to default values
#ifdef ETHSPI_IP
    IPAddress ip(ETHSPI_IP);
#ifdef ETHSPI_GW
    IPAddress gw(ETHSPI_GW);
#else
    IPAddress gw(0, 0, 0, 0);
#endif
#ifdef ETHSPI_NETMASK
    IPAddress subnet(ETHSPI_NETMASK);
#else
    IPAddress subnet(255, 255, 255, 0);
#endif
#ifdef ETHSPI_DNS1
    IPAddress dns1(ETHSPI_DNS1);
#else
    IPAddress dns1(0, 0, 0, 0);
#endif
#ifdef ETHSPI_DNS2
    IPAddress dns2(ETHSPI_DNS2);
#else
    IPAddress dns2(0, 0, 0, 0);
#endif
//  it fails without a 3s delay
    delay(3000);
    if(HASP_ETHERNET.config(ip, gw, subnet, dns1, dns2)) 
        LOG_INFO(TAG_ETH, "Successfully assigned static IP to SPI Ethernet.");
    else
        LOG_INFO(TAG_ETH, "Failed to set static IP for SPI Ethernet.");
#endif // ETHSPI_IP

#else
    if(HASP_ETHERNET.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLKMODE))
                                  LOG_TRACE(TAG_ETH, F("ETH Started "));
#endif

}
fantasmisiciliani commented 1 year ago

Further test on my WT32-SC01 Plus with W5500 Lite, openHASP 0.7.0-rc4 with mods as above and Arduino framework v2.7.0 (because v2.8.0 included in last Tasmota's platform causes errors in LovyanGFX lib): no problem up to 60Mhz, all works as expected. Starting from 62Mhz the MQTT client doesn't connect and I can't reach/ping the device. Download speeds with a 6 MB file: