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

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


前言

本文主要介绍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示例。

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

yaml 复制代码
{
  "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

相关推荐
6***x5459 小时前
Java设计模式之策略模式
java·设计模式·策略模式
章鱼哥7309 小时前
Java 策略模式 + 聚合对象:实现多模块的统计与聚合,快速扩展的实战
java·开发语言·策略模式
h***59339 小时前
SpringBoot中如何手动开启事务
java·spring boot·spring
倚肆10 小时前
Java泛型详解:尖括号<>、通配符?与类型参数T
java
韩风66610 小时前
雪花id改多workerID依赖redis
java
BD_Marathon10 小时前
Eclipse 代码自动补全设置
android·java·eclipse
L.EscaRC10 小时前
深入解析SpringBoot中的循环依赖机制与解决方案
java·spring boot·spring·循环依赖
曾经的三心草10 小时前
JavaEE初阶-网络原理1
java·网络·java-ee
一 乐11 小时前
健身达人小程序|基于java+vue健身达人小程序的系统设计与实现(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·小程序
u***420712 小时前
Ubuntu介绍、与centos的区别、基于VMware安装Ubuntu Server 22.04、配置远程连接、安装jdk+Tomcat
java·ubuntu·centos