forked from boostorg/mqtt5
Add a build with CMake example to README and Introduction page
Summary: related to T13767 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D29243
This commit is contained in:
25
README.md
25
README.md
@@ -66,8 +66,7 @@ The following example illustrates a simple scenario of configuring a Client and
|
||||
int main() {
|
||||
boost::asio::io_context ioc;
|
||||
|
||||
using client_type = async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket>;
|
||||
client_type c(ioc);
|
||||
async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket> c(ioc);
|
||||
|
||||
c.credentials("<your-client-id>", "<client-username>", "<client-pwd>")
|
||||
.brokers("<your-mqtt-broker>", 1883)
|
||||
@@ -85,7 +84,27 @@ int main() {
|
||||
ioc.run();
|
||||
}
|
||||
```
|
||||
To see more examples, visit [Examples](https://spacetime.mireo.com/async-mqtt5/async_mqtt5/examples.html).
|
||||
To see more examples, visit [Examples](https://github.com/mireo/async-mqtt5/tree/master/example).
|
||||
|
||||
Building with CMake
|
||||
---------
|
||||
You can use the `CMakeLists.txt` provided in our repository to compile and run any of the [examples](https://github.com/mireo/async-mqtt5/tree/master/example) or your own source files.
|
||||
The following commands demonstrate compiling and running the previous code using CMake.
|
||||
The source file is located at [example/hello_world_over_tcp.cpp](https://github.com/mireo/async-mqtt5/blob/master/example/hello_world_over_tcp.cpp).
|
||||
|
||||
```console
|
||||
# navigate to the root folder of Async.MQTT5
|
||||
|
||||
# compile the example
|
||||
cmake -S . -B {build-folder} -DBUILD_EXAMPLES=ON -DCMAKE_EXE_LINKER_FLAGS="-pthread"
|
||||
cmake --build {build-folder}
|
||||
|
||||
# run the example
|
||||
./{build-folder}/example/example
|
||||
```
|
||||
|
||||
You can edit the [example/CMakeLists.txt](https://github.com/mireo/async-mqtt5/blob/master/example/CMakeLists.txt) file to compile the source file of your choice.
|
||||
By default, it will compile [example/hello_world_over_tcp.cpp](https://github.com/mireo/async-mqtt5/blob/master/example/hello_world_over_tcp.cpp).
|
||||
|
||||
When to use
|
||||
---------
|
||||
|
@@ -20,7 +20,7 @@
|
||||
[template indexterm1[term1] '''<indexterm><primary>'''[term1]'''</primary></indexterm>''']
|
||||
[template indexterm2[term1 term2] '''<indexterm><primary>'''[term1]'''</primary><secondary>'''[term2]'''</secondary></indexterm>''']
|
||||
|
||||
[template ghreflink[path text] [@https://github.com/mireo/async-mqtt5/[path] [text]]]
|
||||
[template ghreflink[path text] [@https://github.com/mireo/async-mqtt5/blob/master/[path] [text]]]
|
||||
[template reflink2[id text][link async_mqtt5.ref.[id] [^[text]]]]
|
||||
[template reflink[id][reflink2 [id] [id]]]
|
||||
[template refmem[class mem][reflink2 [class].[mem] [class]::[mem]]]
|
||||
|
@@ -45,7 +45,7 @@ In the event of a connection failure with one Broker, the Client switches to the
|
||||
|
||||
[heading Example]
|
||||
The following example illustrates a simple scenario of configuring a Client and publishing a
|
||||
"Hello World!" Application Message with `QoS` 0.
|
||||
"Hello World!" Application Message with `QoS` 0.
|
||||
|
||||
[!c++]
|
||||
#include <iostream>
|
||||
@@ -59,8 +59,7 @@ The following example illustrates a simple scenario of configuring a Client and
|
||||
int main() {
|
||||
boost::asio::io_context ioc;
|
||||
|
||||
using client_type = async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket>;
|
||||
client_type c(ioc);
|
||||
async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket> c(ioc);
|
||||
|
||||
c.credentials("<your-client-id>", "<client-username>", "<client-pwd>")
|
||||
.brokers("<your-mqtt-broker>", 1883)
|
||||
@@ -80,6 +79,23 @@ The following example illustrates a simple scenario of configuring a Client and
|
||||
|
||||
To see more examples, visit [link async_mqtt5.examples Examples].
|
||||
|
||||
[heading Building with CMake]
|
||||
You can use the `CMakeLists.txt` provided in our repository to compile and run any of the [link async_mqtt5.examples examples] or your own source files.
|
||||
The following commands demonstrate compiling and running the previous code using CMake.
|
||||
The source file is located at [ghreflink example/hello_world_over_tcp.cpp example/hello_world_over_tcp.cpp].
|
||||
|
||||
# navigate to the root folder of Async.MQTT5
|
||||
|
||||
# compile the example
|
||||
cmake -S . -B {build-folder} -DBUILD_EXAMPLES=ON -DCMAKE_EXE_LINKER_FLAGS="-pthread"
|
||||
cmake --build {build-folder}
|
||||
|
||||
# run the example
|
||||
./{build-folder}/example/example
|
||||
|
||||
You can edit the [ghreflink example/CMakeLists.txt example/CMakeLists.txt] file to compile the source file of your choice.
|
||||
By default, it will compile [ghreflink example/hello_world_over_tcp.cpp example/hello_world_over_tcp.cpp].
|
||||
|
||||
[heading When to use]
|
||||
|
||||
__Self__ might be suitable for you if any of the following statements is true:
|
||||
|
@@ -14,12 +14,12 @@ int main() {
|
||||
async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket> client(ioc);
|
||||
|
||||
// 1883 is the default TCP MQTT port.
|
||||
client.brokers("<your-mqtt-broker>", 1883)
|
||||
client.brokers("broker.hivemq.com", 1883)
|
||||
.async_run(boost::asio::detached);
|
||||
|
||||
client.async_publish<async_mqtt5::qos_e::at_most_once>(
|
||||
"<topic>", "Hello world!",
|
||||
async_mqtt5::retain_e::no, async_mqtt5::publish_props {},
|
||||
"async-mqtt5/test", "Hello world!",
|
||||
async_mqtt5::retain_e::yes, async_mqtt5::publish_props {},
|
||||
[&client](async_mqtt5::error_code ec) {
|
||||
std::cout << ec.message() << std::endl;
|
||||
client.async_disconnect(boost::asio::detached);
|
||||
|
Reference in New Issue
Block a user