Skip to content

Commit 072781f

Browse files
authored
Merge pull request #970 from david-cermak/bump/mqtt_cxx_0.5
[mqtt_cxx]: Bump -> v0.5.0
2 parents 7336451 + 7ce85c7 commit 072781f

File tree

15 files changed

+189
-17
lines changed

15 files changed

+189
-17
lines changed

.github/workflows/mqtt_cxx__build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
name: Build
1414
strategy:
1515
matrix:
16-
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3"]
16+
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5"]
1717
idf_target: ["esp32"]
18-
test: [ { app: mqtt-basic, path: "components/esp_mqtt_cxx/examples" }]
18+
test: [ { app: mqtt-basic, path: "components/esp_mqtt_cxx/examples" }, { app: test, path: "components/esp_mqtt_cxx/test/unit" }]
1919
runs-on: ubuntu-22.04
2020
container: espressif/idf:${{ matrix.idf_ver }}
2121
steps:
@@ -25,8 +25,7 @@ jobs:
2525
submodules: recursive
2626
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
2727
shell: bash
28-
working-directory: ${{matrix.test.path}}
2928
run: |
3029
. ${IDF_PATH}/export.sh
3130
pip install idf-component-manager idf-build-apps --upgrade
32-
python ../../../ci/build_apps.py ./${{ matrix.test.app }} --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
31+
python ./ci/build_apps.py ./${{ matrix.test.path }} --target ${{ matrix.idf_target }} -vv --preserve-all -c

components/esp_mqtt_cxx/.cz.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ commitizen:
33
bump_message: 'bump(mqtt_cxx): $current_version -> $new_version'
44
pre_bump_hooks: python ../../ci/changelog.py esp_mqtt_cxx
55
tag_format: mqtt_cxx-v$version
6-
version: 0.4.0
6+
version: 0.5.0
77
version_files:
88
- idf_component.yml

components/esp_mqtt_cxx/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [0.5.0](https://github.com/espressif/esp-protocols/commits/mqtt_cxx-v0.5.0)
4+
5+
### Bug Fixes
6+
7+
- Implement simple unit tests ([f41c4a0a](https://github.com/espressif/esp-protocols/commit/f41c4a0a))
8+
- Fix to construct in two steps ([d979e1b3](https://github.com/espressif/esp-protocols/commit/d979e1b3), [#631](https://github.com/espressif/esp-protocols/issues/631))
9+
- Add explicit dependency on esp-mqtt if needed ([3d5e11b8](https://github.com/espressif/esp-protocols/commit/3d5e11b8))
10+
311
## [0.4.0](https://github.com/espressif/esp-protocols/commits/mqtt_cxx-v0.4.0)
412

513
### Bug Fixes

components/esp_mqtt_cxx/esp_mqtt_cxx.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -163,7 +163,20 @@ Client::Client(esp_mqtt_client_config_t const &config) : handler(esp_mqtt_clien
163163
throw MQTTException(ESP_FAIL);
164164
};
165165
CHECK_THROW_SPECIFIC(esp_mqtt_client_register_event(handler.get(), MQTT_EVENT_ANY, mqtt_event_handler, this), mqtt::MQTTException);
166+
}
167+
168+
void Client::start()
169+
{
170+
if (started) {
171+
return;
172+
}
166173
CHECK_THROW_SPECIFIC(esp_mqtt_client_start(handler.get()), mqtt::MQTTException);
174+
started = true;
175+
}
176+
177+
bool Client::is_started() const noexcept
178+
{
179+
return started;
167180
}
168181

169182
void Client::mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) noexcept

components/esp_mqtt_cxx/examples/ssl/main/mqtt_ssl_example.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ extern "C" void app_main(void)
8383
idf::mqtt::Configuration config{};
8484

8585
MyClient client{broker, credentials, config};
86+
client.start();
8687
while (true) {
8788
constexpr TickType_t xDelay = 500 / portTICK_PERIOD_MS;
88-
vTaskDelay( xDelay );
89+
vTaskDelay(xDelay);
8990
}
9091
}

components/esp_mqtt_cxx/examples/tcp/main/mqtt_tcp_example.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern "C" void app_main(void)
7878
mqtt::Configuration config{};
7979

8080
MyClient client{broker, credentials, config};
81+
client.start();
8182

8283
while (true) {
8384
constexpr TickType_t xDelay = 500 / portTICK_PERIOD_MS;

components/esp_mqtt_cxx/idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.4.0"
1+
version: "0.5.0"
22
description: C++ APIs for ESP-MQTT library
33
url: https://github.com/espressif/esp-protocols/tree/master/components/esp_mqtt_cxx
44
issues: https://github.com/espressif/esp-protocols/issues
@@ -8,7 +8,7 @@ dependencies:
88
espressif/esp-idf-cxx: "^1.0.0-beta"
99
# Required IDF version
1010
idf:
11-
version: ">=5.0"
11+
version: ">=5.0,<6.0"
1212
espressif/mqtt:
1313
rules:
1414
- if: idf_version >=6.0

components/esp_mqtt_cxx/include/esp_mqtt.hpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -165,6 +165,19 @@ class Client {
165165
*/
166166
Client(const esp_mqtt_client_config_t &config);
167167

168+
/**
169+
* @brief Start the underlying esp-mqtt client
170+
*
171+
* Must be called after the derived class has finished constructing to avoid
172+
* events being dispatched to partially constructed objects.
173+
*/
174+
void start();
175+
176+
/**
177+
* @brief Check whether start() has been called
178+
*/
179+
[[nodiscard]] bool is_started() const noexcept;
180+
168181
/**
169182
* @brief Subscribe to topic
170183
*
@@ -245,13 +258,13 @@ class Client {
245258
*/
246259
virtual void on_error(const esp_mqtt_event_handle_t event);
247260
/**
248-
* @brief Called if there is an disconnection event
261+
* @brief Called if there is a disconnection event
249262
*
250263
* @param event mqtt event data
251264
*/
252265
virtual void on_disconnected(const esp_mqtt_event_handle_t event);
253266
/**
254-
* @brief Called if there is an subscribed event
267+
* @brief Called if there is a subscribed event
255268
*
256269
* @param event mqtt event data
257270
*/
@@ -263,26 +276,26 @@ class Client {
263276
*/
264277
virtual void on_unsubscribed(const esp_mqtt_event_handle_t event);
265278
/**
266-
* @brief Called if there is an published event
279+
* @brief Called if there is a published event
267280
*
268281
* @param event mqtt event data
269282
*/
270283
virtual void on_published(const esp_mqtt_event_handle_t event);
271284
/**
272-
* @brief Called if there is an before connect event
285+
* @brief Called if there is a before connect event
273286
*
274287
* @param event mqtt event data
275288
*/
276289
virtual void on_before_connect(const esp_mqtt_event_handle_t event);
277290
/**
278-
* @brief Called if there is an connected event
291+
* @brief Called if there is a connected event
279292
*
280293
* @param event mqtt event data
281294
*
282295
*/
283296
virtual void on_connected(const esp_mqtt_event_handle_t event) = 0;
284297
/**
285-
* @brief Called if there is an data event
298+
* @brief Called if there is a data event
286299
*
287300
* @param event mqtt event data
288301
*
@@ -292,5 +305,6 @@ class Client {
292305
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id,
293306
void *event_data) noexcept;
294307
void init(const esp_mqtt_client_config_t &config);
308+
bool started{false};
295309
};
296310
} // namespace idf::mqtt
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
4+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
5+
if(${IDF_TARGET} STREQUAL "linux")
6+
set(EXTRA_COMPONENT_DIRS "../../../../common_components/linux_compat")
7+
set(COMPONENTS main)
8+
endif()
9+
10+
project(esp_mqtt_cxx_host_test)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Test basic mqtt_cxx wrapper operations
2+
3+
## Warning: Linux target not supported, this test works only on target
4+
5+
## Example output
6+
```
7+
I (588) main_task: Started on CPU0
8+
I (598) main_task: Calling app_main()
9+
Randomness seeded to: 374196253
10+
I (608) mqtt_client_cpp: MQTT_EVENT_BEFORE_CONNECT
11+
E (618) esp-tls: [sock=54] delayed connect error: Connection reset by peer
12+
E (618) transport_base: Failed to open a new connection: 32772
13+
E (618) mqtt_client: Error transport connect
14+
I (618) mqtt_client_cpp: MQTT_EVENT_ERROR
15+
E (628) mqtt_client_cpp: Last error reported from esp-tls: 0x8004
16+
E (628) mqtt_client_cpp: Last error captured as transport's socket errno: 0x68
17+
I (638) mqtt_client_cpp: Last errno string (Connection reset by peer)
18+
I (648) mqtt_client_cpp: MQTT_EVENT_DISCONNECTED
19+
===============================================================================
20+
All tests passed (6 assertions in 1 test case)
21+
22+
Test passed!
23+
I (5658) main_task: Returned from app_main()
24+
```

0 commit comments

Comments
 (0)