MQTT初步使用

环境搭建

  1、mosquitto所需要的rpm包

  2、c-ares-1.12.0 

  3、安装最新的openssl版本

  4、mosquitto-1.4.10

mosquitto需要的rpm包

  

c-ares安装

c-ares源码下载

 

./buildconf    #提示libtoolize not found.  需要安装libtool,autoconf,automake
./configure
make
make install

用最新的openssl

编译mosquitto提示出错,‘EC_KEY’ undeclared 
代码不支持老的openssl,所以宏定义提示找不到。
使用openssl-OpenSSL_1_1_0.zip版本
 $ ./config
 $ make
 $ make install
代码不支持老的openssl,所以宏定义提示找不到。
使用openssl-OpenSSL_1_1_0.zip版本
其他程序会用到旧版的openssl,拷贝新的/usr/local/lib/libssl、/usr/local/lib/libcrypto到 /usr/lib/满足兼容

mosquitto使用

编译
make  binary    #只编译二进制文件,不编译man,否则会提示xml错误
src目录下生成mosquitto代理服务器
client目录下生成mosquitto_pub、mosquitto_sub 发布/订阅端。
编译出错一
1486548985: Error: Invalid user 'mosquitto'.  错误提示
编译出错二
warning: failed to load external entity "/usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl"
compilation error: file manpage.xsl line 3 element import
xsl:import : unable to load /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
compilation error: file mosquitto.8.xml line 4 element refentry
解决出错一
adduser mosquitto
解决出错二
yum install  docbook-style-xsl
修改 ./man/manpage.xsl第三行
href="/usr/share/sgml/docbook/xsl-stylesheets-1.75.2/manpages/docbook.xsl"/>

运行/client/mosquitto_pub -t sex -m woman 之后
mosquitto 代理端打印:
[root@localhost src]# ./mosquitto -v
1486549883: mosquitto version 1.4.10 (build date 2017-02-08 01:45:55-0800) starting
1486549883: Using default config.
1486549883: Opening ipv4 listen socket on port 1883.
1486549883: Opening ipv6 listen socket on port 1883.
1486550188: New connection from ::1 on port 1883.
1486550188: New client connected from ::1 as mosqpub/21894-localhost (c1, k60).
1486550188: Sending CONNACK to mosqpub/21894-localhost (0, 0)
1486550188: Received PUBLISH from mosqpub/21894-localhost (d0, q0, r0, m0, 'sex', ... (5 bytes))
1486550188: Received DISCONNECT from mosqpub/21894-localhost
1486550188: Client mosqpub/21894-localhost disconnected.
运行/client/mosquitto_sub -t sex  之后
mosquitto 代理端打印:
1486551115: New connection from ::1 on port 1883.
1486551115: New client connected from ::1 as mosqsub/21928-localhost (c1, k60).
1486551115: Sending CONNACK to mosqsub/21928-localhost (0, 0)
1486551115: Received SUBSCRIBE from mosqsub/21928-localhost
1486551115:     sex (QoS 0)
1486551115: mosqsub/21928-localhost 0 sex
1486551115: Sending SUBACK to mosqsub/21928-localhost
mosquitto_sub 端收到订阅的消息:
[root@localhost client]# ./mosquitto_sub -v -t sex
sex woman

待续

  .......

posted @ 2017-02-08 18:56  daiker  阅读(737)  评论(0编辑  收藏  举报