深圳设计网站排行,建设网站方法,app软件定制聚顶科技好,树莓派写wordpress#x1f308; 个人主页#xff1a;帐篷Li #x1f525; 系列专栏#xff1a;FastBee物联网开源项目 #x1f4aa;#x1f3fb; 专注于简单#xff0c;易用#xff0c;可拓展#xff0c;低成本商业化的AIOT物联网解决方案 目录 一、将java内置mqtt broker切换成EMQX5… 个人主页帐篷Li 系列专栏FastBee物联网开源项目 专注于简单易用可拓展低成本商业化的AIOT物联网解决方案 目录 一、将java内置mqtt broker切换成EMQX5.0
1.1 修改application.yml配置
1.2 使用docker-compose-emqx.yml进行部署
二、EMQX5.0配置
2.1 配置文件方式
2.2 控制台创建方式
2.2.1配置Http认证
2.2.2 配置设备上下线回调 一、将java内置mqtt broker切换成EMQX5.0
1.1 修改application.yml配置 1.2 使用docker-compose-emqx.yml进行部署
# 使用emqx版本mqtt broker输入该命令
sudo cp -rf docker-compose-emqx.yml docker-compose.yml
二、EMQX5.0配置
EMQX配置Http认证和Webhook处理客户端上下线有两种方式: 通过emqx.conf文件配置已有配置好的文件位于 docker/data/emqx/ect文件夹通过18083端口打开EMQX控制台创建客户端认证数据桥接和规则EMQX账号 控制台默认账号 (admin,public)docker-compose方式部署emqx.conf中配置的账号adminadmin123
注意
EMQX控制台修改的账号配置的Http认证、Webhook和规则会被emqx.conf中对应配置覆盖掉。官网解释如下
通过 Dashboard、HTTP API 或 CLI 进行的更改将在运行时写入 data/configs/cluster.hocon 文件并立即生效。如果相同的配置项在 etc/emqx.conf 文件中设置不同值则在重新启动后最终生效的是 etc/emqx.conf 中的配置。 为避免混淆强烈建议不要在 cluster.hocon 和 emqx.conf 中具有相同的配置键。
emqx.conf配置文件中存在任何规则设备消息转发的规则也要配置在emqx.conf中。
2.1 配置文件方式
下面内容复制到emqx.conf文件中
# 设置控制台端口和默认账号
dashboard {listeners.http {bind 18083}default_username admindefault_password admin123
}# http 认证
authentication [{mechanism password_basedbackend httpenable truemethod posturl http://177.7.0.13:8080/iot/tool/mqtt/authv5body {clientid ${clientid}username ${username}password ${password}peerhost ${peerhost}}headers {Content-Type application/jsonX-Request-Source EMQX}}
]# WebHook(匹配上线和下线规则后触发)
bridges {webhook.fastbee_hook {enable trueconnect_timeout 15sretry_interval 60spool_type randompool_size 8enable_pipelining 100max_retries 2request_timeout 15smethod posturl http://177.7.0.13:8080/iot/tool/mqtt/webhookv5body {\clientid\ : \${clientid}\,\event\ : \${event}\,\peername\ : \${peername}\}headers { accept application/json cache-control no-cache connection keep-alive content-type application/json keep-alive timeout5}}
}# 规则处理上线和下线
rule_engine {ignore_sys_message truejq_function_default_timeout 10srules.fastbee_rule {sql SELECT * FROM \t/#\,\$events/client_connected\, \$events/client_disconnected\, \$events/session_subscribed\actions [webhook:fastbee_hook]enable truedescription 处理设备上下线和订阅完主题的规则}
}
2.2 控制台创建方式
2.2.1配置Http认证 请求方式POST请求地址http://177.7.0.13:8080/iot/tool/mqtt/authv5 地址可以是内网或者外网确保能访问请求Body:
{clientid: ${clientid},password: ${password},username: ${username},peerhost: ${peerhost}
}
2.2.2 配置设备上下线回调
Webhook配置设置回调http接口 数据桥接名称fastbee_hook (随意填写)请求方式POST请求地址http://177.7.0.13:8080/iot/tool/mqtt/webhookv5 地址可以是内网或者外网确保能访问请求Body:
{clientid : ${clientid}, event : ${event}, peername : ${peername}}
创建规则让设备连接/断开连接/主题订阅完成时回调http api 规则名称fastbee_rule (随意填写)
SQL编辑器内容分别代表客户端连接/断开连接/主题订阅完成:
SELECT * FROM t/#,$events/client_connected, $events/client_disconnected, $events/session_subscribed
动作选择创建的数据桥接fastbee_hook