---
# System prepended metadata

title: TB Gateway Custom Server Side RPC
tags: [ThingsBoard, ' ThingsBoard Gateway', ' RPC']

---

---
title: TB Gateway Custom Server Side RPC
tags: ThingsBoard, ThingsBoard Gateway, RPC
---

## 透過 TB Gateway 新增自訂 RPC 設定

### MQTT

1. 於 /etc/thingsboard-gateway/config/mqtt.json 新增自訂的 RPC

```
"serverSideRpc": [

...

    {
      "deviceNameFilter": "shellyem.*", // shellyem- 開頭的 device 皆適用
      "methodFilter": "info", // RPC method 名稱
      "requestTopicExpression": "shellies/${deviceName}/command", // Publish Topic
      "valueExpression": "announce" // publish 的內容
    }
]
```
* 此為 oneway RPC 設定，若需 twoway，則加上
```
responseTopicExpression: "response/topic",  // Subscribe Topic
responseTimeout: 10000
```


2. 使用 RPC API `POST - /api/rpc/oneway/{deviceId}` || `POST - /api/rpc/twoway/{deviceId}`
```
{
    "method": "info"
}
```

## Issue

* 反應時間過久 ( 約 6 s )