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

2024-01-07 17:40:20


前言

本文主要介绍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/
在这里插入图片描述

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

文章来源:https://blog.csdn.net/weixin_47874230/article/details/135341037
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。