How To Install Using Arduino Library Manager
This library currently supports
STM32 boards with built-in Ethernet such as :
- Nucleo-144 (F429ZI, F767ZI)
- Discovery (STM32F746G-DISCOVERY)
- All STM32 Boards with Built-in Ethernet, See How To Use Built-in Ethernet
- 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
- 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();
}