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

国内大神源码地址:https://github.com/guodaxia103/thingsboard-gateway

目前在国内有文章写出,Thingsboard Gateway是管理设备使用的,一个Thingsboard Gateway可以管理1000个设备,请参考:https://blog.csdn.net/Zzhou1990/article/details/100106995?tdsourcetag=s_pcqq_aiomsg

前提是Thingsboard开发环境搭建,请参考《Thingsboard开发环境搭建及编译项目》,因为Thingsboard Gateway也跟它相关

为了对Thingsboard有个概念,可以参考官方文档:https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/

下载源码,git bash命令

git clone https://github.com/guodaxia103/thingsboard-gateway

使用管理员身份打开命令行工具,并进入到项目目录

mvn clean install -Dmaven.test.skip=true

出现以下错误

E:\tb\thingsboard-gateway>mvn clean install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.thingsboard:gateway >-----------------------
[INFO] Building Thingsboard Gateway 2.3.-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.thingsboard.common:data:jar:2.4.-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.thingsboard:netty-mqtt:jar:2.4.-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.575 s
[INFO] Finished at: --26T13::+:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project gateway: Could not resolve dependencies for project org.thingsboard:gateway:jar:2.3.-SNAPSHOT: The following artifacts could not be resolved: org.thingsboard.common:data:jar:2.4.-SNAPSHOT, org.thingsboard:netty-mqtt:jar:2.4.-SNAPSHOT: Could not find artifact org.thingsboard.common:data:jar:2.4.-SNAPSHOT -> [Help ]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help ] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

错误截图

原因是Thingsboard Gateway依赖的Thingsboard的版本不匹配

解决方案参考官方Issue:https://github.com/thingsboard/thingsboard-gateway/issues/26#issuecomment-381832965

首先,我们已经有了Thingsboard的开发环境,查看一下Thingsboard版本,这里是2.3.1

修改Thingsboard Gateway源码中的pom.xml文件,记得也修改为2.3.1

再次尝试编译

等待几分钟最终编译成功

编译成功后,在源码的目录下会生成target文件夹,里面的文件即是打包好的结果

其中tb-gateway-windows.zip是针对Windows平台的安装包

目前的状态如下

启动Thingsboard(在运行Thingsboard Gateway前,假使你已经知道了Thingsboard平台是如何运行的,也已经正常的编译成功源代码了)

使用租户管理员,登陆到系统,并创建一个设备,并指定为网关

进入到设备的属性中,将Access Token复制出来备用

目前的状态如下

Windows尝试安装Thingsboard Gateway,首先解压文件

打开Thingsboard Gateway目录下conf配置文件

修改配置文件内容

就使用刚才编译代码时的管理员身份打开的命令行窗口

#进入到指定的目录
cd target\tb-gateway-windows\tb-gateway #安装网关服务
install.bat #开始网关服务
net start tb-gateway

运行截图

目前的状态如下

进入到Thingsboard,查看网关的最后遥测数据,只要出现以下参数变为0,即Thingsboard Gateway与Thingsboard平台已经连接上了

#All values should be set to “”(以下三个属性应该都是0)
devicesOnline:
attributesUploaded:
telemetryUploaded:

浏览器界面

目前的状态如下

尝试一下Thingsboard Gateway的功能先,首先使用最常用的MQTT协议

为了测试,我在本机也搭建了一个mosquitto环境,另外,也修改了mosquitto的端口为1884(找到文件C:\Program Files\mosquitto\mosquitto.conf,找到节点port 1883,将1883修改成1884,并将前面的#删除,重启mosquitto服务让配置生效)

官方参考配置文件地址:https://thingsboard.io/docs/iot-gateway/resources/mqtt-gui-extension-configuration.json

文件内容:

[
{
"id": "mqtt",
"type": "MQTT",
"configuration": {
"brokers": [
{
"host": "127.0.0.1",
"port": ,
"ssl": false,
"retryInterval": ,
"credentials": {
"type": "anonymous"
},
"mapping": [
{
"topicFilter": "sensors",
"converter": {
"type": "json",
"filterExpression": "$",
"deviceNameJsonExpression": "${$.serialNumber}",
"deviceTypeJsonExpression": "${$.model}",
"attributes": [
{
"type": "string",
"key": "model",
"value": "${$.model}"
}
],
"timeseries": [
{
"type": "double",
"key": "temperature",
"value": "${$.temperature}"
}
]
}
},
{
"topicFilter": "sensor/+/temperature",
"converter": {
"type": "json",
"filterExpression": "$",
"deviceNameTopicExpression": "(?<=sensor/)(.*?)(?=/temperature)",
"timeout": ,
"timeseries": [
{
"type": "double",
"key": "temperature",
"value": "${$.value}"
}
]
}
}
],
"connectRequests": [
{
"topicFilter": "sensors/connect",
"deviceNameJsonExpression": "${$.serialNumber}"
},
{
"topicFilter": "sensor/+/connect",
"deviceNameTopicExpression": "(?<=sensor/)(.*?)(?=/connect)"
}
],
"disconnectRequests": [
{
"topicFilter": "sensors/disconnect",
"deviceNameJsonExpression": "${$.serialNumber}"
},
{
"topicFilter": "sensor/+/disconnect",
"deviceNameTopicExpression": "(?<=sensor/)(.*?)(?=/disconnect)"
}
],
"attributeRequests": [
{
"topicFilter": "sensors/attributes",
"deviceNameJsonExpression": "${$.serialNumber}",
"attributeKeyJsonExpression": "${$.key}",
"requestIdJsonExpression": "${$.requestId}",
"clientScope": false,
"responseTopicExpression": "sensors/${deviceName}/attributes/${responseId}",
"valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
},
{
"topicFilter": "sensors/+/attributes/+/request/+",
"deviceNameTopicExpression": "(?<=sensors/)(.*?)(?=/attributes)",
"attributeKeyTopicExpression": "(?<=attributes/)(.*?)(?=/request)",
"requestIdTopicExpression": "(?<=request/)(.*?)($)",
"clientScope": false,
"responseTopicExpression": "sensors/${deviceName}/attributes/${attributeKey}/response/${requestId}",
"valueExpression": "${attributeValue}"
}
],
"attributeUpdates": [
{
"deviceNameFilter": ".*",
"attributeFilter": ".*",
"topicExpression": "sensor/${deviceName}/${attributeKey}",
"valueExpression": "{\"${attributeKey}\":\"${attributeValue}\"}"
}
],
"serverSideRpc": [
{
"deviceNameFilter": ".*",
"methodFilter": "echo",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"responseTopicExpression": "sensor/${deviceName}/response/${methodName}/${requestId}",
"responseTimeout": ,
"valueExpression": "${params}"
},
{
"deviceNameFilter": ".*",
"methodFilter": "no-reply",
"requestTopicExpression": "sensor/${deviceName}/request/${methodName}/${requestId}",
"valueExpression": "${params}"
}
]
}
]
}
}
]

进入到Thingsboard的网关中,查看配置,点击上传

将下载的json配置文件拖动到上传框,并点击上传

可以看到网关的状态为同步状态

查看其中的配置内容,请留意,现在的MQTT服务器是127.0.0.1,端口是1884,使用的就是本机安装mosquitto服务器

MQTTBox(下载地址:http://workswithweb.com/mqttbox.html

创建一个连接,直接连接到本机的mosquitto上

然后在MQTTBox上发布一条消息,点击发送

#主题
sensors
#消息体
{"serialNumber":"SN-001", "model":"T1000", "temperature":36.6}

刷新Thingsboard设备的列表,可以看到多了一个SN-001的设备

并且新加入的设置也是有遥测值的

新设备与网关进行了关联

如果需要设置设备在线或离线状态,需要发送主题sensor/设备编号/connect(离线,需要发送主题sensor/设备编号/disconnect

目前的状态如下

即然本地MQTT Broker是可以的,那么远程的MQTT Broker呢?是否可用呢

在Thingsboard中修改网关的MQTT设置,并保存

再次使用MQTTBox测试

在Thingsboard设备列表中又增加了SN-002的设备,且已经有了遥测值

提醒,这里提醒一下,Thingsboard Gateway需要与Thingsboard配套使用,如果版本不同,则无法进行处理

最终理想的状态

最新文章

  1. ABP理论之CSRF
  2. 《A Convolutional Neural Network Cascade for Face Detection》
  3. BZOJ1562——[NOI2009]变换序列
  4. 2014-2015-2 《Java程序设计》课程学生博客列表
  5. 30 分钟开发一个简单的 watchOS 2 app &lt;oneVcat&gt;
  6. [转]Rapid Reporter——轻量级ET测试记录工具
  7. attempting to bokeyaunrun eclipse useing the jre instead of jdk,to run eclipse using
  8. 采用SharePoint Designer将JavaScript而他们的网站页面集成的定义
  9. 函数响应式编程及ReactiveObjC学习笔记 (二)
  10. js中splice()的用法
  11. Greedy分饼干
  12. 【从零开始自制CPU之学习篇06】寄存器
  13. ganglia使用nagios告警
  14. GCP试用到期再申请
  15. 为你的 Hadoop 集群选择合适的硬件
  16. Linux——线程
  17. DWR组件——基于远程过程调用实现Ajax
  18. ubuntu14下搭建svn
  19. octomap的简介
  20. git and github问题集锦

热门文章

  1. 导出带图片的Excel——OOXML文件分析
  2. angularcli 第三篇(数据循环*ngFor、条件判断*ngIf)
  3. 私有容器镜像仓库harbor
  4. Maven01-maven打包Web项目成war文件-tomcat脱机运行启动项目
  5. MySQL延迟 查询主表
  6. 04 Spring的依赖注入
  7. CH6401 创世纪
  8. Centos7 安装谷歌浏览器
  9. 使用dos创建一个maven项目
  10. Selenium常用API的使用java语言之20-获取窗口截图