移植mosquitto到嵌入式linux平台

从上年接触MQTT开始,就有看到mosquitto,但未仔细了解过,初步认为是运行在服务器上的MQTT代理服务软件。这两天突然有个想法,想在ARM板上运行MQTT服务程序,用于各模块间的消息通信。

根据资料,发现mosquitto居然是个轻量级的MQTT服务程序,由MQTT协议创始人之一的Andy Stanford-Clark开发。许多人把它移植到了树莓派、ARM板上。

mosquitto介绍

官方网址:http://mosquitto.org/

官网简介:Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.

移植参考文章

移植过程

1. 下载源码,下载链接:http://mosquitto.org/files/source/,本人选择版本:1.4.15,理由是不选择最新版本,并且1.4.15版本是1.4版本最后发布的版本。

2. 修改config.mk

a) 文件开始地方增加如下:

# added by gyr 2019.03.13
CC=arm-linux-gnueabihf-gcc
CXX=arm-linux-gnueabihf-g++
CPP=arm-linux-gnueabihf-g++
AR=arm-linux-gnueabihf-ar
LD=arm-linux-gnueabihf-ld
DESTDIR=install_out

b) 在config.mk末尾:

STRIP定义改为如下:

STRIP?=arm-linux-gnueabihf-strip

prefix定义改为如下:

prefix=out

c) 去除一些选项,如不使用SSL等:

WITH_TLS:=no

WITH_TLS_PSK:=no

WITH_SRV:=no

WITH_UUID:=no

根据makefile,DESTDIR定义了执行make install时,mosquitto配置文件的安装路径,即位于mosquitto-1.4.15/install_out目录下

3. 编译:make && make install

编译出来的mosquitto、客户端、lib分别位于:

mosquitto-1.4.15/src/install_outout/sbin
mosquitto-1.4.15/client/install_outout/bin
mosquitto-1.4.15/lib/install_outout/lib

4. Error: Invalid user ‘mosquitto’.

把mosquitto-1.4.15/install_out/etc/mosquito/mosquitto.conf.example文件重命名为mosquitto.conf,并修改该文件,把其中#user mosquitto改为user root,root为板子登陆的用户名。再把该mosquitto.conf上传到板子上。

./mosquitto -c mosquitto.conf

通过-c选项指定mosquitto配置文件加载路径

./mosquitto -c mosquitto.conf

259604: mosquitto version 1.4.15 (build date 2019-03-13 22:19:05+0800) starting

259604: Config loaded from mosquitto.conf.

259604: Opening ipv4 listen socket on port 1883.

259604: Opening ipv6 listen socket on port 1883.

259604: Warning: Mosquitto should not be run as root/administrator.

这里有个Warning,经测试,可以忽略该Warning

5. 测试:

使用mosquitto_sub和mosquitto_pub进行测试

这两个程序需要用到mosquitto动态库,先导出该库的路径:

export LD_LIBRARY_PATH=/opt/app/mqtt/boker/lib

否则会出错:

./mosquitto_sub -v -t mqtt_test

./mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

订阅消息:

./mosquitto_sub -v -t mqtt_test

发布消息:

./mosquitto_pub -t mqtt_test -m “hello world ”

-t指定消息主题,-m指定消息内容

» 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
» 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
分享到:

  One Response to “移植MQTT服务端mosquitto到嵌入式linux平台”

  1. […] 创建于 2015-01-31*/ var cpro_id = "u1932930"; » 上一篇:   移植MQTT服务端mosquitto到嵌入式linux平台 » […]

Leave a Reply to 移植paho.mqtt.embedded-c到嵌入式linux平台 » reille blog Cancel reply

(必须)

(我会替您保密的)(必须)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

   
© 2012 velep.com | reille blog | 管理| 粤ICP备15065318号-2| 谷歌地图| 百度地图| Suffusion theme|Sayontan Sinha

无觅相关文章插件,快速提升流量