什么是 ThingsBoard 网关?
ThingsBoard 网关是一个开源组件,用于将本地设备(如 Modbus、OPC-UA、MQTT 客户端等)连接到 ThingsBoard IoT 平台。 它支持多种协议,并能将设备数据转换为统一格式上传至云端,同时支持远程配置和固件更新。
安装 ThingsBoard 网关
推荐在 Linux 或 Raspberry Pi 上使用 Python 版本的网关:
pip3 install thingsboard-gateway
安装完成后,配置文件通常位于 /etc/thingsboard-gateway/ 目录下。
基本配置步骤
- 编辑
tb_gateway.yaml文件,填入你的 ThingsBoard 服务器地址和访问令牌。 - 根据设备类型,在
configs/目录下启用对应的连接器(如modbus.json、mqtt.json)。 - 重启网关服务:
sudo systemctl restart thingsboard-gateway
示例:MQTT 连接器配置
在 configs/mqtt.json 中添加如下内容:
{
"broker": {
"host": "localhost",
"port": 1883,
"clientId": "ThingsBoardGateway"
},
"mapping": [
{
"topicFilter": "sensors/temperature",
"converter": {
"type": "json",
"deviceNameJsonExpression": "${$.deviceId}",
"deviceTypeJsonExpression": "Thermometer",
"timeout": 60000,
"attributes": [],
"timeseries": [
{
"key": "temperature",
"value": "${$.value}"
}
]
}
}
]
}
验证配置
启动网关后,查看日志确认是否成功连接:
journalctl -u thingsboard-gateway -f
若一切正常,你将在 ThingsBoard 平台上看到新设备自动注册并上报数据。