esp-idf/examples/protocols/https_server/wss_server
Mahavir Jain af1f342ee8 Merge branch 'fix/make_esp_tls_t_private' into 'master'
Make esp_tls_t as private structure

Closes IDF-2812

See merge request espressif/esp-idf!17812
2022-05-12 14:47:42 +08:00
..
main Merge branch 'fix/make_esp_tls_t_private' into 'master' 2022-05-12 14:47:42 +08:00
CMakeLists.txt https_server example: Add new WSS server example 2020-09-09 08:00:38 +02:00
README.md docs: Updated protocols/http* examples READMEs 2021-09-13 09:55:19 +05:30
sdkconfig.defaults esp_netif: Remove tcpip_adapter compatibility layer 2022-03-10 08:19:43 +01:00
wss_server_example_test.py esp_https_server: API cleanup 2022-02-14 16:25:54 +05:30

HTTP Websocket server with SSL support

This example creates a SSL server and employs a simple Websocket request handler. It demonstrates handling multiple clients from the server including:

  • PING-PONG mechanism
  • Sending asynchronous messages to all clients

See the esp_https_server component documentation for details.

Websocket support in http_server

Please refer to the documentation of Websocket server feature in the documentation, or to the description of using websocket handlers in httpd in the simple ws echo example.

How to use example

Before project configuration and build, be sure to set the correct chip target using idf.py set-target <chip_name>.

Hardware Required

  • A development board with ESP32/ESP32-S2/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
  • A USB cable for power supply and programming

Configure the project

idf.py menuconfig

Open the project configuration menu (idf.py menuconfig) to configure Wi-Fi or Ethernet. See "Establishing Wi-Fi or Ethernet Connection" section in examples/protocols/README.md for more details.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(Replace PORT with the name of the serial port to use.)

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Certificates

You will need to approve a security exception in your browser. This is because of a self signed certificate; this will be always the case, unless you preload the CA root into your browser/system as trusted.

You can generate a new certificate using the OpenSSL command line tool:

openssl req -newkey rsa:2048 -nodes -keyout prvtkey.pem -x509 -days 3650 -out cacert.pem -subj "/CN=ESP32 HTTPS server example"

Expiry time and metadata fields can be adjusted in the invocation.

Please see the openssl man pages (man openssl-req) for more details.

It is strongly recommended to not reuse the example certificate in your application; it is included only for demonstration.