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

Posted iotschool

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的默认端口

配置文件位置:

技术图片

搜索

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 二次开发讨论群:121202538

以上是关于Thingsboard 3.0 通过 tb-gateway 网关接入 MQTT 设备教程的主要内容,如果未能解决你的问题,请参考以下文章

欢迎一起翻译thingsboard 中文文档,一起学习thingsboard物联网平台

如何通过 websocket 从 Thingsboard 检索所有客户设备的遥测数据

Python通过MQTT协议上传物联网数据给ThingsBoard

Python通过MQTT协议上传物联网数据给ThingsBoard

物联网平台thingsboard搭建学习记录

Thingsboard源码分析-MQTT设备连接协议(下)