简介
ThingsBoard 是一个开源的物联网平台,支持设备管理、数据可视化和规则引擎。 Modbus 是一种广泛应用于工业自动化领域的通信协议。 本页面介绍如何将 Modbus 设备接入 ThingsBoard,实现远程监控与数据上报。
准备工作
- 运行中的 ThingsBoard 实例(社区版或专业版)
- 支持 Modbus RTU/TCP 的设备
- 安装了 Java 运行环境(用于运行 ThingsBoard Gateway)
使用 ThingsBoard Gateway 接入 Modbus
推荐使用 ThingsBoard Gateway 作为中间件。
1. 安装 Gateway
pip3 install thingsboard-gateway
2. 配置 Modbus 连接(tb_gateway.yaml)
thingsboard:
host: YOUR_TB_HOST
port: 1883
accessToken: YOUR_DEVICE_ACCESS_TOKEN
modbus:
enabled: true
configuration: modbus.json
3. 创建 modbus.json 配置文件
{
"server": {
"type": "tcp",
"host": "192.168.1.100",
"port": 502,
"timeout": 3000,
"method": "socket"
},
"devices": [
{
"name": "Modbus Device 1",
"type": "default",
"attributes": [],
"timeseries": [
{
"tag": "temperature",
"functionCode": 3,
"address": 0,
"registerCount": 1,
"byteOrder": "BIG"
}
]
}
]
}
验证数据
启动 Gateway 后,登录 ThingsBoard 控制台,进入对应设备的“最新遥测”页面,即可看到从 Modbus 设备读取的数据。
常见问题
- 连接失败? 检查 Modbus 设备 IP、端口及防火墙设置。
- 数据不更新? 确认寄存器地址、功能码与设备手册一致。
- 字节序错误? 尝试修改
byteOrder为BIG或LITTLE。