基本知识

Server-side RPC

In order to subscribe to RPC commands from the server, send GET request with optional “timeout” request parameter to the following URL: 为了订阅RPC命令从服务端,需要发送get请求并加入可选的timeout参数,url如下:

  1. http(s)://host:port/api/v1/$ACCESS_TOKEN/rpc

Once subscribed, a client may receive rpc request or a timeout message if there are no requests to a particular device. An example of RPC request body is shown below:
一旦订阅了,客户端会rpc请求响应结果如下,或者超时。

  1. {
  2. "id": "1",
  3. "method": "setGpio",
  4. "params": {
  5. "pin": "23",
  6. "value": 1
  7. }
  8. }

where

  • id - request id, integer request identifier
  • method - RPC method name, string
  • params - RPC method params, custom json object

and can reply to them using POST request to the following URL:

  1. http://host:port/api/v1/$ACCESS_TOKEN/rpc/{$id}

where $id is an integer request identifier.

我们拼接以下url
curl -v -X GET http://www.vincentisme.com:8080/api/v1/TRU09Sr72OWYQv0DMmZN/rpc?timeout=20000

如果你是windows系统,请使用以下命令:
Invoke-WebRequest -v http://www.vincentisme.com:8080/api/v1/TRU09Sr72OWYQv0DMmZN/rpc?timeout=20000 -Method GET
执行命令之后,去tb上点击开关组件或者修改值的组件,会得到如下的响应。
image.png
image.png

以上就是http协议的服务器端rpc。。