Two HTTPS servers on one ESP32?

tpbedford
Posts: 31
Joined: Mon Feb 14, 2022 4:16 am

Two HTTPS servers on one ESP32?

Postby tpbedford » Thu Mar 10, 2022 10:35 pm

I'm certainly approaching this the wrong way, but I'd like to have an HTTPS server and WSS (secure websocket) server running on one ESP32.

I've tried to run the ESP-IDF Simple https server example and the ESP-IDF wss_server example in parallel, calling both:

Code: Select all

start_wss_echo_server()
and

Code: Select all

start_webserver()
both of which ultimately call

Code: Select all

httpd_ssl_start(&server, &conf);
I've configured them to listen on different ports (and use a differnt UDP ctrl_port), and both appear to start up OK, but neither actually accept a connection on their respective ports (which are 8443 and 443).

I presume I can just use on instance of httpd_ssl_start() and bind both my https server and wss server on different URLS?

Anyone able to provide suggestions on setting this up?

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Two HTTPS servers on one ESP32?

Postby chegewara » Fri Mar 11, 2022 2:34 am

Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: Two HTTPS servers on one ESP32?

Postby ESP_YJM » Fri Mar 11, 2022 2:35 am

Do you make two server ctrl_port different?

tpbedford
Posts: 31
Joined: Mon Feb 14, 2022 4:16 am

Re: Two HTTPS servers on one ESP32?

Postby tpbedford » Mon Mar 14, 2022 4:14 am

ESP_YJM wrote:
Fri Mar 11, 2022 2:35 am
Do you make two server ctrl_port different?
I did make ctrl_port different.

I was unable to get this to work. For my application it was simple enough that I could bind the Websocket handler to "/ws" and move the http fileserver from "/*" to "/a/*" to avoid a conflict in the wildcard .

So I made the websocket server dependent on the httpd instance instead.

chegewara wrote:
Fri Mar 11, 2022 2:34 am
Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.
Actually it looks like the same solution as mine: Bind another path/handler to the one httpd instance:
  1.     ssl_server.registerPath("/", request_handler_ssl);
  2.     ssl_server.registerPath("/ws", wss_request_handler, HTTP_GET, true);
Basically this is how I did it in mine.

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: Two HTTPS servers on one ESP32?

Postby ESP_YJM » Tue Mar 15, 2022 8:26 am

Could you please change the log level to debug and share your whole log.

greycon
Posts: 33
Joined: Fri Nov 03, 2023 9:59 pm

Re: Two HTTPS servers on one ESP32?

Postby greycon » Fri Nov 03, 2023 10:47 pm

chegewara wrote:
Fri Mar 11, 2022 2:34 am
Hi,
this may or may not be useful to you. In this example i am running 1 x http server + 1 x ws server + 1 x https server + 1 x wss server, all at the same time:
https://github.com/chegewara/esp32sx-c- ... ttp-server

It may be useless to you because it is based on C++ components/wrappers, but you may test with it and eventually see how it works.
That's a nice piece of work - so if I understand it at a first read, you manage to achieve some actual asynchronous request processing by means of having a thread work with the underlying HTTP server TCP/IP ports, is that correct?

I plan to try it out tomorrow - thanks again for sharing this. My use case is very simple, I could certainly get by with the HTTP Server handling requests synchronously, but it would be much more elegant to handle them async. Even on an ESP32. I wonder if requests could be made available for handling on the second code... perhaps httpd_queue_work does this - so much to learn :-)

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 83 guests