esp_websocket_client.rst 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ESP WebSocket Client
  2. ====================
  3. Overview
  4. --------
  5. The ESP WebSocket client is an implementation of `WebSocket protocol client <https://tools.ietf.org/html/rfc6455>`_ for ESP32
  6. Features
  7. --------
  8. * supports WebSocket over TCP, SSL with mbedtls
  9. * Easy to setup with URI
  10. * Multiple instances (Multiple clients in one application)
  11. Configuration
  12. -------------
  13. URI
  14. ^^^
  15. - Supports ``ws``, ``wss`` schemes
  16. - WebSocket samples:
  17. - ``ws://websocket.org``: WebSocket over TCP, default port 80
  18. - ``wss://websocket.org``: WebSocket over SSL, default port 443
  19. - Minimal configurations:
  20. .. code:: c
  21. const esp_websocket_client_config_t ws_cfg = {
  22. .uri = "ws://websocket.org",
  23. };
  24. - If there are any options related to the URI in
  25. ``esp_websocket_client_config_t``, the option defined by the URI will be
  26. overridden. Sample:
  27. .. code:: c
  28. const esp_websocket_client_config_t ws_cfg = {
  29. .uri = "ws://websocket.org:123",
  30. .port = 4567,
  31. };
  32. //WebSocket client will connect to websocket.org using port 4567
  33. SSL
  34. ^^^
  35. - Get certificate from server, example: ``websocket.org``
  36. ``openssl s_client -showcerts -connect websocket.org:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >websocket_org.pem``
  37. - Configuration:
  38. .. code:: cpp
  39. const esp_websocket_client_config_t ws_cfg = {
  40. .uri = "wss://websocket.org",
  41. .cert_pem = (const char *)websocket_org_pem_start,
  42. };
  43. For more options on ``esp_websocket_client_config_t``, please refer to API reference below
  44. Application Example
  45. -------------------
  46. Simple WebSocket example that uses esp_websocket_client to establish a websocket connection and send/receive data with the `websocket.org <https://websocket.org>`_ Server: :example:`protocols/websocket`.
  47. API Reference
  48. -------------
  49. .. include:: /_build/inc/esp_websocket_client.inc