diff --git a/docs/en/api-reference/protocols/mqtt.rst b/docs/en/api-reference/protocols/mqtt.rst index c5a22aa74..7579d7046 100644 --- a/docs/en/api-reference/protocols/mqtt.rst +++ b/docs/en/api-reference/protocols/mqtt.rst @@ -18,10 +18,10 @@ Features Application Example ------------------- - * :example:`protocols/mqtt/tcp`: MQTT over tcp, defalut port 1883 - * :example:`protocols/mqtt/ssl`: MQTT over tcp, defalut port 8883 - * :example:`protocols/mqtt/ws`: MQTT over Websocket, defalut port 80 - * :example:`protocols/mqtt/wss`: MQTT over Websocket Secure, defalut port 443 + * :example:`protocols/mqtt/tcp`: MQTT over tcp, default port 1883 + * :example:`protocols/mqtt/ssl`: MQTT over tcp, default port 8883 + * :example:`protocols/mqtt/ws`: MQTT over Websocket, default port 80 + * :example:`protocols/mqtt/wss`: MQTT over Websocket Secure, default port 443 Configuration @@ -32,30 +32,30 @@ URI - Curently support ``mqtt``, ``mqtts``, ``ws``, ``wss`` schemes - MQTT over TCP samples: - - ``mqtt://iot.eclipse.org``: MQTT over TCP, default port 1883: - - ``mqtt://iot.eclipse.org:1884`` MQTT over TCP, port 1884: - - ``mqtt://username:password@iot.eclipse.org:1884`` MQTT over TCP, + - ``mqtt://mqtt.eclipse.org``: MQTT over TCP, default port 1883: + - ``mqtt://mqtt.eclipse.org:1884`` MQTT over TCP, port 1884: + - ``mqtt://username:password@mqtt.eclipse.org:1884`` MQTT over TCP, port 1884, with username and password - MQTT over SSL samples: - - ``mqtts://iot.eclipse.org``: MQTT over SSL, port 8883 - - ``mqtts://iot.eclipse.org:8884``: MQTT over SSL, port 8884 + - ``mqtts://mqtt.eclipse.org``: MQTT over SSL, port 8883 + - ``mqtts://mqtt.eclipse.org:8884``: MQTT over SSL, port 8884 - MQTT over Websocket samples: - - ``ws://iot.eclipse.org:80/ws`` + - ``ws://mqtt.eclipse.org:80/mqtt`` - MQTT over Websocket Secure samples: - - ``wss://iot.eclipse.org:443/ws`` + - ``wss://mqtt.eclipse.org:443/mqtt`` - Minimal configurations: .. code:: c const esp_mqtt_client_config_t mqtt_cfg = { - .uri = "mqtt://iot.eclipse.org", + .uri = "mqtt://mqtt.eclipse.org", .event_handle = mqtt_event_handler, // .user_context = (void *)your_context }; @@ -67,26 +67,26 @@ URI .. code:: c const esp_mqtt_client_config_t mqtt_cfg = { - .uri = "mqtt://iot.eclipse.org:1234", + .uri = "mqtt://mqtt.eclipse.org:1234", .event_handle = mqtt_event_handler, .port = 4567, }; - //MQTT client will connect to iot.eclipse.org using port 4567 + //MQTT client will connect to mqtt.eclipse.org using port 4567 SSL ^^^ -- Get certificate from server, example: ``iot.eclipse.org`` - ``openssl s_client -showcerts -connect iot.eclipse.org:8883 /dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem`` +- Get certificate from server, example: ``mqtt.eclipse.org`` + ``openssl s_client -showcerts -connect mqtt.eclipse.org:8883 /dev/null|openssl x509 -outform PEM >mqtt_eclipse_org.pem`` - Check the sample application: ``examples/mqtt_ssl`` - Configuration: .. code:: cpp const esp_mqtt_client_config_t mqtt_cfg = { - .uri = "mqtts://iot.eclipse.org:8883", + .uri = "mqtts://mqtt.eclipse.org:8883", .event_handle = mqtt_event_handler, - .cert_pem = (const char *)iot_eclipse_org_pem_start, + .cert_pem = (const char *)mqtt_eclipse_org_pem_start, }; For more options on ``esp_mqtt_client_config_t``, please refer to API reference below diff --git a/examples/protocols/mqtt/ssl/CMakeLists.txt b/examples/protocols/mqtt/ssl/CMakeLists.txt index 13bdd8c21..717181000 100644 --- a/examples/protocols/mqtt/ssl/CMakeLists.txt +++ b/examples/protocols/mqtt/ssl/CMakeLists.txt @@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(mqtt_ssl) -target_add_binary_data(mqtt_ssl.elf "main/iot_eclipse_org.pem" TEXT) +target_add_binary_data(mqtt_ssl.elf "main/mqtt_eclipse_org.pem" TEXT) diff --git a/examples/protocols/mqtt/ssl/README.md b/examples/protocols/mqtt/ssl/README.md index 3d369bdf9..70fe819c8 100644 --- a/examples/protocols/mqtt/ssl/README.md +++ b/examples/protocols/mqtt/ssl/README.md @@ -2,7 +2,7 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) -This example connects to the broker iot.eclipse.org using ssl transport and as a demonstration subscribes/unsubscribes and send a message on certain topic. +This example connects to the broker mqtt.eclipse.org using ssl transport and as a demonstration subscribes/unsubscribes and send a message on certain topic. It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. @@ -22,9 +22,9 @@ make menuconfig * Set ssid and password for the board to connect to AP. -Note how to create a PEM certificate for iot.eclipse.org: +Note how to create a PEM certificate for mqtt.eclipse.org: ``` -openssl s_client -showcerts -connect iot.eclipse.org:8883 /dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem +echo "" | openssl s_client -showcerts -connect mqtt.eclipse.org:8883 | sed -n "1,/Root/d; /BEGIN/,/END/p" | openssl x509 -outform PEM >mqtt_eclipse_org.pem ``` ### Build and Flash diff --git a/examples/protocols/mqtt/ssl/main/Kconfig.projbuild b/examples/protocols/mqtt/ssl/main/Kconfig.projbuild index 8b4eda41a..7d7f8f80f 100644 --- a/examples/protocols/mqtt/ssl/main/Kconfig.projbuild +++ b/examples/protocols/mqtt/ssl/main/Kconfig.projbuild @@ -14,7 +14,7 @@ config WIFI_PASSWORD config BROKER_URI string "Broker URL" - default "mqtts://iot.eclipse.org:8883" + default "mqtts://mqtt.eclipse.org:8883" help URL of an mqtt broker which this example connects to. diff --git a/examples/protocols/mqtt/ssl/main/app_main.c b/examples/protocols/mqtt/ssl/main/app_main.c index 3ce00741c..9b9335b09 100644 --- a/examples/protocols/mqtt/ssl/main/app_main.c +++ b/examples/protocols/mqtt/ssl/main/app_main.c @@ -70,11 +70,11 @@ static void wifi_init(void) } #if CONFIG_BROKER_CERTIFICATE_OVERRIDDEN == 1 -static const uint8_t iot_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; +static const uint8_t mqtt_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; #else -extern const uint8_t iot_eclipse_org_pem_start[] asm("_binary_iot_eclipse_org_pem_start"); +extern const uint8_t mqtt_eclipse_org_pem_start[] asm("_binary_mqtt_eclipse_org_pem_start"); #endif -extern const uint8_t iot_eclipse_org_pem_end[] asm("_binary_iot_eclipse_org_pem_end"); +extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end"); static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) { @@ -132,7 +132,7 @@ static void mqtt_app_start(void) const esp_mqtt_client_config_t mqtt_cfg = { .uri = CONFIG_BROKER_URI, .event_handle = mqtt_event_handler, - .cert_pem = (const char *)iot_eclipse_org_pem_start, + .cert_pem = (const char *)mqtt_eclipse_org_pem_start, }; ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); diff --git a/examples/protocols/mqtt/ssl/main/component.mk b/examples/protocols/mqtt/ssl/main/component.mk index 797c4a1f6..597752fb9 100644 --- a/examples/protocols/mqtt/ssl/main/component.mk +++ b/examples/protocols/mqtt/ssl/main/component.mk @@ -1 +1 @@ -COMPONENT_EMBED_TXTFILES := iot_eclipse_org.pem +COMPONENT_EMBED_TXTFILES := mqtt_eclipse_org.pem diff --git a/examples/protocols/mqtt/ssl/main/iot_eclipse_org.pem b/examples/protocols/mqtt/ssl/main/mqtt_eclipse_org.pem similarity index 100% rename from examples/protocols/mqtt/ssl/main/iot_eclipse_org.pem rename to examples/protocols/mqtt/ssl/main/mqtt_eclipse_org.pem diff --git a/examples/protocols/mqtt/ssl/mqtt_ssl_example_test.py b/examples/protocols/mqtt/ssl/mqtt_ssl_example_test.py index 3ea27c096..ef9d1a9d6 100644 --- a/examples/protocols/mqtt/ssl/mqtt_ssl_example_test.py +++ b/examples/protocols/mqtt/ssl/mqtt_ssl_example_test.py @@ -86,8 +86,8 @@ def test_examples_protocol_mqtt_ssl(env, extra_data): client.on_connect = on_connect client.on_message = on_message client.tls_set(None, - None, - None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None) + None, + None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None) client.tls_insecure_set(True) print("Connecting...") client.connect(broker_url, broker_port, 60) @@ -117,5 +117,6 @@ def test_examples_protocol_mqtt_ssl(env, extra_data): event_stop_client.set() thread1.join() + if __name__ == '__main__': test_examples_protocol_mqtt_ssl() diff --git a/examples/protocols/mqtt/tcp/main/Kconfig.projbuild b/examples/protocols/mqtt/tcp/main/Kconfig.projbuild index 71f95ea8f..da995ffe0 100644 --- a/examples/protocols/mqtt/tcp/main/Kconfig.projbuild +++ b/examples/protocols/mqtt/tcp/main/Kconfig.projbuild @@ -14,7 +14,7 @@ config WIFI_PASSWORD config BROKER_URL string "Broker URL" - default "mqtt://iot.eclipse.org" + default "mqtt://mqtt.eclipse.org" help URL of the broker to connect to diff --git a/examples/protocols/mqtt/ws/README.md b/examples/protocols/mqtt/ws/README.md index 619519d92..905d20809 100644 --- a/examples/protocols/mqtt/ws/README.md +++ b/examples/protocols/mqtt/ws/README.md @@ -2,7 +2,7 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) -This example connects to the broker iot.eclipse.org over web sockets as a demonstration subscribes/unsubscribes and send a message on certain topic. +This example connects to the broker mqtt.eclipse.org over web sockets as a demonstration subscribes/unsubscribes and send a message on certain topic. It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. diff --git a/examples/protocols/mqtt/ws/main/Kconfig.projbuild b/examples/protocols/mqtt/ws/main/Kconfig.projbuild index 5223e885f..faa2b78be 100644 --- a/examples/protocols/mqtt/ws/main/Kconfig.projbuild +++ b/examples/protocols/mqtt/ws/main/Kconfig.projbuild @@ -14,7 +14,7 @@ config WIFI_PASSWORD config BROKER_URI string "Broker URL" - default "ws://iot.eclipse.org:80/ws" + default "ws://mqtt.eclipse.org:80/mqtt" help URL of an mqtt broker which this example connects to. diff --git a/examples/protocols/mqtt/ws/mqtt_ws_example_test.py b/examples/protocols/mqtt/ws/mqtt_ws_example_test.py index b4919bfb6..0e5aee978 100644 --- a/examples/protocols/mqtt/ws/mqtt_ws_example_test.py +++ b/examples/protocols/mqtt/ws/mqtt_ws_example_test.py @@ -82,7 +82,6 @@ def test_examples_protocol_mqtt_ws(env, extra_data): client = mqtt.Client(transport="websockets") client.on_connect = on_connect client.on_message = on_message - client.ws_set_options(path="/ws", headers=None) print("Connecting...") client.connect(broker_url, broker_port, 60) except Exception: diff --git a/examples/protocols/mqtt/wss/CMakeLists.txt b/examples/protocols/mqtt/wss/CMakeLists.txt index 7ba5e6295..f94926163 100644 --- a/examples/protocols/mqtt/wss/CMakeLists.txt +++ b/examples/protocols/mqtt/wss/CMakeLists.txt @@ -6,4 +6,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(mqtt_websocket_secure) -target_add_binary_data(mqtt_websocket_secure.elf "main/iot_eclipse_org.pem" TEXT) +target_add_binary_data(mqtt_websocket_secure.elf "main/mqtt_eclipse_org.pem" TEXT) diff --git a/examples/protocols/mqtt/wss/README.md b/examples/protocols/mqtt/wss/README.md index 43d829ccb..c92500eaa 100644 --- a/examples/protocols/mqtt/wss/README.md +++ b/examples/protocols/mqtt/wss/README.md @@ -1,7 +1,7 @@ # ESP-MQTT MQTT over WSS Sample application (See the README.md file in the upper level 'examples' directory for more information about examples.) -This example connects to the broker iot.eclipse.org over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic. +This example connects to the broker mqtt.eclipse.org over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic. It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. @@ -21,10 +21,10 @@ make menuconfig * Set ssid and password for the board to connect to AP. -Note how to create a PEM certificate for iot.eclipse.org: +Note how to create a PEM certificate for mqtt.eclipse.org: ``` -openssl s_client -showcerts -connect iot.eclipse.org:8883 /dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem +openssl s_client -showcerts -connect mqtt.eclipse.org:8883 /dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem ``` ### Build and Flash diff --git a/examples/protocols/mqtt/wss/main/Kconfig.projbuild b/examples/protocols/mqtt/wss/main/Kconfig.projbuild index 964d436f6..9ec3753de 100644 --- a/examples/protocols/mqtt/wss/main/Kconfig.projbuild +++ b/examples/protocols/mqtt/wss/main/Kconfig.projbuild @@ -14,7 +14,7 @@ config WIFI_PASSWORD config BROKER_URI string "Broker URL" - default "wss://iot.eclipse.org:443/ws" + default "wss://mqtt.eclipse.org:443/mqtt" help URL of an mqtt broker which this example connects to. diff --git a/examples/protocols/mqtt/wss/main/app_main.c b/examples/protocols/mqtt/wss/main/app_main.c index 50595495a..47f11a5fe 100644 --- a/examples/protocols/mqtt/wss/main/app_main.c +++ b/examples/protocols/mqtt/wss/main/app_main.c @@ -70,11 +70,11 @@ static void wifi_init(void) } #if CONFIG_BROKER_CERTIFICATE_OVERRIDDEN == 1 -static const uint8_t iot_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; +static const uint8_t mqtt_eclipse_org_pem_start[] = "-----BEGIN CERTIFICATE-----\n" CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; #else -extern const uint8_t iot_eclipse_org_pem_start[] asm("_binary_iot_eclipse_org_pem_start"); +extern const uint8_t mqtt_eclipse_org_pem_start[] asm("_binary_mqtt_eclipse_org_pem_start"); #endif -extern const uint8_t iot_eclipse_org_pem_end[] asm("_binary_iot_eclipse_org_pem_end"); +extern const uint8_t mqtt_eclipse_org_pem_end[] asm("_binary_mqtt_eclipse_org_pem_end"); static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) { @@ -128,7 +128,7 @@ static void mqtt_app_start(void) const esp_mqtt_client_config_t mqtt_cfg = { .uri = CONFIG_BROKER_URI, .event_handle = mqtt_event_handler, - .cert_pem = (const char *)iot_eclipse_org_pem_start, + .cert_pem = (const char *)mqtt_eclipse_org_pem_start, }; ESP_LOGI(TAG, "[APP] Free memory: %d bytes", esp_get_free_heap_size()); diff --git a/examples/protocols/mqtt/wss/main/component.mk b/examples/protocols/mqtt/wss/main/component.mk index 797c4a1f6..597752fb9 100644 --- a/examples/protocols/mqtt/wss/main/component.mk +++ b/examples/protocols/mqtt/wss/main/component.mk @@ -1 +1 @@ -COMPONENT_EMBED_TXTFILES := iot_eclipse_org.pem +COMPONENT_EMBED_TXTFILES := mqtt_eclipse_org.pem diff --git a/examples/protocols/mqtt/wss/main/iot_eclipse_org.pem b/examples/protocols/mqtt/wss/main/mqtt_eclipse_org.pem similarity index 100% rename from examples/protocols/mqtt/wss/main/iot_eclipse_org.pem rename to examples/protocols/mqtt/wss/main/mqtt_eclipse_org.pem diff --git a/examples/protocols/mqtt/wss/mqtt_wss_example_test.py b/examples/protocols/mqtt/wss/mqtt_wss_example_test.py index 6aac644c6..2f529548f 100644 --- a/examples/protocols/mqtt/wss/mqtt_wss_example_test.py +++ b/examples/protocols/mqtt/wss/mqtt_wss_example_test.py @@ -84,8 +84,8 @@ def test_examples_protocol_mqtt_wss(env, extra_data): client.on_connect = on_connect client.on_message = on_message client.tls_set(None, - None, - None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None) + None, + None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None) print("Connecting...") client.connect(broker_url, broker_port, 60) except Exception: