API详情——Viot协议转换接口
  liyizhang 2023年07月11日 664 0 云开发云云对接

Viot协议转换接口

请求参数

名称 说明 数据类型 长度 是否必选
originMfr 源厂商的名称即协议转换的其中一方平台名称。 String M
targetMfr 目标厂商的名称即协议转换的另一方平台名称。 String M
deviceType 设备类型。为设备的PID。 String M
deviceNo 设备序列号。可从小峰管家中获取设备的序列号。 String M
optType 操作类型。 String M
domain 转换目标iot域名 String M
url 请求url String M
paramObject 请求参数。具体参照API网站API详情 (jftech.com) JSONObject M
token 请求token String
methodEnum 请求方法。在“Post”与“Get”中选择,默认为“Post”。 String

请求格式

Content-Type: application/json; charset=UTF-8
Request URL: 
https://service:port/server/api/convert
Request Method: POST
Body Data: 
{
    "originMfr": "HUAWEI",
    "targetMfr": "JFTECH",
    "deviceType": "xxxxxxxxxxxxxxxxx", //设备类型
    "deviceNo": "xxxxxxxxxxxxxx", //设备序列号
    "optType": "powerSwitchOFF", //操作类型
    "domain": "/v1.0/iot-03/categories/kg/status", //域名
    "url": "xxxxxxxxxxxxxxx", //请求url
    "paramObject": { //请求参数
        "sn": " xxxxxxxxxxxxxx ",
        "Switch": "OFF"
    }
}

响应参数

名称 说明 数据类型 是否必选 示例
code 请求状态码 2000:成功 其他:失败 Int M 2000
msg 接口提示信息 String M success
data 接口响应数据 Object M
├─ Ret 设备响应状态码 Int M 100
├─retMsg 设备返回失败信息 String
├─ Props M
├─ ├─ poweSwitch 开关状态值:ON:表示开 OFF:表示关 String M ON

响应格式

Response:
{
    "code": 2000,
    "msg": "success",
    "data": {
        "Ret": 100,
        "props": [
            "powerSwitch"
        ]
    }
}

接口逻辑

  1. 参数通过ConvertController中的接口传入,ConvertController是接口传入的起始处。判断传入参数originMfr,targetMfr是否有效。若两厂商相同,则程序终止,并报错,展示"源厂商和目标厂商不能相同!"
  2. 若参数有效,则选取想转换协议的厂商名称,与传入参数一同传入PlatformIotRequestContext.dispatch()函数,进而传入AbstractPlatform.sendCommand()函数。
  3. 在AbstractPlatform.sendCommand()方法中,首先将传入参数convert(),进行协议转换。判断此设备协议是否已在redis缓存(RedisBaseProtocolRequestService)或数据库(CommonProtocolRequestService)中,若在,则直接调用convert()函数,利用BaseProtocolConvertService.resolve() 解析参数。若都不在,则手动转换协议。根据协议转换的方向,判断使用BaseProtocolConvertFactory里的transformTo()或transformFrom()函数。具体根据设备类型及操作类型,匹配相对应的协议。
  4. 若是协议转换失败,则程序终止,并报错。
  5. 若是协议转换成功,则验证token对应的设备是否在线。若设备不在线,则程序终止,并报错,展示“设备不在线”错误信息。若在线,则向设备发送请求,即可控制设备。
最后一次编辑于 2023年07月11日 0

暂无评论

推荐阅读
  liyizhang   2023年07月11日   537   0   0 spring boot
  liyizhang   2023年07月11日   536   0   0 spring boot
  luojiaxing   2023年07月11日   601   0   0 spring boot
  luojiaxing   2023年07月11日   855   0   0 spring boot