查询更新

优质
小牛编辑
126浏览
2023-12-01

OTA更新查询与下载

获取access_token

  • 终端设备
    终端设备直接接入OTA服务器应当使用Client Credentials模式,client_id为设备id,client_serect为设备令牌.
  • App接入
    如果终端设备无法直接接入OTA服务器,而通过App中转,那么App应当也使用Client Credentials模式,client_id为app_id,client_secret为app_secret.

注:

  • 1.获取access_token的具体方法请参考鉴权与授权页面.
  • 2.app_id和app_secret需要事先注册.

查询更新

查询设备最新的升级包的Api为

GET /api/v1/devices/${deviceId}/modules/${moduleName}/firmwares/${version}/type/${type}?access_token=${access_token}

参数如下:

参数含义备注
deviceId设备id设备Id唯一决定了一台设备,服务器将根据设备Id反查设备所设的产品信息
moduleName要进行升级的模块名
version设备模块当前的版本号
type升级类型如果为delta那么将返回差分升级信息,否则返回全量升级包
access_token鉴权令牌

 注: 该接口默认返回当前最新的升级包,版本号之间没有依赖关系,固件的前后关系按照发布的时间来确定,即晚发布的固件为新固件.

如果请求成功,将返回如下格式的json:

{
    "success": true,
    "code": 200,
    "message": "请求成功",
    "data": {
        "createdAt": "2019/11/13 19:57:07",
        "targetDeviceSn": "ai10000000000019",
        "targetModule": "gx8180",
        "type": "delta",
        "sourceVersion": "V1.0",
        "targetVersion": "V2.0",
        "size": 35,
        "sha1": "dc614ba32f6eb0e5d050d5d237d5ff5ed497d7eb",
        "href": "https://ai.nationalchip.com/api/v1/diffFirmwares/1/download"
    }
}

各字段含义如下:

参数含义备注
createdAt固件发布日期
targetDeviceSn更新包的目标设备id
type更新类型
sourceVersion更新包的原版本
targetVersion更新包目标版本若type非delta,则与sourceVersion保持一致
size更新包大小单位为字节
sha1更新包的sha1签名
href更新包的下载链接
filename更新包默认的文件名

下载更新

根据上文得到的href可以直接下载更新包二进制文件:

GET https://ai.nationalchip.com/api/v1/diffFirmwares/1/download?access_token=${access_token}