关于智能家居:智能家居开源生态智汀家庭云的WebSocket-API-消息定义

89次阅读

共计 1550 个字符,预计需要花费 4 分钟才能阅读完成。

WebSocket 是一种网络传输协定,可在单个 TCP 连贯上进行全双工通信,位于 OSI 模型的应用层。WebSocket 协定在 2011 年由 IETF 标准化为 RFC 6455,后由 RFC 7936 补充标准。

WebSocket 使得客户端和服务器之间的数据交换变得更加简略,容许服务端被动向客户端推送数据。在 WebSocket API 中,浏览器和服务器只须要实现一次握手,两者之间就能够创立持久性的连贯,并进行双向数据传输。本文次要跟大家分享一下智汀家庭云的 WebSocket API 音讯定义。

1. 音讯定义

通常,一个 WebSocket 音讯格局如下:

{
  "id": 1,
  "domain": "","service":"",
  "service_data": {"device_id": 1}
}

·id: 音讯 ID,必填,服务端会返回对应 ID 的后果

·domain: plugin 或者插件 id

  1. 设施相干命令

2.1 插件设施状态变更

{
  "type": "attribute_change",
  "identity": "2762071932",
  "instance_id": 2,
  "attr": {
    "attribute": "power",
    "val": "on",
    "val_type": "string"
  }
}

2.2 发现设施

申请:Request

{
  "id": 1,
  "service": "discover"
}

响应:Response

{
    "id": 1,
    "type": "","result": {"device": {"name":"zhiting_M1","identity":"hijklmn","model":"M1","manufacturer":"zhiting","plugin_id":"demo"}
    },
    "success": true
}

2.3 获取设施属性

申请:Request

{
  "id": 1,
  "domain": "zhiting",
  "service": "get_attributes",
  "identity": "2762071932"
}

响应:Response

{
  "id": 1,
  "result": {
    "identity": "2762071932",
    "device": {
      "name": "","identity":"2762071932","instances": [
        {
          "type": "light_bulb",
          "instance_id": 0,
          "attrs": [
            {
              "attribute": "power",
              "val": "on",
              "val_type": "string"
            },
            {
              "attribute": "brightness",
              "val": 55,
              "val_type": "int"
            },
            {
              "attribute": "color_temp",
              "val": 3500,
              "val_type": "int"
            }
          ]
        }
      ]
    }
  },
  "success": true
}

2.4 设置设施属性

申请:Request

{
  "id": 1,
  "domain": "zhiting",
  "service": "set_attributes",
  "identity": "2762071932",
  "service_data": {
    "attributes": [
      {
        "instance_id": 1,
        "attribute": "power",
        "val": "on"
      }
    ]
  }
}

响应:Response

{
  "id": 1,
  "type": "response",
  "success": true,
  "error": "error"
}

3. 装置插件

{
  "id": 1,
  "domain": "plugin",
  "service": "install",
  "service_data": {"plugin_id": "plugin_id"}
}
{
  "id": 1,
  "success": true
}

以上,感激大家观看,感兴趣的能够在评论区给小编留言哦。

正文完
 0