What http server for the ESP32 ?

I have a project that works on the ESP8266 which I am trying to port to the ESP32. On the ESP8266 one simply uses ESP8266Webserver or ESP8266WebserverSecure to provide a HTTP or HTTPS interface to the user. Having looked at the ESP32, the picture seems much less clear.

For example, there is something called AsyncWebserver which does not appear to have a 'secure' counterpart. There is also the Frank Hessel ESP_HTTPS_server which initial tests seem to indicate is rather complex and slow and appears to have no simple mechanisms for some actions such as enumerating retuned parameters. In addition, when I tried using that, I was getting a compiler complaining that WiFi.h is defined twice.

Is there an "official" webserver library for the ESP32 that I should be using?

Usually the difference between using ESP8266 versions and ESP32 versions is removing the ESP8266 part from the start of the library name.
Example…
#include <ESP8266Webserver.h>
would become…
#include <Webserver.h>

I have just got a Wemos D1 MINI ESP32 and it appears to work with the WIFI examples in the IDE. Certainly the SimpleWiFiServer example does what is expected of it but I have not tried anything else

Riva:
Usually the difference between using ESP8266 versions and ESP32 versions is removing the ESP8266 part from the start of the library name.
Example…
#include <ESP8266Webserver.h>
would become…
#include <Webserver.h>

Thank you! You have reduced my conversion effort to about 5mins worth of work!

If only that was documented somewhere in the espressif docs it would have been VERY helpful.

For some reason the ESP32 version of WiFi is missing some functions:

WiFi.softAPSSID()
WiFi.softAPPSK()
WiFi.setSleepMode()
WiFiServer.status()

So far I have not found any equivalents and will probably have to find a workaround forsoftAPSSID() and softAPPSK(). I’m not sure whether setSleepMode() is neccessary, but WiFiServer.status() was rather crucial. Its curious that the later version of the library for a later version of the hardware would be missing these?

Look at the ESP32 library:

WiFi.softAPSSID() = WiFi.SSID()
WiFi.softAPPSK() = WiFI.PSK()
WiFi.setSleepMode() = WiFi.setSleep()
WiFiServer.status() = **

** WiFiServer has a boolean operator which can be used to test if the server i listening:

if (WiFiServer() == true)
{
  //Listening
}

Danois, thanks for that.

Riva, works for Webserver but there seems to be no WebServerSecure.h. Bit strange really as the word does turn Red in the editor, but I get the following when I try to compile:

WebServerSecure.h: No such file or directory

BitSeeker: Riva, works for Webserver but there seems to be no WebServerSecure.h. Bit strange really as the word does turn Red in the editor, but I get the following when I try to compile:

WebServerSecure.h: No such file or directory

I'm not sure as I don't use servers on ESP but a google search yields this library for the ESP32. It may be worth checking if the HTTPS is already baked into the WebServer instead of using separate header file.

Riva:
I’m not sure as I don’t use servers on ESP but a google search yields this library for the ESP32. It may be worth checking if the HTTPS is already baked into the WebServer instead of using separate header file.

Thanks. Had a little play with it and it does look promising although very different and more complex to program than the built-in library. The built-in library would have been ideal as the coding is identical and with a few minor tweaks I could have had one codebase for both platforms. Using the Frank Hessel library will require a complete re-write, but at least its an option.

As already mentioned, I was puzzled by the fact that when I type in #include <WebServerSecure.h> it turns bold red as though it was a recognized module, but I then got a compiler error so compared the corresponding paths in the two libraries:

~/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/ESP8266WebServer

~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer

Among other things, this contains a file called keywords.txt. The ESP32 version contains as follows:

#######################################
# Datatypes (KEYWORD1)
#######################################

WebServer KEYWORD1
WebServerSecure KEYWORD1
HTTPMethod KEYWORD1

So as can be seen, the keyword ‘WebServerSecure’ is present. However, although the ESP8266 path contains ESP8266WebServerSecure.h and ESPWebServerSecure.cpp files, the ESP32 does NOT contain either a corresponding WebServerSecure.h or WebServerSecure.cpp file as perhaps might be expected. Having had a look at the ESP32 Git repository, I find the same.

Can anyone shed any light on this? Is this a file omission from the library, or was the secure version never implemented?

UPDATE:
Just to add that I found this via Google:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_https_server.html

It appears to relate to the Frank Hessel Library but does not explicitly give credit to that author, so is the Frank Hessel HTTPS library now built-into the ESP32 library? Is it now the de-facto HTTPS library for the ESP32? I see that the Hessel Library was updated from version 0.3.1 to 1.0.0 yesterday, so how long before these changes propagate to the ESP32 library?

Can anyone shed any light on this? Is this a file omission from the library, or was the secure version never implemented?

As ESP32 core was based on the ESP8266 core I would assume this is a simple copy/paste error that has not been swept up.

I have spent several hours converting my code to the Hessel ESP_HTTPS_Server library and while it initially looked promising and I made considerable progress, I am less than happy with the result, I have found it difficult to work with for several reasons:

  1. It uses a lot more abstraction and is considerably more complex than ESP8266Webserver
  2. It is large - sketch takes 70% program memory with clear text, 90% with secure. Compare that against 35% and 70% for the ESP8266.
  3. Makes a meal of working with post requests which need programming around (seems to be very focussed on file downloads for some reason?). For example, a simple server.arg() takes several lines to accomplish and gets especially complex requiring and external parsing routine when using POST.
  4. It is VERY slow. Much slower than the ESP8266, although to be fair, I'm not sure if this is down to ESP32 hardware or the complexity of the Hessel library.
  5. It uses std::string everywhere which makes it tedious to integrate with sketches built using the Arduino IDE requiring lots of messy conversions with e.g. c_str() everywhere.

Does anyone know of a better webserver library for the ESP32, ideally one that is compatible with ESP8266?

Since at present my audience are most likely to be Arduino IDE users (Uno, Nano, Leonardo, Mega2560 etc) I have stuck with developing and testing my sketches using the Arduino IDE. With WiFi boards such as the ESP8266 and ESP32 it seems the picture is a bit more complex as these are not Arduino boards. A move to Platformio has been suggested, and I believe the Hessel library may have been developed on this platform, which may explain the generous use of std::string, but my concern is that I may then run into the additional overhead of having to support two different IDE's which I would prefer to avoid. As it is, I will already need to maintain separate codebases for the ESP8266 and ESP32 when really, I see no reason why this should be necessary other than that the library has not been provided on the ESP32 for some reason. I find this perplexing since the underlying WiFiServer and WiFiServerSecure components exist on both platforms, albeit the latter seems to have some function omissions.

I guess the point is that I am unsure of which direction to go in. Having the equivalent to ESP8266WebServerSecure on the ESP32 would be ideal as there could be a unified codebase, but it doesn't seem to exist. From a hardware perspective the ESP32 makes sense but from a software point of view the picture is looking a bit complex.

I have even looked into the idea of using MQTT instead of HTTP/S. Its an interesting concept and would allow a unified codebase, but there is the issue of providing a server, e.g. Raspberry Pi. Fine and maybe worthwhile if the object is to control multiple devices, but much less so if the object it to control just one or two devices. However, some preliminary testing with Mosquito on a Linux PC shows that it could work and something could be developed in e.g. Python to run on a PC/Laptop.

I guess what I am looking for is a bit of clarity. Will have to shelve this for a while until I can figure out what to do.