EthernetWebServer for ESP8266/ESP32, Mega, Teensy, SAM DUE, SAMD21, SAMD51, nRF52 boards with Ethernet W5X00, ENC28J60 shields

This is simple yet complete WebServer library for AVR, Teensy, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32.

The library supports

  1. HTTP Server and Client
  2. HTTP GET and POST requests, provides argument parsing, handles one client at a time.

Library is based on and modified from:

  1. Ivan Grokhotkov’s ESP8266WebServer

The EthernetWebServer class found in EthernetWebServer.h header, is a simple web server that knows how to handle HTTP requests such as GET and POST and can only support one simultaneous client.

There currently are 6 examples:

  1. HelloServer
  2. HelloServer2
  3. AdvancedWebServer
  4. HttpBasicAuth
  5. PostServer
  6. SimpleAuthentication

This is the HelloServer

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetWebServer.h>

#ifdef CORE_TEENSY
  // For Teensy 4.0
  #if defined(__IMXRT1062__)
  #define BOARD_TYPE      "TEENSY 4.0"
  #elif ( defined(__MKL26Z64__) || defined(ARDUINO_ARCH_AVR) )
  #define BOARD_TYPE      "TEENSY LC or 2.0"
  #else
  #define BOARD_TYPE      "TEENSY 3.X"
  #endif
#else
// For Mega
#define BOARD_TYPE      "AVR Mega"
#endif

// Enter a MAC address and IP address for your controller below.

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

// Select the IP address according to your local network
IPAddress ip(192, 168, 2, 100);

EthernetWebServer server(80);

const int led = 13;

void handleRoot() 
{
  server.send(200, "text/plain", "Hello from EthernetWebServer");
}

void handleNotFound()
{
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++)
  {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void)
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  delay(1000);
  Serial.println("\nStarting HelloServer on " + String(BOARD_TYPE));

  // start the ethernet connection and the server:
  Ethernet.begin(mac, ip);

  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "This works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();

  Serial.print(F("HTTP EthernetWebServer is @ IP : "));
  Serial.println(Ethernet.localIP());
}

void loop(void)
{
  server.handleClient();
}

Update Feb 17th 2020

EthernetWebServer libraries v1.0.0 just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager.

Update Feb 17th 2020

Version v1.0.1

  1. Add support to Server’s lambda function calls with dependency on Functional-VLPP library

Update Feb 20th 2020

Version v1.0.2

  1. From v1.0.2+, the library supports many more Arduino boards (Atmel AVR-s, Atmel SAM3X8E ARM Cortex-M3, STM32F series, ESP8266, Intel ARC32(Genuino101), Nordic nRF51(RFduino), Teensy boards, Realtek Ameba(RTL8195A,RTL8710))
  2. Support Wiznet W5x00 or ENC28J60 EThernet shields by using UIPEthernet library besides standard Ethernet, Ethernet2, Ethernet3 libraries.

Update Feb 23rd 2020

Version v1.0.3

1.From v1.0.3+, the library supports more Arduino boards ( SAM DUE, SAMD: ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.)

1 Like

Update May 13th 2020

Many more releases from last update:

New in v1.0.8

  1. Fix W5x00 support for ESP8266 boards.

New in v1.0.7

  1. Add ENC28J60 support to ESP32 and ESP8266 boards.

New in v1.0.6

  1. Add W5x00 support to ESP32 and ESP8266 boards.

New in v1.0.5

  1. Add support to nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B30_ublox, etc.
  2. Support any future custom Ethernet library that meets the no-compiling-error requirements. Currently Ethernet2, EThernet3, EthernetLarge libraries are supported. Ethernet_Shield_W5200, EtherCard, EtherSia libraries are not supported.

New in v1.0.4

  1. Add support to SAM51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, etc.).

Update Sept 15th 2020

Many more releases from last update:

New in v1.0.12

  1. Add support to new EthernetENC library for ENC28J60.
  2. Add debug feature. Clean up code.

New in v1.0.11

  1. Add support to Seeeduino SAMD21/SAMD51 boards (LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, etc.)
  2. Add and restructure examples.

New in v1.0.10

  1. Fix bug not closing client and releasing socket.
  2. Merge new features from latest ESP8266WebServer
  3. Add and enhance examples.

New in v1.0.9

  1. Add EthernetWrapper.h for easier W5x00 support as well as more Ethernet libs in the future.
  2. Add default SS/CS pin for ESP8266 and ESP32
  3. Increase default clock speed for W5x00 in Ethernet, and EthernetLarge libraries to 25MHz from 14MHz. Tested OK on W5100 as well as W5500.

Updated Jan 13th 2021

Releases v1.2.1

  1. Clean-up all compiler warnings possible.
  2. Add Table of Contents
  3. Add examples
  4. Modify Version String

Releases v1.2.0

  1. Add support to NativeEthernet Library for Teensy 4.1
  2. Add Version String.

Major Releases v1.1.0

  1. Add high-level HTTP and WebSockets Client by merging ArduinoHttpClient Library
  2. Add many more examples for HTTP and WebSockets Client.

Releases v1.0.13

  1. Add support to PROGMEM-related commands, such as sendContent_P() and send_P()
  2. Update Platform.ini to support PlatformIO 5.x owner-based dependency declaration.
  3. Clean up code.
  4. Update examples.