[关闭]
@soszrg 2018-11-15T06:49:27.000000Z 字数 4074 阅读 857

OTA接口文档

anxin

服务器地址

  1. http://121.40.214.215:8000

token格式

  1. Authorization: token d79be1d657d9a8b45f6f903620e84b06cbf225e0
  1. 获取oss token(token)

前端用OTA接口


获取oss token(token)

接口地址

GET /oss_token/ota/

请求参数

返回参数

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"oss token"
  5. },
  6. "data":{
  7. "accessid":"wHQNXGL...",
  8. "host":"https://mxchip-fog.oss...",
  9. "policy":"eyJleHBpcmF0aW9uIjog...",
  10. "signature":"gXOilR99=...",
  11. "expire":1541665617,
  12. "dir":"ota/",
  13. "callback":"eyJjYWxsYm..."
  14. }
  15. }

返回参数说明


上传OTA固件(Token)

POST /api/v1/ota/[product_id]/files/

请求参数

参数名 类型 必须 说明
file_name string 固件名
file_url string 固件地址
md5 string 固件的MD5值
size string 固件大小
ug_type int OTA类型:0 mcu升级(默认类型);1 wifi升级
version string 固件版本
description string 固件描述
mac_range string list 要升级的MAC地址范围
customize string 用户自定义字段

返回值

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"upload file ok"
  5. },
  6. "data":{
  7. "id":1,
  8. "product":"test",
  9. "ota_type":0,
  10. "file_name":"ota.bin",
  11. "file_url":"https://xxx.com/a.bin",
  12. "size":"20kb",
  13. "md5":"gzsf12jkiu...",
  14. "version":"1.0.1",
  15. "mac_range":null,
  16. "customize":"xxx",
  17. "created_at":"2018-11-13T22:34:47",
  18. "updated_at":"2018-11-13T22:34:47",
  19. "description":'',
  20. "status":0,
  21. "is_delete":false,
  22. "extra":{
  23. }
  24. }
  25. }

返回值说明

字段 类型 说明
id int 固件ID,固件唯一标识,用于后续固件的修改和删除等
status int 文件当前状态:0 测试,1 上线,2 无效

错误码

错误代码 错误说明
10000 参数错误:缺少product参数

固件列表(Token)

GET /api/v1/ota/[product_id]/files/

返回值

  1. {
  2. "meta":{
  3. "message":"info list",
  4. "code":0
  5. },
  6. "data":{
  7. "count":1,
  8. "page_size":10,
  9. "next":null,
  10. "previous":null,
  11. "results":[
  12. {
  13. "id":1,
  14. "product":"test",
  15. "ota_type":0,
  16. "file_name":"ota.bin",
  17. "file_url":"https://a.com/a.bin",
  18. "size":"20kb",
  19. "md5":"f6hk9vgc4...",
  20. "version":"1.0.1",
  21. "mac_range":null,
  22. "customize":"xxxx",
  23. "created_at":"2018-11-13T22:34:47",
  24. "updated_at":"2018-11-13T22:34:47",
  25. "description":"",
  26. "status":0,
  27. "is_delete":false,
  28. "extra":{
  29. }
  30. }
  31. ]
  32. }
  33. }

错误码

错误代码 错误说明
10000 参数错误:缺少product参数

固件详细信息(Token)

GET /api/v1/ota/[product_id]/files/[id]

请求参数

参数名 类型 必须 说明
id int 固件id(该参数放于url中)

返回值

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"file info"
  5. },
  6. "data":{
  7. "id":1,
  8. "product":"test",
  9. "ota_type":0,
  10. "file_name":"ota.bin",
  11. "file_url":"https://a.com/a.bin",
  12. "size":"20kb",
  13. "md5":"abki2lnb...",
  14. "version":"1.0.1",
  15. "mac_range":null,
  16. "customize":"xxxx",
  17. "created_at":"2018-11-13T22:34:47",
  18. "updated_at":"2018-11-13T22:34:47",
  19. "description":"",
  20. "status":0,
  21. "is_delete":false,
  22. "extra":{
  23. }
  24. }
  25. }

错误码

错误代码 错误说明
10000 参数错误:参考Response中的message

删除单个固件(Token)

DELETE /api/v1/ota/[product_id]/files/[id]

请求参数

参数名 类型 必须 说明
id int 固件ID(该参数放于url)

返回值

  1. {
  2. "meta":{
  3. "message":"任务删除成功",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":null
  8. }
  9. }

错误码

错误代码 错误说明
10000 参数错误:参考Response中的message
10500 ot_id错误,找不到任务
10501 任务状态错误:仅有测试中的任务可以删除

修改固件信息(Token)

PUT /api/v1/ota/[product_id]/files/[id]

请求参数

参数名 类型 必须 说明
ot_id int 任务ID(拼接于url中)
file_url string 固件地址
version string 固件版本(同一产品下不可重复)
md5 string 固件的MD5值
size string 固件大小
file_name string 固件名
description string 任务描述
mac_range string list 要升级的MAC地址范围

返回值

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"update file ok"
  5. },
  6. "data":{
  7. "ota_type":0,
  8. "file_name":"ota.bin",
  9. "file_url":"https://xxx.com/a.bin",
  10. "size":"20kb",
  11. "md5":"fg2bz4...",
  12. "version":"1.0.1",
  13. "mac_range":[
  14. "DEF1LUK",
  15. "DEF1L2G"
  16. ],
  17. "extra":{
  18. }
  19. }
  20. }

错误码

错误代码 错误说明
10000 参数错误:参考Response中的message

设备端接口


设备检查OTA

GET /api/v1/ota/device/

请求参数

参数名 类型 必须 说明
product_id string 产品id
wifi_version string wifi当前版本号
mcu_version string mcu当前版本号

注意:

  1. http://121.40.214.215:8000/api/v1/ota/devce/?product_id=xxx&wifi_version=xxx&mcu_version=xxx

返回值

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"ota file info"
  5. },
  6. "data":{
  7. "need_ota":true,
  8. "files":[
  9. {
  10. "file_url":"https://xxx.com/mcu.bin",
  11. "md5":"xxzz...",
  12. "version":"1.0.1",
  13. "ota_type":0,
  14. "customize":""
  15. },
  16. {
  17. "file_url":"https://xxx.com/wifi.bin",
  18. "md5":"xxzz...",
  19. "version":"1.0.1",
  20. "ota_type":1,
  21. "customize":""
  22. }
  23. ]
  24. }
  25. }

返回值说明

字段 类型 说明
need_ota boolean 是否需要OTA,true:需要,false:不需要
files array 固件列表(可能为空)
files.file_url string 固件下载链接
files.md5 string md5
files.version string 版本号
files.ota_type int 固件类型,0:mcu;1:wifi
files.customize string 拓展字段

说明
- files:need_ota为false时,表示云端认为设备此时不需要ota,fiels为空;need_ota为true时,files有三种情况:两个文件(mcu和wifi都有),一个mcu文件,一个wifi文件

错误码

错误代码 错误说明
10000 参数错误:参考Response中的message

设备上传版本信息

PUT /api/v1/ota/version/

请求参数

参数名 类型 必须 说明
device_id string 设备id
wifi_version string wifi当前版本号
mcu_version string mcu当前版本号

返回值

  1. {
  2. "meta":{
  3. "code":0,
  4. "message":"update version ok"
  5. },
  6. "data":{
  7. }
  8. }

错误码

错误代码 错误说明
10000 参数错误:参考Response中的message

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注