thingsboard-gateway 上送共享属性
时间: 2023-09-21 22:09:09 浏览: 159
ThingsBoard Gateway 是一个用于将设备数据上传到 ThingsBoard IoT 平台的工具,它支持多种设备和协议,并提供了灵活的配置选项。要上送共享属性,需要在 Gateway 的配置文件中进行相关配置。
首先,在 `thingsboard-gateway/config/tb_gateway.yaml` 文件中添加以下内容:
```
# 配置共享属性
shared_attributes:
- attribute1
- attribute2
```
在上述配置中,`shared_attributes` 表示要上送的共享属性列表,可以根据需要添加或删除属性。然后,在 `thingsboard-gateway/config/devices.yaml` 文件中为设备配置共享属性:
```
devices:
- name: my_device
type: mqtt
...
attributes:
shared:
attribute1: 10
attribute2: true
```
在上述配置中,`attributes` 表示设备的属性列表,`shared` 表示要共享的属性,其中 `attribute1` 和 `attribute2` 分别表示要共享的属性名称,可以根据需要自定义属性名称和属性值。
完成上述配置后,ThingsBoard Gateway 将自动将共享属性上送到 ThingsBoard IoT 平台,可以在平台上查看设备的共享属性。
相关问题
thingsboard-gateway 连接thinsboard平台
### 配置 ThingsBoard Gateway 连接到 ThingsBoard 平台
#### 安装 ThingsBoard IoT Gateway
为了安装并运行 ThingsBoard IoT Gateway 作为守护进程,可以使用如下命令来完成软件包的安装:
```bash
sudo apt install ./python3-thingsboard-gateway.deb -y
```
这一步骤会自动处理依赖关系并将服务注册为系统的启动项[^1]。
#### 修改配置文件
在成功安装之后,需要编辑 `tb_gateway.yaml` 文件来进行基本设置。该文件通常位于 `/etc/thingsboard/gateway/` 目录下。主要修改部分涉及连接到云端的信息以及网关的工作模式等参数。
对于 Modbus Slave 设备来说,在同一目录下的 `extensions/modbus.json` 中定义了具体的协议细节和映射规则。这里有几个重要的字段用于指定如何解析来自 Modbus 的数据并向 ThingsBoard 发送相应的属性更新请求:
- **tag**: 如 "certificateNumber", 表明此条目对应的设备属性名称。
- **type**: 数据类型的声明, 比如整数类型 "32int".
- **functionCode**: 使用的功能码, 像读取寄存器的操作代码 "4".
- **objectsCount**: 单次查询返回的最大对象数量.
- **address**: 开始读取的位置偏移量.
以下是示例 JSON 片段展示了一个典型的 Modbus 连接器配置方式[^2]:
```json
{
"server": {
"host": "localhost",
"port": 502,
"mode": "tcp"
},
"devices": [
{
"name": "Modbus Device Example",
"attributesPollingInterval": 5000,
"timeseriesPollingInterval": 5000,
"extensionConfiguration": "./modbus-config.json"
}
]
}
```
在此基础上还需要创建或调整 `./modbus-config.json`, 添加具体要监控的寄存器及其对应于 ThingsBoard 属性的名字和其他必要选项。
#### 启动与验证
最后一步就是重启 ThingsBoard Gateway 使新的配置生效,并通过查看日志确认一切正常工作。如果遇到任何问题,则应检查上述提到的各项设定是否正确无误。
```bash
sudo systemctl restart thingsboard-gateway.service
journalctl -u thingsboard-gateway.service --follow
```
阅读全文
相关推荐
















