EthernetWebServer for STM32F/L/H/G/WB/MP1 boards using Ethernet built-in LAN8742A, LAN8720 or W5x00, ENC28J60 Ethernet

Working libraries, libraries being ported and related hardware
Post Reply
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

EthernetWebServer for STM32F/L/H/G/WB/MP1 boards using Ethernet built-in LAN8742A, LAN8720 or W5x00, ENC28J60 Ethernet

Post by khoih-prog »

EthernetWebServer_STM32 library


How To Install Using Arduino Library Manager

This library currently supports

STM32 boards with built-in Ethernet such as : STM32 boards (with 64+K Flash) running EMC28J60 shields
  • Nucleo-144
  • Nucleo-64
  • Discovery
  • STM32MP1
  • Generic STM32F1 (with 64+K Flash): C8 and up
  • Generic STM32F4
  • STM32L0
  • LoRa boards
  • 3-D printer boards
  • Generic Flight Controllers
  • Midatronics boards
and these boards are not supported:
  • Nucleo-32 (small Flash/memory)
  • Eval (no Serial, just need to redefine in sketch, library and UIPEthernet)
  • Generic STM32F0 (small Flash/memory)
  • Generic STM32F1 (with <64K Flash): C6
  • Generic STM32F3 : no HardwareSPI.h
  • Electronics Speed Controllers (small Flash/memory)

This is simple yet complete WebServer library for STM32 boards running built-in Ethernet (Nucleo-144, Discovery) or EMC28J60 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 :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.

Sample Code

Code: Select all

/*
 * Currently support 
 * 1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
 *    - Nucleo-144 (F429ZI, F767ZI)
 *    - Discovery (STM32F746G-DISCOVERY)
 * 2) STM32 boards (with 64+K Flash) running EMC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
 * 
 */

#define USE_BUILTIN_ETHERNET   false    //true

#include <EthernetWebServer_STM32.h>
  
// 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, 200);

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 Nucleo-144");

  // 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();
}
Last edited by khoih-prog on Sun Apr 11, 2021 5:39 pm, edited 5 times in total.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: EthernetWebServer for STM32 boards using Ethernet built-in or shields

Post by fpiSTM »

Thanks for sharing.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32 boards using Ethernet built-in or shields

Post by khoih-prog »

New in Version v1.0.1

1. Add support to popular W5x00 Ethernet shields to all STM32 boards having 64+K bytes Flash.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32 boards using Ethernet built-in LAN8742A or W5x00, ENC28J60 shields

Post by khoih-prog »

New in Version v1.0.2
1. Remove dependency on Functional-VLPP library
2. Enhance examples, fix indentation and update README.md
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32 boards using Ethernet built-in LAN8742A or W5x00, ENC28J60 Ethernet shields

Post by khoih-prog »

New in v1.0.3

1. Fix bug not closing client and releasing socket.
2. Merge new features from latest ESP8266WebServer
3. Add and enhance examples.
4. Add back dependency to Functional-VLPP library

Image
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32 boards using Ethernet built-in LAN8742A or W5x00, ENC28J60 Ethernet shields

Post by khoih-prog »

New in v1.0.4

1. Add support to all STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash.
- STM32L0, STM32L1, STM32L4
- STM32G0, STM32G4
- STM32H7
- STM32WB
- STM32MP1

AdvancedWebServer example running on Nucleo-64 NUCLEO-L053R8 and ENC28J60

Image
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32F/L/H/G/WB/MP1 boards using Ethernet built-in LAN8742A or W5x00, ENC28J60 Ethernet shield

Post by khoih-prog »

Major Release v1.0.5

1. Add support to new EthernetENC Library for ENC28J60.
2. Add support to Ethernet2, Ethernet3 and EthernetLarge libraries on top of Ethernet Library
2. Add debug feature. Clean up code. Restructure examples.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

Re: EthernetWebServer for STM32F/L/H/G/WB/MP1 boards using Ethernet built-in LAN8742A or W5x00, ENC28J60 Ethernet shield

Post by khoih-prog »

Major Release 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.

Release v1.0.6

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.
khoih-prog
Posts: 102
Joined: Thu Feb 27, 2020 7:54 am
Location: Toronto

EthernetWebServer for STM32F/L/H/G/WB/MP1 boards using Ethernet built-in LAN8742A, LAN8720 or W5x00, ENC28J60 Ethernet

Post by khoih-prog »

Releases v1.2.0

1. Add support to LAN8720 Ethernet for many STM32F4 (F407xx, NUCLEO_F429ZI) and STM32F7 (DISCO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG) boards.
2. Add LAN8720 examples
3. Add Packages' Patches for STM32 to use LAN8720 with STM32Ethernet and LwIP libraries


Image

Releases v1.1.1

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

Return to “Libraries & Hardware”