From 6694e60134ccffc3e36599c4468373140af455aa Mon Sep 17 00:00:00 2001 From: Euripedes Rocha Filho Date: Thu, 13 Aug 2026 15:52:45 +0200 Subject: [PATCH] fix: Examples to use available mosquitto broker --- examples/custom_outbox/CMakeLists.txt | 4 +-- examples/custom_outbox/README.md | 2 +- examples/custom_outbox/main/CMakeLists.txt | 2 +- examples/mqtt5/README.md | 2 +- examples/mqtt5/main/app_main.c | 2 -- examples/mqtt5/pytest_mqtt5.py | 2 +- examples/ssl/CMakeLists.txt | 2 +- examples/ssl/README.md | 13 ++------ examples/ssl/main/CMakeLists.txt | 7 ++++- examples/ssl/main/app_main.c | 20 +++++++----- examples/ssl/main/mosquitto.org.crt | 24 ++++++++++++++ examples/ssl/main/mqtt_eclipseprojects_io.pem | 30 ------------------ examples/ssl_mutual_auth/main/CMakeLists.txt | 2 +- examples/ssl_mutual_auth/main/app_main.c | 7 +---- examples/ssl_psk/main/CMakeLists.txt | 2 +- examples/ssl_psk/main/app_main.c | 7 +---- examples/tcp/README.md | 2 +- examples/ws/README.md | 4 +-- examples/ws/main/CMakeLists.txt | 2 +- examples/ws/main/Kconfig.projbuild | 2 +- examples/ws/main/app_main.c | 7 +---- examples/wss/CMakeLists.txt | 2 +- examples/wss/README.md | 15 ++------- examples/wss/main/CMakeLists.txt | 2 +- examples/wss/main/Kconfig.projbuild | 2 +- examples/wss/main/app_main.c | 17 ++++------ examples/wss/main/isrg_root_x1.crt | 31 +++++++++++++++++++ examples/wss/main/mqtt_eclipseprojects_io.pem | 30 ------------------ 28 files changed, 106 insertions(+), 138 deletions(-) create mode 100644 examples/ssl/main/mosquitto.org.crt delete mode 100644 examples/ssl/main/mqtt_eclipseprojects_io.pem create mode 100644 examples/wss/main/isrg_root_x1.crt delete mode 100644 examples/wss/main/mqtt_eclipseprojects_io.pem diff --git a/examples/custom_outbox/CMakeLists.txt b/examples/custom_outbox/CMakeLists.txt index 137506b..ac32cf1 100644 --- a/examples/custom_outbox/CMakeLists.txt +++ b/examples/custom_outbox/CMakeLists.txt @@ -16,5 +16,5 @@ target_sources(${mqtt} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/main/custom_outbox.cp # system needs to be aware of it to be able to compile and link the mqtt component. # First we get our dependency idf_component_get_property(pthread pthread COMPONENT_LIB) -# And them we link the components -target_link_libraries(${mqtt} PRIVATE ${pthread}) +# And then we link the components +target_link_libraries(${mqtt} PUBLIC ${pthread}) diff --git a/examples/custom_outbox/README.md b/examples/custom_outbox/README.md index 1c40206..6ccace3 100644 --- a/examples/custom_outbox/README.md +++ b/examples/custom_outbox/README.md @@ -6,7 +6,7 @@ This example is a slightly modified version of the tcp example to show how to configure a custom outbox. This example connects to the broker URI selected using `idf.py menuconfig` (using mqtt tcp transport) and as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) Note: If the URI equals `FROM_STDIN` then the broker address is read from stdin upon application startup (used for testing) diff --git a/examples/custom_outbox/main/CMakeLists.txt b/examples/custom_outbox/main/CMakeLists.txt index 7423b60..ce3b0b8 100644 --- a/examples/custom_outbox/main/CMakeLists.txt +++ b/examples/custom_outbox/main/CMakeLists.txt @@ -1,4 +1,4 @@ idf_component_register(SRCS "app_main.c" INCLUDE_DIRS "." - PRIV_REQUIRES mqtt nvs_flash esp_netif + PRIV_REQUIRES mqtt nvs_flash esp_netif pthread ) diff --git a/examples/mqtt5/README.md b/examples/mqtt5/README.md index 62d1ec9..2eb2447 100644 --- a/examples/mqtt5/README.md +++ b/examples/mqtt5/README.md @@ -5,7 +5,7 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) This example connects to the broker URI selected using `idf.py menuconfig` (using mqtt tcp transport) and as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) Note: If the URI equals `FROM_STDIN` then the broker address is read from stdin upon application startup (used for testing) diff --git a/examples/mqtt5/main/app_main.c b/examples/mqtt5/main/app_main.c index cafc59c..0da3064 100644 --- a/examples/mqtt5/main/app_main.c +++ b/examples/mqtt5/main/app_main.c @@ -218,8 +218,6 @@ static void mqtt5_app_start(void) .broker.address.uri = CONFIG_BROKER_URL, .session.protocol_ver = MQTT_PROTOCOL_V_5, .network.disable_auto_reconnect = true, - .credentials.username = "123", - .credentials.authentication.password = "456", .session.last_will.topic = "topic/will", .session.last_will.msg = "i will leave", .session.last_will.msg_len = 12, diff --git a/examples/mqtt5/pytest_mqtt5.py b/examples/mqtt5/pytest_mqtt5.py index e0c94c1..323294b 100644 --- a/examples/mqtt5/pytest_mqtt5.py +++ b/examples/mqtt5/pytest_mqtt5.py @@ -16,7 +16,7 @@ def test_examples_protocol_mqtt5(dut: Dut) -> None: """ steps: | 1. join AP - 2. connect to mqtt://mqtt.eclipseprojects.io + 2. connect to mqtt://test.mosquitto.org 3. check connection success """ # check and log bin size diff --git a/examples/ssl/CMakeLists.txt b/examples/ssl/CMakeLists.txt index e41e1b8..05cab3b 100644 --- a/examples/ssl/CMakeLists.txt +++ b/examples/ssl/CMakeLists.txt @@ -8,4 +8,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) idf_build_set_property(MINIMAL_BUILD ON) project(mqtt_ssl) -target_add_binary_data(${PROJECT_NAME}.elf "main/mqtt_eclipseprojects_io.pem" TEXT) +target_add_binary_data(${PROJECT_NAME}.elf "main/mosquitto.org.crt" TEXT) diff --git a/examples/ssl/README.md b/examples/ssl/README.md index 2a74f45..3485244 100644 --- a/examples/ssl/README.md +++ b/examples/ssl/README.md @@ -5,8 +5,8 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) -This example connects to the broker mqtt.eclipseprojects.io using ssl transport and as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +This example connects to the broker test.mosquitto.org using ssl transport and as a demonstration subscribes/unsubscribes and send a message on certain topic. +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. @@ -21,14 +21,7 @@ This example can be executed on any ESP32 board, the only required interface is * Open the project configuration menu (`idf.py menuconfig`) * Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details. -PEM certificate for this example could be extracted from an openssl `s_client` command connecting to mqtt.eclipseprojects.io. -In case a host operating system has `openssl` and `sed` packages installed, one could execute the following command to download and save the root certificate to a file (Note for Windows users: Both Linux like environment or Windows native packages may be used). -``` -echo "" | openssl s_client -showcerts -connect mqtt.eclipseprojects.io:8883 | sed -n "1,/Root/d; /BEGIN/,/END/p" | openssl x509 -outform PEM >mqtt_eclipse_org.pem -``` -Please note that this is not a general command for downloading a root certificate for an arbitrary host; -this command works with mqtt.eclipseprojects.io as the site provides root certificate in the chain, which then could be extracted -with text operation. +The default broker URI is `mqtts://test.mosquitto.org:8883`. As documented on [test.mosquitto.org](http://test.mosquitto.org), port 8883 should be verified with the Mosquitto certificate authority file `mosquitto.org.crt`. That CA is included as `main/mosquitto.org.crt` and can be downloaded from [mosquitto.org.crt](https://test.mosquitto.org/ssl/mosquitto.org.crt). ### Build and Flash diff --git a/examples/ssl/main/CMakeLists.txt b/examples/ssl/main/CMakeLists.txt index d6ca62d..bdde96c 100644 --- a/examples/ssl/main/CMakeLists.txt +++ b/examples/ssl/main/CMakeLists.txt @@ -1,3 +1,8 @@ +idf_build_get_property(idf_target IDF_TARGET) +set(ssl_priv_requires mqtt esp_partition nvs_flash esp_netif) +if(NOT idf_target STREQUAL "linux") + list(APPEND ssl_priv_requires app_update) +endif() idf_component_register(SRCS "app_main.c" - PRIV_REQUIRES mqtt esp_partition nvs_flash esp_netif app_update + PRIV_REQUIRES ${ssl_priv_requires} INCLUDE_DIRS ".") diff --git a/examples/ssl/main/app_main.c b/examples/ssl/main/app_main.c index 49378b3..5e7d811 100644 --- a/examples/ssl/main/app_main.c +++ b/examples/ssl/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -26,25 +26,28 @@ #include "esp_log.h" #include "mqtt_client.h" #include "esp_tls.h" +#if !CONFIG_IDF_TARGET_LINUX #include "esp_ota_ops.h" +#endif #include static const char *TAG = "mqtts_example"; #if CONFIG_BROKER_CERTIFICATE_OVERRIDDEN == 1 -static const uint8_t mqtt_eclipseprojects_io_pem_start[] = "-----BEGIN CERTIFICATE-----\n" - CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; +static const uint8_t mosquitto_org_crt_start[] = "-----BEGIN CERTIFICATE-----\n" + CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; #else -extern const uint8_t mqtt_eclipseprojects_io_pem_start[] asm("_binary_mqtt_eclipseprojects_io_pem_start"); +extern const uint8_t mosquitto_org_crt_start[] asm("_binary_mosquitto_org_crt_start"); #endif -extern const uint8_t mqtt_eclipseprojects_io_pem_end[] asm("_binary_mqtt_eclipseprojects_io_pem_end"); +extern const uint8_t mosquitto_org_crt_end[] asm("_binary_mosquitto_org_crt_end"); // // Note: this function is for testing purposes only publishing part of the active partition -// (to be checked against the original binary) +// (to be checked against the original binary). No-op on Linux target. // static void send_binary(esp_mqtt_client_handle_t client) { +#if !CONFIG_IDF_TARGET_LINUX esp_partition_mmap_handle_t out_handle; const void *binary_address; const esp_partition_t *partition = esp_ota_get_running_partition(); @@ -53,6 +56,9 @@ static void send_binary(esp_mqtt_client_handle_t client) int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size); int msg_id = esp_mqtt_client_publish(client, "topic/binary", binary_address, binary_size, 0, 0); ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id); +#else + (void)client; +#endif } /* @@ -140,7 +146,7 @@ static void mqtt_app_start(void) const esp_mqtt_client_config_t mqtt_cfg = { .broker = { .address.uri = CONFIG_BROKER_URI, - .verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start, + .verification.certificate = (const char *)mosquitto_org_crt_start, }, }; ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size()); diff --git a/examples/ssl/main/mosquitto.org.crt b/examples/ssl/main/mosquitto.org.crt new file mode 100644 index 0000000..e76dbd8 --- /dev/null +++ b/examples/ssl/main/mosquitto.org.crt @@ -0,0 +1,24 @@ +-----BEGIN CERTIFICATE----- +MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL +BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG +A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU +BgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hv +by5vcmcwHhcNMjAwNjA5MTEwNjM5WhcNMzAwNjA3MTEwNjM5WjCBkDELMAkGA1UE +BhMCR0IxFzAVBgNVBAgMDlVuaXRlZCBLaW5nZG9tMQ4wDAYDVQQHDAVEZXJieTES +MBAGA1UECgwJTW9zcXVpdHRvMQswCQYDVQQLDAJDQTEWMBQGA1UEAwwNbW9zcXVp +dHRvLm9yZzEfMB0GCSqGSIb3DQEJARYQcm9nZXJAYXRjaG9vLm9yZzCCASIwDQYJ +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAME0HKmIzfTOwkKLT3THHe+ObdizamPg +UZmD64Tf3zJdNeYGYn4CEXbyP6fy3tWc8S2boW6dzrH8SdFf9uo320GJA9B7U1FW +Te3xda/Lm3JFfaHjkWw7jBwcauQZjpGINHapHRlpiCZsquAthOgxW9SgDgYlGzEA +s06pkEFiMw+qDfLo/sxFKB6vQlFekMeCymjLCbNwPJyqyhFmPWwio/PDMruBTzPH +3cioBnrJWKXc3OjXdLGFJOfj7pP0j/dr2LH72eSvv3PQQFl90CZPFhrCUcRHSSxo +E6yjGOdnz7f6PveLIB574kQORwt8ePn0yidrTC1ictikED3nHYhMUOUCAwEAAaNT +MFEwHQYDVR0OBBYEFPVV6xBUFPiGKDyo5V3+Hbh4N9YSMB8GA1UdIwQYMBaAFPVV +6xBUFPiGKDyo5V3+Hbh4N9YSMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL +BQADggEBAGa9kS21N70ThM6/Hj9D7mbVxKLBjVWe2TPsGfbl3rEDfZ+OKRZ2j6AC +6r7jb4TZO3dzF2p6dgbrlU71Y/4K0TdzIjRj3cQ3KSm41JvUQ0hZ/c04iGDg/xWf ++pp58nfPAYwuerruPNWmlStWAXf0UTqRtg4hQDWBuUFDJTuWuuBvEXudz74eh/wK +sMwfu1HFvjy5Z0iMDU8PUDepjVolOCue9ashlS4EB5IECdSR2TItnAIiIwimx839 +LdUdRudafMu5T5Xma182OC0/u/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE +m/XriWr/Cq4h/JfB7NTsezVslgkBaoU= +-----END CERTIFICATE----- diff --git a/examples/ssl/main/mqtt_eclipseprojects_io.pem b/examples/ssl/main/mqtt_eclipseprojects_io.pem deleted file mode 100644 index 43b222a..0000000 --- a/examples/ssl/main/mqtt_eclipseprojects_io.pem +++ /dev/null @@ -1,30 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw -TzELMAkGA1UEBhMCVVMxKTAn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J+m74uyA+eitRY8kc607TkC53wl -ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz -CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm -lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4 -avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2 -yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O -yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids -hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+ -HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv -MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX -nLRbwHOoq7hHwg== ------END CERTIFICATE----- diff --git a/examples/ssl_mutual_auth/main/CMakeLists.txt b/examples/ssl_mutual_auth/main/CMakeLists.txt index 31650f3..3bf739c 100644 --- a/examples/ssl_mutual_auth/main/CMakeLists.txt +++ b/examples/ssl_mutual_auth/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "app_main.c" - PRIV_REQUIRES mqtt esp_wifi nvs_flash + PRIV_REQUIRES mqtt nvs_flash esp_netif INCLUDE_DIRS ".") diff --git a/examples/ssl_mutual_auth/main/app_main.c b/examples/ssl_mutual_auth/main/app_main.c index 97b5a2a..f82907d 100644 --- a/examples/ssl_mutual_auth/main/app_main.c +++ b/examples/ssl_mutual_auth/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,7 +15,6 @@ #include #include #include -#include "esp_wifi.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" @@ -27,10 +26,6 @@ #include "freertos/semphr.h" #include "freertos/queue.h" -#include "lwip/sockets.h" -#include "lwip/dns.h" -#include "lwip/netdb.h" - #include "esp_log.h" #include "mqtt_client.h" diff --git a/examples/ssl_psk/main/CMakeLists.txt b/examples/ssl_psk/main/CMakeLists.txt index 31650f3..3bf739c 100644 --- a/examples/ssl_psk/main/CMakeLists.txt +++ b/examples/ssl_psk/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "app_main.c" - PRIV_REQUIRES mqtt esp_wifi nvs_flash + PRIV_REQUIRES mqtt nvs_flash esp_netif INCLUDE_DIRS ".") diff --git a/examples/ssl_psk/main/app_main.c b/examples/ssl_psk/main/app_main.c index 428e075..7e30258 100644 --- a/examples/ssl_psk/main/app_main.c +++ b/examples/ssl_psk/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,7 +16,6 @@ #include #include #include -#include "esp_wifi.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" @@ -28,10 +27,6 @@ #include "freertos/semphr.h" #include "freertos/queue.h" -#include "lwip/sockets.h" -#include "lwip/dns.h" -#include "lwip/netdb.h" - #include "esp_log.h" #include "mqtt_client.h" #include "esp_tls.h" diff --git a/examples/tcp/README.md b/examples/tcp/README.md index 27de9f5..ccf4a76 100644 --- a/examples/tcp/README.md +++ b/examples/tcp/README.md @@ -5,7 +5,7 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) This example connects to the broker URI selected using `idf.py menuconfig` (using mqtt tcp transport) and as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) Note: If the URI equals `FROM_STDIN` then the broker address is read from stdin upon application startup (used for testing) diff --git a/examples/ws/README.md b/examples/ws/README.md index 1eb9c48..d1a7615 100644 --- a/examples/ws/README.md +++ b/examples/ws/README.md @@ -5,8 +5,8 @@ (See the README.md file in the upper level 'examples' directory for more information about examples.) -This example connects to the broker mqtt.eclipseprojects.io over web sockets as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +This example connects to the broker test.mosquitto.org over web sockets as a demonstration subscribes/unsubscribes and send a message on certain topic. +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. diff --git a/examples/ws/main/CMakeLists.txt b/examples/ws/main/CMakeLists.txt index 31650f3..3bf739c 100644 --- a/examples/ws/main/CMakeLists.txt +++ b/examples/ws/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "app_main.c" - PRIV_REQUIRES mqtt esp_wifi nvs_flash + PRIV_REQUIRES mqtt nvs_flash esp_netif INCLUDE_DIRS ".") diff --git a/examples/ws/main/Kconfig.projbuild b/examples/ws/main/Kconfig.projbuild index 0fb37be..2a2ce37 100644 --- a/examples/ws/main/Kconfig.projbuild +++ b/examples/ws/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "Example Configuration" config BROKER_URI string "Broker URL" - default "ws://test.mosquitto.org:80/mqtt" + default "ws://test.mosquitto.org:8080/mqtt" help URL of an mqtt broker which this example connects to. diff --git a/examples/ws/main/app_main.c b/examples/ws/main/app_main.c index 5bb0d27..53ea95c 100644 --- a/examples/ws/main/app_main.c +++ b/examples/ws/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,7 +15,6 @@ #include #include #include -#include "esp_wifi.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" @@ -27,10 +26,6 @@ #include "freertos/semphr.h" #include "freertos/queue.h" -#include "lwip/sockets.h" -#include "lwip/dns.h" -#include "lwip/netdb.h" - #include "esp_log.h" #include "mqtt_client.h" diff --git a/examples/wss/CMakeLists.txt b/examples/wss/CMakeLists.txt index e62d88e..bea36b6 100644 --- a/examples/wss/CMakeLists.txt +++ b/examples/wss/CMakeLists.txt @@ -8,4 +8,4 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake) idf_build_set_property(MINIMAL_BUILD ON) project(mqtt_websocket_secure) -target_add_binary_data(${PROJECT_NAME}.elf "main/mqtt_eclipseprojects_io.pem" TEXT) +target_add_binary_data(${PROJECT_NAME}.elf "main/isrg_root_x1.crt" TEXT) diff --git a/examples/wss/README.md b/examples/wss/README.md index d8ecdc3..cbfebff 100644 --- a/examples/wss/README.md +++ b/examples/wss/README.md @@ -4,8 +4,8 @@ # 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 mqtt.eclipseprojects.io over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic. -(Please note that the public broker is maintained by the community so may not be always available, for details please see this [disclaimer](https://iot.eclipse.org/getting-started/#sandboxes)) +This example connects to the broker test.mosquitto.org over secure websockets and as a demonstration subscribes/unsubscribes and send a message on certain topic. +(Please note that the public broker is maintained by the community so may not be always available, for details please visit http://test.mosquitto.org) It uses ESP-MQTT library which implements mqtt client to connect to mqtt broker. @@ -20,16 +20,7 @@ This example can be executed on any ESP32 board, the only required interface is * Open the project configuration menu (`idf.py menuconfig`) * Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details. -Note how to create a PEM certificate for mqtt.eclipseprojects.io: - -PEM certificate for this example could be extracted from an openssl `s_client` command connecting to mqtt.eclipseprojects.io. -In case a host operating system has `openssl` and `sed` packages installed, one could execute the following command to download and save the root certificate to a file (Note for Windows users: Both Linux like environment or Windows native packages may be used). -``` -echo "" | openssl s_client -showcerts -connect mqtt.eclipseprojects.io:443 | sed -n "1,/Root/d; /BEGIN/,/END/p" | openssl x509 -outform PEM >mqtt_eclipse_org.pem -``` -Please note that this is not a general command for downloading a root certificate for an arbitrary host; -this command works with mqtt.eclipseprojects.io as the site provides root certificate in the chain, which then could be extracted -with text operation. +The default broker URI is `wss://test.mosquitto.org:8081/mqtt`. As documented on [test.mosquitto.org](http://test.mosquitto.org), port 8081 uses a Let's Encrypt certificate, so verification should use the appropriate Let's Encrypt CA. This example embeds ISRG Root X1 as `main/isrg_root_x1.crt`. ### Build and Flash diff --git a/examples/wss/main/CMakeLists.txt b/examples/wss/main/CMakeLists.txt index 31650f3..3bf739c 100644 --- a/examples/wss/main/CMakeLists.txt +++ b/examples/wss/main/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "app_main.c" - PRIV_REQUIRES mqtt esp_wifi nvs_flash + PRIV_REQUIRES mqtt nvs_flash esp_netif INCLUDE_DIRS ".") diff --git a/examples/wss/main/Kconfig.projbuild b/examples/wss/main/Kconfig.projbuild index f7de59a..6f2b1dc 100644 --- a/examples/wss/main/Kconfig.projbuild +++ b/examples/wss/main/Kconfig.projbuild @@ -2,7 +2,7 @@ menu "Example Configuration" config BROKER_URI string "Broker URL" - default "wss://test.mosquitto.org:443/mqtt" + default "wss://test.mosquitto.org:8081/mqtt" help URL of an mqtt broker which this example connects to. diff --git a/examples/wss/main/app_main.c b/examples/wss/main/app_main.c index 6aa4ef8..1ecc322 100644 --- a/examples/wss/main/app_main.c +++ b/examples/wss/main/app_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -15,7 +15,6 @@ #include #include #include -#include "esp_wifi.h" #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" @@ -27,22 +26,18 @@ #include "freertos/semphr.h" #include "freertos/queue.h" -#include "lwip/sockets.h" -#include "lwip/dns.h" -#include "lwip/netdb.h" - #include "esp_log.h" #include "mqtt_client.h" static const char *TAG = "mqttwss_example"; #if CONFIG_BROKER_CERTIFICATE_OVERRIDDEN == 1 -static const uint8_t mqtt_eclipseprojects_io_pem_start[] = "-----BEGIN CERTIFICATE-----\n" - CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; +static const uint8_t isrg_root_x1_crt_start[] = "-----BEGIN CERTIFICATE-----\n" + CONFIG_BROKER_CERTIFICATE_OVERRIDE "\n-----END CERTIFICATE-----"; #else -extern const uint8_t mqtt_eclipseprojects_io_pem_start[] asm("_binary_mqtt_eclipseprojects_io_pem_start"); +extern const uint8_t isrg_root_x1_crt_start[] asm("_binary_isrg_root_x1_crt_start"); #endif -extern const uint8_t mqtt_eclipseprojects_io_pem_end[] asm("_binary_mqtt_eclipseprojects_io_pem_end"); +extern const uint8_t isrg_root_x1_crt_end[] asm("_binary_isrg_root_x1_crt_end"); static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event) { @@ -108,7 +103,7 @@ static void mqtt_app_start(void) { const esp_mqtt_client_config_t mqtt_cfg = { .broker.address.uri = CONFIG_BROKER_URI, - .broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start, + .broker.verification.certificate = (const char *)isrg_root_x1_crt_start, }; ESP_LOGI(TAG, "[APP] Free memory: %" PRIu32 " bytes", esp_get_free_heap_size()); esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg); diff --git a/examples/wss/main/isrg_root_x1.crt b/examples/wss/main/isrg_root_x1.crt new file mode 100644 index 0000000..b85c803 --- /dev/null +++ b/examples/wss/main/isrg_root_x1.crt @@ -0,0 +1,31 @@ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw +TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh +cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4 +WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu +ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY +MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc +h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+ +0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U +A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW +T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH +B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC +B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv +KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn +OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn +jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw +qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI +rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV +HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq +hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL +ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ +3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK +NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5 +ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur +TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC +jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc +oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq +4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA +mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d +emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc= +-----END CERTIFICATE----- diff --git a/examples/wss/main/mqtt_eclipseprojects_io.pem b/examples/wss/main/mqtt_eclipseprojects_io.pem deleted file mode 100644 index 43b222a..0000000 --- a/examples/wss/main/mqtt_e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