Thingsboard 3.0 通过 tb-gateway 网关接入 MQTT 设备教程

本次演示环境Windows 10,TB版本为Thingsboard 3.0,Thingsboard-gateway版本为2.3.1.1,采用EMQ X作为MQTT broker,用MQTT box作为演示设备。

环境准备:

  • thingsboard3.0源码安装

下载地址:https://github.com/thingsboard/thingsboard/releases

教程:https://www.iotschool.com/wiki/tbinstallhttps://www.iotschool.com/topics/732

  • 安装thingsboard-gateway2.3.1.1,特别说明:本地运行TB-gateway需要安装Python3.5以上的环境才能运行

下载地址:https://github.com/thingsboard/thingsboard-gateway/releases

教程:https://thingsboard.io/docs/iot-gateway/install/source-installation/

  • 安装EMQ X

下载地址:https://github.com/emqx/emqx/releases

教程:https://docs.emqx.io/broker/latest/cn/getting-started/install.html##zip

  • 安装MQTT Box

下载地址:https://www.iotschool.com/topics/553

教程:往后看

一切准备就绪,现在开始

1、由于TB默认占用了1883端口,所以需要更改EMQ X的默认端口

配置文件位置:

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

搜索

listener.tcp.external =

找到后,将本行修改为:

listener.tcp.external = 127.0.0.1:1884

2、登录TB控制台,创建一个网关设备

iotschool

3、复制网关设备的访问令牌

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

4、将复制的令牌写入到网关下面的tb_gateway.yaml文件中的accessToken字段后面

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

iotschool

5、配置网关下面的mqtt.json文件

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

6、重启EMQ X,如果已启动,需要先停止再启动,命令参考:

https://docs.emqx.io/broker/latest/cn/getting-started/install.html##zip

7、启动网关,启动教程请参考

https://thingsboard.io/docs/iot-gateway/install/source-installation/

8、启动MQTT Box并配置

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

9、访问EMQ X

http://127.0.0.1:18083
帐号:admin
密码:public

如果配置正常,此时应该有个客户端接入了EMQ X,一个是MQTT box模拟的设备,一个是TB网关

10、登录TB控制台,刷新设备列表,目前只有我们刚刚创建的网关设备

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

11、使用MQTT Box向“/sensor/data”Topic发送以下测试数据

{"serialNumber": "SN-001", "sensorType": "Thermometer", "sensorModel": "T1000", "temp": 18, "hum": 11}

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

12、切回TB控制台,刷新设备列表会自动增加一台设备

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

13、点击最新遥测,会看到我们刚刚同步上来的信息

Thingsboard 3.0 通过tb-gateway网关接入MQTT 设备教程

thingsboard交流QQ群 121202538

欢迎大家加入thingsboard 二次开发讨论群:121202538

原文地址:https://www.cnblogs.com/iotschool/p/13065330.html