-
Notifications
You must be signed in to change notification settings - Fork 174
[mqtt_cxx]: Bump -> v0.5.0 #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
david-cermak
merged 5 commits into
espressif:master
from
david-cermak:bump/mqtt_cxx_0.5
Dec 11, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f9c6c1
fix(mqtt_cxx): Fix build job of mqtt_cxx examples
david-cermak d979e1b
fix(mqtt_cxx): Fix to construct in two steps
david-cermak f41c4a0
fix(mqtt_cxx): Implement simple unit tests
david-cermak 1cc2c97
fix(mqtt_cxx): Remove clang-tidy for mqtt-cxx as unsupported on latest
david-cermak 7ce85c7
bump(mqtt_cxx): 0.4.0 -> 0.5.0
david-cermak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| cmake_minimum_required(VERSION 3.5) | ||
|
|
||
|
|
||
| include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
| if(${IDF_TARGET} STREQUAL "linux") | ||
| set(EXTRA_COMPONENT_DIRS "../../../../common_components/linux_compat") | ||
| set(COMPONENTS main) | ||
| endif() | ||
|
|
||
| project(esp_mqtt_cxx_host_test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Test basic mqtt_cxx wrapper operations | ||
|
|
||
| ## Warning: Linux target not supported, this test works only on target | ||
|
|
||
| ## Example output | ||
| ``` | ||
| I (588) main_task: Started on CPU0 | ||
| I (598) main_task: Calling app_main() | ||
| Randomness seeded to: 374196253 | ||
| I (608) mqtt_client_cpp: MQTT_EVENT_BEFORE_CONNECT | ||
| E (618) esp-tls: [sock=54] delayed connect error: Connection reset by peer | ||
| E (618) transport_base: Failed to open a new connection: 32772 | ||
| E (618) mqtt_client: Error transport connect | ||
| I (618) mqtt_client_cpp: MQTT_EVENT_ERROR | ||
| E (628) mqtt_client_cpp: Last error reported from esp-tls: 0x8004 | ||
| E (628) mqtt_client_cpp: Last error captured as transport's socket errno: 0x68 | ||
| I (638) mqtt_client_cpp: Last errno string (Connection reset by peer) | ||
| I (648) mqtt_client_cpp: MQTT_EVENT_DISCONNECTED | ||
| =============================================================================== | ||
| All tests passed (6 assertions in 1 test case) | ||
|
|
||
| Test passed! | ||
| I (5658) main_task: Returned from app_main() | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| idf_component_register(SRCS "test_esp_mqtt_cxx.cpp" | ||
| WHOLE_ARCHIVE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| dependencies: | ||
| espressif/catch2: "^3.4.0" | ||
| esp_mqtt_cxx: | ||
| version: "*" | ||
| override_path: '../../../' |
92 changes: 92 additions & 0 deletions
92
components/esp_mqtt_cxx/test/unit/main/test_esp_mqtt_cxx.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #include "catch2/catch_session.hpp" | ||
| #include "catch2/catch_test_macros.hpp" | ||
| #include "esp_mqtt.hpp" | ||
| #include "esp_mqtt_client_config.hpp" | ||
| #include "esp_netif.h" | ||
|
|
||
| namespace mqtt = idf::mqtt; | ||
|
|
||
| namespace { | ||
| class TestClient final : public mqtt::Client { | ||
| public: | ||
| using mqtt::Client::Client; | ||
|
|
||
| bool constructed{false}; | ||
| bool before_connect{false}; | ||
| bool disconnected{false}; | ||
|
|
||
| TestClient(const mqtt::BrokerConfiguration &broker, const mqtt::ClientCredentials &credentials, const mqtt::Configuration &config) : | ||
| mqtt::Client(broker, credentials, config) | ||
| { | ||
| constructed = true; | ||
| } | ||
|
|
||
| private: | ||
| void on_connected(esp_mqtt_event_handle_t const event) override | ||
| { | ||
| CHECK(constructed); | ||
| } | ||
|
|
||
| void on_data(esp_mqtt_event_handle_t const event) override | ||
| { | ||
| CHECK(constructed); | ||
| } | ||
|
|
||
| void on_before_connect(esp_mqtt_event_handle_t const event) override | ||
| { | ||
| CHECK(constructed); | ||
| before_connect = true; | ||
| } | ||
|
|
||
| void on_disconnected(const esp_mqtt_event_handle_t event) override | ||
| { | ||
| CHECK(constructed); | ||
| disconnected = true; | ||
|
|
||
| } | ||
|
|
||
| }; | ||
| } // namespace | ||
|
|
||
| TEST_CASE("Client does not auto-start and can dispatch events after construction", "[esp_mqtt_cxx]") | ||
| { | ||
| mqtt::BrokerConfiguration broker{ | ||
| .address = mqtt::URI{std::string{"mqtt://127.0.0.1:1883"}}, | ||
| .security = mqtt::Insecure{} | ||
| }; | ||
| mqtt::ClientCredentials credentials{}; | ||
| mqtt::Configuration config{}; | ||
|
|
||
| TestClient client{broker, credentials, config}; | ||
|
|
||
| REQUIRE(client.is_started() == false); | ||
|
|
||
| // start the client and expect disconnection (reset by peer) | ||
| // since no server's running on this ESP32 | ||
| client.start(); | ||
| CHECK(client.is_started() == true); | ||
|
|
||
| CHECK(client.before_connect); | ||
| usleep(10000); | ||
| CHECK(client.disconnected); | ||
| } | ||
|
|
||
| extern "C" void app_main(void) | ||
| { | ||
| ESP_ERROR_CHECK(esp_netif_init()); | ||
| ESP_ERROR_CHECK(esp_event_loop_create_default()); | ||
|
|
||
| Catch::Session session; | ||
|
|
||
| int failures = session.run(); | ||
| if (failures > 0) { | ||
| printf("TEST FAILED! number of failures=%d\n", failures); | ||
| return; | ||
| } | ||
| printf("Test passed!\n"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| CONFIG_COMPILER_CXX_EXCEPTIONS=y | ||
| CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 | ||
| CONFIG_LWIP_PPP_SUPPORT=y | ||
| CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.