1、qt使用mqtt客户端
qmqtt相关库和头文件需要自己编译源码(源码下载地址https://github.com/emqx/qmqtt),编译后lib文件夹下的*.a文件即为库文件。
将源码下的所有头文件复制到一个文件夹,生成的库文件放在一个文件夹。
新项目直接包含头文件和库文件就可以使用qmqtt了。
2、emq服务器搭建(windows10)
命令行切换到emq目录,执行命令 emqttd start打开emq服务
D:\ProgramFiles\emqttd-windows10-v2.3.4\emqttd\bin>emqttd start
D:\ProgramFiles\emqttd-windows10-v2.3.4\emqttd>
用浏览器打开链接http://127.0.0.1:18083/#/
默认用户名:admin
默认密码:public
进入可视化界面
停止emq服务
D:\ProgramFiles\emqttd-windows10-v2.3.4\emqttd\bin>emqttd stop
3、启用用户名密码
(1)修改emq.conf文件,我的emq.conf文件路径为D:\ProgramFiles\emqttd-windows10-v2.3.4\emqttd\etc\emq.conf。里面有一个配置选项mqtt.allow_anonymous,其值为true时,则不作用户名密码验证,为false时,则进行用户名密码验证。我们要启用用户名密码验证,将默认的true改成false,如下图所示:
(2)设置默认用户名、密码
修改文件emq_auth_username.conf,我的路径为D:\ProgramFiles\emqttd-windows10-v2.3.4\emqttd\etc\plugins\emq_auth_username.conf,编辑用户名密码
##--------------------------------------------------------------------
## Username Authentication Plugin
##--------------------------------------------------------------------
## Examples:
##auth.user.1.username = admin
##auth.user.1.password = public
##auth.user.2.username = feng@emqtt.io
##auth.user.2.password = public
##auth.user.3.username = name~!@#$%^&*()_+
##auth.user.3.password = pwsswd~!@#$%^&*()_+
(3)启用插件
3、linux服务器搭建(CentOS7)
(1)安装unzip
yum -y install unzip
(2)下载emqx
wget https://www.emqx.io/downloads/broker/v4.0.3/emqx-centos7-v4.0.3.zip
(3)解压并移动到/usr/local目录下
unzip emqx-centos7-v4.0.3.zip && mv emqx/usr/local
(4)编辑系统环境配置
vi /etc/profile
(5)在末尾添加如下内容
# emqx
export EMQPATH=/usr/local/emqx
export PATH=$EMQPATH/bin:$PATH
(6)更新环境变量
source /etc/profile
(7)执行命令:emqx console检查安装和环境变量配置是否正常
[root@VM_16_7_centos ~]# emqx console
Exec: /usr/local/emqx/erts-10.5/bin/erlexec -boot /usr/local/emqx/releases/v4.0.3/emqx -mode embedded -boot_var ERTS_LIB_DIR /usr/local/emqx/erts-10.5/../lib -mnesia dir "/usr/local/emqx/data/mnesia/emqx@127.0.0.1" -config /usr/local/emqx/data/configs/app.2020.04.09.14.10.22.config -args_file /usr/local/emqx/data/configs/vm.2020.04.09.14.10.22.args -vm_args /usr/local/emqx/data/configs/vm.2020.04.09.14.10.22.args -start_epmd false -epmd_module ekka_epmd -proto_dist ekka -- console
Root: /usr/local/emqx
/usr/local/emqx
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:1:1] [ds:1:1:8] [async-threads:4] [hipe]
Starting emqx on node emqx@127.0.0.1
Start http:management listener on 8081 successfully.
Start http:dashboard listener on 18083 successfully.
Start mqtt:tcp listener on 127.0.0.1:11883 successfully.
Start mqtt:tcp listener on 0.0.0.0:1883 successfully.
Start mqtt:ws listener on 0.0.0.0:8083 successfully.
Start mqtt:ssl listener on 0.0.0.0:8883 successfully.
Start mqtt:wss listener on 0.0.0.0:8084 successfully.
EMQ X Broker 4.0.3 is running now!
Eshell V10.5 (abort with ^G)
(emqx@127.0.0.1)1>
(8)依次执行下面命令配置防火墙,开启端口
firewall-cmd --permanent --add-port=1883/tcp
firewall-cmd --permanent --add-port=18083/tcp
firewall-cmd --reload
(9)启动服务
emqx start
(10)查看emq当前状态
emqx_ctl status