This library v1.0.0 currently supports
- STM32 boards with built-in Ethernet LAN8742A such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- STM32 boards (with 64+K Flash) running EMC28J60 shields
This is simple yet complete WebServer library for STM32
boards running built-in Ethernet LAN8742A (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
- HTTP Server and Client
- HTTP GET and POST requests, provides argument parsing, handles one client at a time.
Library is based on and modified from:
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:
This is the HelloServer
/*
* Currently support
* 1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
* - Nucleo-144 (F429ZI, F767ZI)
* - Discovery (STM32F746G-DISCOVERY)
* - All STM32 Boards with Built-in Ethernet, See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
* 2) STM32 boards (with 64+K Flash) running EMC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
* 3) STM32 boards (with 32+K Flash) running W5x00 Ethernet shields
*
*/
#define USE_BUILTIN_ETHERNET false //true
// If don't use USE_BUILTIN_ETHERNET, and USE_UIP_ETHERNET => use W5x00 with Ethernet library
#define USE_UIP_ETHERNET false
#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();
}
Update Feb 28th 2020
New in Version v1.0.1
- Add support to W5x00 Ethernet shields to all STM32 boards having 64+K bytes Flash.
Updated: Mar 2nd 2020
EthernetWebServer_STM32 libraries v1.0.1
just got included into Arduino Library Manager.
Now you can install this library directly from Arduino Library Manager
Updated: Mar 6th 2020
New in Version v1.0.2
- Remove dependency on
Functional-VLPP library
. - Enhance examples and update README.md