概述
1. MQTT客户端C代码库
- C语言库:https://github.com/eclipse/paho.mqtt.c
1.1 C源码下载构建
# centos7 OS 方法一
$ git clone https://github.com/eclipse/paho.mqtt.c.git
$ cd paho.mqtt.c
$ make
$ sudo make install
# make help查看当前Makefile支持命令
# make package 构造安装包压缩目录,解压缩后是生成项目链接库
mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
mkdir -p /usr/local/include
install -m 644 build/output/libpaho-mqtt3c.so.1.3 /usr/local/lib
install -m 644 build/output/libpaho-mqtt3cs.so.1.3 /usr/local/lib
install -m 644 build/output/libpaho-mqtt3a.so.1.3 /usr/local/lib
install -m 644 build/output/libpaho-mqtt3as.so.1.3 /usr/local/lib
install build/output/paho_c_version /usr/local/bin
install build/output/samples/paho_c_pub /usr/local/bin
install build/output/samples/paho_c_sub /usr/local/bin
install build/output/samples/paho_cs_pub /usr/local/bin
install build/output/samples/paho_cs_sub /usr/local/bin
/sbin/ldconfig /usr/local/lib
ln -s libpaho-mqtt3c.so.1 /usr/local/lib/libpaho-mqtt3c.so
ln -s libpaho-mqtt3cs.so.1 /usr/local/lib/libpaho-mqtt3cs.so
ln -s libpaho-mqtt3a.so.1 /usr/local/lib/libpaho-mqtt3a.so
ln -s libpaho-mqtt3as.so.1 /usr/local/lib/libpaho-mqtt3as.so
install -m 644 src/MQTTAsync.h /usr/local/include
install -m 644 src/MQTTClient.h /usr/local/include
install -m 644 src/MQTTClientPersistence.h /usr/local/include
install -m 644 src/MQTTProperties.h /usr/local/include
install -m 644 src/MQTTReasonCodes.h /usr/local/include
install -m 644 src/MQTTSubscribeOpts.h /usr/local/include
install -m 644 src/MQTTExportDeclarations.h /usr/local/include
install -m 644 doc/man/man1/paho_c_pub.1 /usr/local/share/man/man1
install -m 644 doc/man/man1/paho_c_sub.1 /usr/local/share/man/man1
install -m 644 doc/man/man1/paho_cs_pub.1 /usr/local/share/man/man1
install -m 644 doc/man/man1/paho_cs_sub.1 /usr/local/share/man/man1
#方法二,cmake指定构建安装目录,作为第三方动态链接库
#将项目目录下载到/root下面,同时指定生成目标安装位置为/root/mqtt
mkdir -p root/mqtt/build
cd /root/mqtt/
cmake -DCMAKE_INSTALL_PREFIX="/root/mqtt" ../paho.mqtt.c
make
make install
编译成功后,生成4个二进制可执行文件,paho_c_pub paho_c_sub paho_cs_pub paho_cs_sub。c表示客户端,pub表示发布,sub表示订阅,cs表示安全openssl。还有4个动态链接库
libpaho-mqtt3a.so - asynchronous (MQTTAsync)
libpaho-mqtt3as.so - asynchronous with SSL (MQTTAsync)
libpaho-mqtt3c.so - "classic" / synchronous (MQTTClient)
libpaho-mqtt3cs.so - "classic" / synchronous with SSL (MQTTClient)
1.2 C客户端可执行文件使用
- 可执行文件
命令行使用可参考 https://modelbasedtesting.co.uk/2018/08/08/paho-c-client-mqtt-5-0-and-command-line-utilities/
paho_c_sub -t topic -h 127.0.0.1 -p 1883 -q 2
paho_c_pub -t topic -h 127.0.0.1 -q 2 -m "hello,user"
2. MQTT客户端Golang代码库
- Golang语言库:https://github.com/eclipse/paho.mqtt.golang
官方示例:在官方库中存在样本,例如paho.mqtt.golang库示例在paho.mqtt.golang/cmd目录中,可以编译参考
2.1 GO客户端API
//安装go mqtt客户端
go get github.com/eclipse/paho.mqtt.golang
go get github.com/gorilla/websocket
go get golang.org/x/net/proxy
//引入mqtt 客户端的API
import "github.com/eclipse/paho.mqtt.golang"
2.2 GO客户端API
-
客户端go函数使用解释 https://www.cnblogs.com/veviDP/p/8900748.html
-
MQTT非官方中文API手册 https://www.jianshu.com/p/05914c15b9a8
最后
以上就是鲜艳小霸王为你收集整理的MQTT客户端paho.mqtt.XXX的全部内容,希望文章能够帮你解决MQTT客户端paho.mqtt.XXX所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复