Install MQTT Client C Library
1 | apt update |
Test Demo
Edit src/sample/CMakeLists.txt:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40diff --git a/src/samples/CMakeLists.txt b/src/samples/CMakeLists.txt
index 79ea886..230599a 100644
--- a/src/samples/CMakeLists.txt
+++ b/src/samples/CMakeLists.txt
@@ -18,6 +18,7 @@
# Note: on OS X you should install XCode and the associated command-line tools
#
+cmake_minimum_required(VERSION 3.10)
INCLUDE_DIRECTORIES(
.
${CMAKE_SOURCE_DIR}/src
@@ -51,15 +52,15 @@ TARGET_LINK_LIBRARIES(MQTTClient_subscribe paho-mqtt3c)
TARGET_LINK_LIBRARIES(MQTTClient_publish paho-mqtt3c)
TARGET_LINK_LIBRARIES(MQTTClient_publish_async paho-mqtt3c)
-INSTALL(TARGETS paho_c_sub
- paho_c_pub
- paho_cs_sub
- paho_cs_pub
- MQTTAsync_subscribe
- MQTTAsync_publish
- MQTTClient_subscribe
- MQTTClient_publish
- MQTTClient_publish_async
-
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+#INSTALL(TARGETS paho_c_sub
+# paho_c_pub
+# paho_cs_sub
+# paho_cs_pub
+# MQTTAsync_subscribe
+# MQTTAsync_publish
+# MQTTClient_subscribe
+# MQTTClient_publish
+# MQTTClient_publish_async
+#
+# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Edit MQTTClient_publish_async.c and MQTTClient_subscribe.c:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21diff --git a/src/samples/MQTTClient_publish_async.c b/src/samples/MQTTClient_publish_async.c
index 7784349..57ef1ab 100644
--- a/src/samples/MQTTClient_publish_async.c
+++ b/src/samples/MQTTClient_publish_async.c
@@ -19,7 +19,7 @@
-
+
@@ -72,6 +72,8 @@ int main(int argc, char* argv[])
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
+ conn_opts.username = "username";
+ conn_opts.password = "passwd";
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
1 | diff --git a/src/samples/MQTTClient_subscribe.c b/src/samples/MQTTClient_subscribe.c |
Type the below command:1
2
3
4
5mkdir build
cd build
cmake ..
make
.MQTTClient_subscribe
Open another terminal:./MQTTClient_publish_async
- Result: