I am trying to get the Ethernet Featherwing with the w5500 chip to act as a EthernetServer.
If you try to use the official Arduino Ethernet library you will get an error that the EthernetServer has a pure virtual function.
The product page: https://www.adafruit.com/product/3201 does state that "Server is not supported at this time" but that was probably years ago so I wanted to inquire if anyone got this working.
It isn't clear to me what the problem is though, since the regular Arduino Ethernet shield (https://store-usa.arduino.cc/products/a ... edStore=us) uses the same chip and I can get that working as a server fine.
EthernetClient instances can be created fine.
Do any third party libraries enable the use of the EthernetServer class with this feather?
I see others with similar questions from some time ago:
Ethernet Featherwing
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- avsteele
- Posts: 7
- Joined: Thu Sep 01, 2022 4:46 pm
Re: Ethernet Featherwing
I have a solution that enables the use of the Ethernet FeatherWing as a server!
Steps:
Then the example code below will work. If you follow the above steps you should be able to ping the server, and it should respond to HTTP requests from a browser or curl. The only other wing you may need to modify are the pin #'s, use the comments in the code to guide you.
This code was modified from one of the examples in the repository
- I am using VS Code as the editor
- I am using the Platform IO (PIO below) extension to manage the project and dependencies
- I am using a third party library in the PIO library registry called "WebServer_ESP32_W5500" (repository here: https://github.com/khoih-prog/WebServer_ESP32_W5500/)
Steps:
- Open VS Code
- in PIO create a new project. Select whichever ESP32 board you are using. (creating the project takes a while)
- In the project, to to libraries and search for "WebServer ESP32 W5500" add the one called "WebServer_ESP32_W5500". If you are using a feather with a ESP32 S2,C2 instead add the library "WebServer_ESP32_SC_W5500"
- modify one file in the library as indicated below
- wire the FeatherWing IRQ pad to one of the ESP32 GPIO pins (your choice, but I use GPIO4 below)
Code: Select all
// remove this line (line 71 on 3/21/23)
if ( esp_read_mac(mac_eth, ESP_MAC_ETH) == ESP_OK )
// replace it with
if ( W5500_Mac == nullptr)
This code was modified from one of the examples in the repository
Code: Select all
#include <Arduino.h>
#if !( defined(ESP32) )
#error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting.
#endif
// defined use for optional printing
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
//////////////////////////////////////////////////////////
/// OVERRIDES below confirmed working for:
/// Adafruit ESP32 Huzzah Feather v2 https://learn.adafruit.com/assets/112834
/// Ethernet FeatherWing https://learn.adafruit.com/adafruit-wiz5500-wiznet-ethernet-featherwing/pinouts
///
/// If you are using another chip, refer to its pin-out to set the
// SPI:
// default => seems to work
// #define ETH_SPI_HOST SPI3_HOST
// CLOCK:
// 25 (MHz) => fails (the software reset in library init times out).
// 14 => success
#define SPI_CLOCK_MHZ 14
// Wire the 'IRQ' of ethernet wing to GPIO # below
// (this may not be required, i did it before other problem were fixed)
#define INT_GPIO 4
// for pins ESP32 Huzzuh https://learn.adafruit.com/assets/112834
#define MISO_GPIO 21
#define MOSI_GPIO 19
#define SCK_GPIO 5
#define CS_GPIO 33
//////////////////////////////////////////////////////////
#include <WebServer_ESP32_W5500.h>
// WE are not using Wifi, but this is still correct
WiFiServer server(80);
// use the mac provided when you purchased your chip
byte mac[] = { 0x98, 0x76, 0xB6, 0x12, 0x0E, 0xD3 };
const bool USE_DHCP = true;
// number of requests received
int reqCount = 0;
void setup()
{
Serial.begin(115200);
while (!Serial && (millis() < 5000));
Serial.print(F("\nStart WebServer on "));
Serial.print(ARDUINO_BOARD);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(WEBSERVER_ESP32_W5500_VERSION);
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST);
ET_LOGWARN1(F("MOSI:"), MOSI_GPIO);
ET_LOGWARN1(F("MISO:"), MISO_GPIO);
ET_LOGWARN1(F("SCK:"), SCK_GPIO);
ET_LOGWARN1(F("CS:"), CS_GPIO);
ET_LOGWARN1(F("INT:"), INT_GPIO);
ET_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
ET_LOGWARN(F("========================="));
///////////////////////////////////
// To be called before ETH.begin()
ESP32_W5500_onEvent();
// set mac and pins
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac );
ET_LOGINFO("Init OK.");
if(USE_DHCP)
{
ET_LOGINFO("using DHCP");
}
else
{
IPAddress myIP(192, 168, 25, 232);
IPAddress myGW(192, 168, 25, 1);
IPAddress mySN(255, 255, 255, 0);
// (optional?) Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);
ETH.config(myIP, myGW, mySN, myDNS);
ET_LOGINFO("static ip config OK.");
}
ESP32_W5500_waitForConnect();
ET_LOGINFO("Wait for connect OK.");
// start the web server (port 80 is default)
server.begin();
ET_LOGINFO("Server Started.");
ET_LOGINFO("End of setup.");
}
void loop()
{
// listen for incoming clients
WiFiClient client = server.available();
if (client)
{
Serial.println(F("New client"));
// an http request ends with a blank line
bool currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
Serial.println(F("Sending response"));
// send a standard http response header
// use \r\n instead of many println statements to speedup data send
client.print(
"HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n" // the connection will be closed after completion of the response
"Refresh: 20\r\n" // refresh the page automatically every 20 sec
"\r\n");
client.print("<!DOCTYPE HTML>\r\n");
client.print("<html>\r\n");
client.print(String("<h2>Hello World from ") + BOARD_NAME + "!</h2>\r\n");
client.print("Requests received: ");
client.print(++reqCount);
client.print("<br>\r\n");
client.print("<br>\r\n");
client.print("</html>\r\n");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(10);
// close the connection:
client.stop();
Serial.println(F("Client disconnected"));
}
}
- avsteele
- Posts: 7
- Joined: Thu Sep 01, 2022 4:46 pm
Re: Ethernet Featherwing
Actually there is an even easier way.
The official Ethernet library can be made to work with this wing, you just need to change one line in Ethernet.h apparently.
See: https://forum.arduino.cc/t/ethernet-h-l ... /1052950/8
After this the normal web server example works (don't forget to set the CS pin correctly (33 for ESP32 v2 w/ ethernet feather, this is already noted in the example)
The official Ethernet library can be made to work with this wing, you just need to change one line in Ethernet.h apparently.
Code: Select all
class EthernetServer : public Server {
//…to…
class EthernetServer : public Print {
After this the normal web server example works (don't forget to set the CS pin correctly (33 for ESP32 v2 w/ ethernet feather, this is already noted in the example)
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Ethernet Featherwing
Good information.. thanks for posting the solution and the follow-up!
Please be positive and constructive with your questions and comments.