Closed jimmie11 closed 3 years ago
Those examples are written for ESP32/ESP8266 using ESPAsyncWebServer which is not supported by the EthernetWebServer Library.
You can convert the example to use synchronous (ESP8266)WebServer, then you can use them with this library. The syntax is very similar, such as
server.on("/", handleSomething);
Good Luck,
PS: Currently, the AsyncWebServer is ready only for ESP32/ESP8266 using ESPAsyncWebServer and STM32 using AsyncWebServer_STM32
Thank you but Server.on is what causes the compile error. How will using the same statement and changing the library to synchronous help?
You certainly have to first rewrite the examples to use (ESP8266)WebServer. That will modify the function call from asynch way
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
to synchronous way
server.on("/", handleSomething);
then port the modified examples to EthenetWebServer.
It's better to spend some more time to research the differences between Async and Sync examples.
This is the Async_HelloServer example written for AsyncWebServer_STM32 library
void setup(void)
{
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
Serial.println("\nStart Async_HelloServer on " + String(BOARD_NAME));
...
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
{
handleRoot(request);
});
server.on("/inline", [](AsyncWebServerRequest * request)
{
request->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)
{
}
and the similar HelloServer written for sync EthernetWebServer library
void setup(void)
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial);
Serial.print("\nStarting HelloServer on " + String(BOARD_TYPE));
Serial.println(" with " + String(SHIELD_TYPE));
Serial.println("EthernetWebServer Version " + String(ETHERNET_WEBSERVER_VERSION));
...
server.on(F("/"), handleRoot);
server.on(F("/inline"), []()
{
server.send(200, F("text/plain"), F("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();
}
A very nice and complete webserver example has been posted by David Bird at:
https://github.com/G6EJD/ESP-SMART-Thermostat
I am trying to convert that example to use your library with a Teensy 4.1 but getting a compile error for
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
Is there an equivalent to that statement?
Thank you.