Thingsboard 3.0 通过 tb-gateway 网关接入 MQTT 设备教程
原创
©著作权归作者所有:来自51CTO博客作者ThingsKit物联网平台的原创作品,请联系作者获取转载授权,否则将追究法律责任
TK物联网平台:ThingsKit物联网平台
本次演示环境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/tbinstall 和 https://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的默认端口
配置文件位置:

搜索
```go
listener.tcp.external =
找到后,将本行修改为:
listener.tcp.external = 127.0.0.1:1884
2、登录TB控制台,创建一个网关设备

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

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


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


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并配置

9、访问EMQ X
http://127.0.0.1:18083
帐号:admin
密码:public
如果配置正常,此时应该有个客户端接入了EMQ X,一个是MQTT box模拟的设备,一个是TB网关

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

11、使用MQTT Box向“/sensor/data”Topic发送以下测试数据
{"serialNumber": "SN-001", "sensorType": "Thermometer", "sensorModel": "T1000", "temp": 18, "hum": 11}

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

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

关注“云腾五洲”:获取二开ThingsBoard物联网平台演示

TK物联网平台:ThingsKit物联网平台