thingsboard-gateway使用modbus协议接入设备

thingsboard-gateway使用modbus协议接入设备

  • 前言
  • 1.modbus poll下载及配置
  • 2.修改tb_gateway.yaml
  • 3.修改modbus.json
  • 4.重启thingsboard-gateway服务


前言

本文主要介绍thingsboard-gateway使用modbus协议接入设备信息,使用thingsboard-gateway版本为2.5.5.2。
github仓库地址:https://github.com/thingsboard
文章建立在thingsboard以及tingsboard-gateway服务搭建好的基础上, 搭建thingsboard-gateway服务可以参考官方文档:http://www.ithingsboard.com/docs/iot-gateway/installation/
thingsboard-gateway使用modbus协议接入设备_第1张图片

1.modbus poll下载及配置

2.修改tb_gateway.yaml

tb_gateway.yaml示例。

connectors:
- configuration: modbus.json 
  name: Modbus
  type: modbus
storage:
  max_records_count: 100000
  read_records_count: 100 
  type: memory
thingsboard:
  host: 192.168.80.251  #thingsboard服务ip
  port: 1883			#thingsboard服务mqtt端口
  remoteConfiguration: false
  security:
    accessToken: 4vR9kMQrKom2xD9FgnkQ	#设备的访问令牌

3.修改modbus.json

{
  "master": {
    "slaves": [
      {
        "attributes": [],
        "byteOrder": "BIG",
        "wordOrder": "BIG",
        "connectAttemptCount": 5,
        "connectAttemptTimeMs": 5000,
        "waitAfterFailedAttemptsMs": 300000,
        "deviceName": "test-modbus1", #设备名称,可自定义
        "host": "192.168.80.251",	#modbus服务器ip
        "type": "tcp",
        "method": "socket",		
        "pollPeriod": 30000,	#数据获取间隔,单位ms
        "port": 5021,			#modbus服务器端口
        "retries": true,		
        "unitId": 10,			#对应modbus poll中的Slave ID
        "sendDataOnlyOnChange": false,	#只有数据发生改变才发送,此处填false
        "timeout": 35,
        "timeseries": [
          {
            "address": 1,	#对应modbus poll中的address
            "functionCode": 3,	#对应modbus poll中的function 03选项
            "objectsCount": 2,	#数据长度,2表示接收2个返回的字节
            "tag": "modbus",	#字段名,可自定义
            "type": "bytes"
          }
        ]
      },
      {
        "attributes": [],
        "byteOrder": "BIG",
        "wordOrder": "BIG",
        "connectAttemptCount": 5,
        "connectAttemptTimeMs": 5000,
        "waitAfterFailedAttemptsMs": 300000,
        "deviceName": "test-modbus2",
        "host": "192.168.80.251",
        "type": "tcp",
        "method": "socket",
        "pollPeriod": 30000,
        "port": 5021,
        "retries": true,
        "unitId": 17,
        "sendDataOnlyOnChange": false,
        "timeout": 35,
        "timeseries": [
          {
            "address": 11,
            "functionCode": 3,
            "objectsCount": 2,
            "tag": "modbus",
            "type": "bytes"
          }
        ]
      }
    ]
  }
}

4.重启thingsboard-gateway服务

重启:docker restart thingsboard-gateway

重启完成后thingsboard服务中会出现上面modbus.json中配置的设备,如果没有设备,说明环境有问题,查看日志:docker logs -t thingsboard-gateway

你可能感兴趣的:(thingsboard,java,modbus,java)