mqtt.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ESP-MQTT
  2. ========
  3. Overview
  4. --------
  5. ESP-MQTT is an implementation of MQTT protocol client (MQTT is a lightweight publish/subscribe messaging protocol).
  6. Features
  7. --------
  8. * supports MQTT over TCP, SSL with mbedtls, MQTT over Websocket, MQTT over Websocket Secure.
  9. * Easy to setup with URI
  10. * Multiple instances (Multiple clients in one application)
  11. * Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).
  12. Application Example
  13. -------------------
  14. * :example:`protocols/mqtt/tcp`: MQTT over tcp, default port 1883
  15. * :example:`protocols/mqtt/ssl`: MQTT over tcp, default port 8883
  16. * :example:`protocols/mqtt/ws`: MQTT over Websocket, default port 80
  17. * :example:`protocols/mqtt/wss`: MQTT over Websocket Secure, default port 443
  18. Configuration
  19. -------------
  20. URI
  21. ^^^
  22. - Curently support ``mqtt``, ``mqtts``, ``ws``, ``wss`` schemes
  23. - MQTT over TCP samples:
  24. - ``mqtt://mqtt.eclipse.org``: MQTT over TCP, default port 1883:
  25. - ``mqtt://mqtt.eclipse.org:1884`` MQTT over TCP, port 1884:
  26. - ``mqtt://username:password@mqtt.eclipse.org:1884`` MQTT over TCP,
  27. port 1884, with username and password
  28. - MQTT over SSL samples:
  29. - ``mqtts://mqtt.eclipse.org``: MQTT over SSL, port 8883
  30. - ``mqtts://mqtt.eclipse.org:8884``: MQTT over SSL, port 8884
  31. - MQTT over Websocket samples:
  32. - ``ws://mqtt.eclipse.org:80/mqtt``
  33. - MQTT over Websocket Secure samples:
  34. - ``wss://mqtt.eclipse.org:443/mqtt``
  35. - Minimal configurations:
  36. .. code:: c
  37. const esp_mqtt_client_config_t mqtt_cfg = {
  38. .uri = "mqtt://mqtt.eclipse.org",
  39. .event_handle = mqtt_event_handler,
  40. // .user_context = (void *)your_context
  41. };
  42. - If there are any options related to the URI in
  43. ``esp_mqtt_client_config_t``, the option defined by the URI will be
  44. overridden. Sample:
  45. .. code:: c
  46. const esp_mqtt_client_config_t mqtt_cfg = {
  47. .uri = "mqtt://mqtt.eclipse.org:1234",
  48. .event_handle = mqtt_event_handler,
  49. .port = 4567,
  50. };
  51. //MQTT client will connect to mqtt.eclipse.org using port 4567
  52. SSL
  53. ^^^
  54. - Get certificate from server, example: ``mqtt.eclipse.org``
  55. ``openssl s_client -showcerts -connect mqtt.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >mqtt_eclipse_org.pem``
  56. - Check the sample application: ``examples/mqtt_ssl``
  57. - Configuration:
  58. .. code:: cpp
  59. const esp_mqtt_client_config_t mqtt_cfg = {
  60. .uri = "mqtts://mqtt.eclipse.org:8883",
  61. .event_handle = mqtt_event_handler,
  62. .cert_pem = (const char *)mqtt_eclipse_org_pem_start,
  63. };
  64. For more options on ``esp_mqtt_client_config_t``, please refer to API reference below
  65. Change settings in ``menuconfig``
  66. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  67. ::
  68. make menuconfig
  69. -> Component config -> ESP-MQTT Configuration
  70. - :ref:`CONFIG_MQTT_PROTOCOL_311`: Enables 3.1.1 version of MQTT protocol
  71. - :ref:`CONFIG_MQTT_TRANSPORT_SSL`, :ref:`CONFIG_MQTT_TRANSPORT_WEBSOCKET`: Enables specific MQTT transport layer, such as SSL, WEBSOCKET, WEBSOCKET_SECURE
  72. - :ref:`CONFIG_MQTT_CUSTOM_OUTBOX`: Disables default implementation of mqtt_outbox, so a specific implementaion can be supplied
  73. API Reference
  74. -------------
  75. .. include:: /_build/inc/mqtt_client.inc