The ESP WebSocket client is an implementation of WebSocket protocol client for ESP32
- supports WebSocket over TCP, SSL with mbedtls
- Easy to setup with URI
- Multiple instances (Multiple clients in one application)
- Supports
ws
,wss
schemes - WebSocket samples:
ws://websocket.org
: WebSocket over TCP, default port 80wss://websocket.org
: WebSocket over SSL, default port 443
- Minimal configurations:
const esp_websocket_client_config_t ws_cfg = {
.uri = "ws://websocket.org",
};
- If there are any options related to the URI in
esp_websocket_client_config_t
, the option defined by the URI will be overridden. Sample:
const esp_websocket_client_config_t ws_cfg = {
.uri = "ws://websocket.org:123",
.port = 4567,
};
//WebSocket client will connect to websocket.org using port 4567
- Get certificate from server, example:
websocket.org
openssl s_client -showcerts -connect websocket.org:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >websocket_org.pem
- Configuration:
const esp_websocket_client_config_t ws_cfg = {
.uri = "wss://websocket.org",
.cert_pem = (const char *)websocket_org_pem_start,
};
For more options on esp_websocket_client_config_t
, please refer to API reference below
Simple WebSocket example that uses esp_websocket_client to establish a websocket connection and send/receive data with the websocket.org Server: :example:`protocols/websocket`.