[关闭]
@soszrg 2018-03-28T02:30:45.000000Z 字数 6782 阅读 494

OTA接口文档_简单版(V3.1)

V3.1

版本:v3.1


前端用OTA接口


创建OTA任务(Token)

POST /ota/tasks/

请求参数

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

ug_type说明

返回值

  1. {
  2. "meta":{
  3. "message":"任务创建成功",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":16,
  8. "product":{
  9. "product_id":"d927a33cf7...",
  10. "name":"测试1"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":11,
  15. "file_name":"",
  16. "component":"",
  17. "description":"",
  18. "version":"1.0.1",
  19. "upload_time":"2018-02-02 18:06:18",
  20. "size":"10kb"
  21. }
  22. ],
  23. "status":0,
  24. "description":"",
  25. "ug_type":0,
  26. "mac_range":[
  27. ],
  28. "update_time":"2018-02-02 18:06:18",
  29. "create_time":"2018-02-02 18:06:18",
  30. "extend":null
  31. }
  32. }

返回值说明

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

错误码

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

任务列表(Token)

GET /ota/tasks/

请求参数

参数名 类型 必须 说明
product_id string 产品ID

返回值

  1. {
  2. "meta":{
  3. "message":"OTA任务列表",
  4. "code":0
  5. },
  6. "data":{
  7. "count":2,
  8. "next":null,
  9. "previous":null,
  10. "results":[
  11. {
  12. "ot_id":17,
  13. "product":{
  14. "product_id":"d927a33c...",
  15. "name":"测试1"
  16. },
  17. "ota_files":[
  18. {
  19. "of_id":12,
  20. "file_name":"",
  21. "component":"",
  22. "description":"",
  23. "version":"1.0.1",
  24. "upload_time":"2018-02-02 18:33:10",
  25. "size":"10size"
  26. }
  27. ],
  28. "status":0,
  29. "description":"",
  30. "ug_type":0,
  31. "mac_range":[
  32. ],
  33. "update_time":"2018-02-02 18:33:10",
  34. "create_time":"2018-02-02 18:33:10",
  35. "extend":null
  36. },
  37. {
  38. "ot_id":16,
  39. "product":{
  40. "product_id":"d927a33cf...",
  41. "name":"测试1"
  42. },
  43. "ota_files":[
  44. {
  45. "of_id":11,
  46. "file_name":"",
  47. "component":"",
  48. "description":"",
  49. "version":"1.0.1",
  50. "upload_time":"2018-02-02 18:06:18",
  51. "size":"10size"
  52. }
  53. ],
  54. "status":0,
  55. "description":"",
  56. "ug_type":0,
  57. "mac_range":[
  58. ],
  59. "update_time":"2018-02-02 18:06:18",
  60. "create_time":"2018-02-02 18:06:18",
  61. "extend":null
  62. }
  63. ]
  64. }
  65. }

错误码

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

单个任务信息(Token)

GET /ota/tasks/<ot_id>/

请求参数

参数名 类型 必须 说明
ot_id int 任务ID

返回值

  1. {
  2. "meta":{
  3. "message":"任务信息",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":2,
  8. "product":{
  9. "product_id":"d927a33cf...",
  10. "name":"测试1"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":1,
  15. "file_name":"test",
  16. "component":"",
  17. "description":"",
  18. "version":"ota_version_v0.3",
  19. "upload_time":"2018-01-22 10:17:59",
  20. "size":""
  21. }
  22. ],
  23. "status":1,
  24. "description":"",
  25. "ug_type":0,
  26. "mac_range":null,
  27. "update_time":"2018-01-22 10:31:31",
  28. "create_time":"2018-01-22 10:31:31",
  29. "extend":null
  30. }
  31. }

错误码

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

删除单个任务(Token)

DELETE /ota/tasks/<ot_id>/

请求参数

参数名 类型 必须 说明
ot_id int 任务ID

返回值

  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 /ota/tasks/<ot_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. "message":"更新任务成功",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":10,
  8. "product":{
  9. "product_id":"d927a33...",
  10. "name":"更新任务成功"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":5,
  15. "file_name":"fn",
  16. "component":"",
  17. "description":"12qwe",
  18. "version":"1.0.5",
  19. "upload_time":"2018-01-31 17:44:30",
  20. "size":"101kb",
  21. "file_url":"https://ota.com/firmware.bin",
  22. "md5":"AAVDWCSSSAAA..."
  23. }
  24. ],
  25. "status":0,
  26. "description":"123456",
  27. "ug_type":0,
  28. "mac_range":[
  29. "a...",
  30. "b...",
  31. "c..."
  32. ],
  33. "update_time":"2018-01-31 17:44:30",
  34. "create_time":"2018-01-31 17:44:30",
  35. "extend":null
  36. }
  37. }

错误码

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

任务发布(Token)

PUT /ota/tasks/<ot_id>/release/

请求参数

参数名 类型 必须 说明
ot_id int 任务ID

返回值

  1. {
  2. "meta":{
  3. "message":"发布成功",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":10,
  8. "product":{
  9. "product_id":"d91fa...",
  10. "name":"测试1"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":5,
  15. "file_name":"fn",
  16. "component":"",
  17. "description":"12qwe",
  18. "version":"1.0.5",
  19. "upload_time":"2018-01-31 17:44:30",
  20. "size":"101kb",
  21. "file_url":"https://ota.com/1.bin",
  22. "md5":"AAVDWCSSSAAA"
  23. }
  24. ],
  25. "status":1,
  26. "description":"123456",
  27. "ug_type":0,
  28. "mac_range":[
  29. "a",
  30. "b",
  31. "c"
  32. ],
  33. "update_time":"2018-02-05 15:49:48",
  34. "create_time":"2018-01-31 17:44:30",
  35. "extend":null
  36. }
  37. }

错误码

错误代码 错误说明
10000 ot_id错误,找不到任务

推送OTA到设备(Token)

POST /ota/tasks/<ot_id>/push/

请求参数

参数名 类型 必须 说明
ot_id int 任务ID
dsn_list string array MAC地址数组

返回值

  1. {
  2. "meta":{
  3. "message":"推送完成",
  4. "code":0
  5. },
  6. "data":{
  7. "errors": ["ACX...", "BESF..."],
  8. "successes": ["FBXX...", "AAACC..."]
  9. }
  10. }

字段说明

字段 类型 说明
successes list 推送成功的设备
errors list 推送失败的设备

错误码

错误代码 错误说明
10000 参数错误

获取设备的OTA日志(Token)

GET /ota/tasks/logs/

请求参数

参数名 类型 必须 说明
device_id string 设备ID

返回值

  1. {
  2. "meta":{
  3. "message":"Log列表",
  4. "code":0
  5. },
  6. "data":{
  7. "count":2,
  8. "next":null,
  9. "previous":null,
  10. "results":[
  11. {
  12. "ol_id":"9b76ff91-3620-11e7-af30-dc536017523b",
  13. "product_id":"8d01f2041...",
  14. "device_id":"bbddc751346...",
  15. "dsn":"test050901",
  16. "content":"OTA任务完成",
  17. "customize":"",
  18. "create_time":"2017-05-11 16:05:33.321000"
  19. },
  20. {
  21. "ol_id":"9b761530-3620-11e7-be45-dc536017523b",
  22. "product_id":"8d01f2041...",
  23. "device_id":"bbddc75134...",
  24. "dsn":"test050901",
  25. "content":"固件[test]更新完成",
  26. "customize":"",
  27. "create_time":"2017-05-11 16:05:33.315000"
  28. }
  29. ]
  30. }
  31. }

错误码

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

设备用OTA接口


FOG设备通过设备ID检查OTA

PUT /v3_1/ota/device/

请求参数

参数名 类型 必须 说明
device_id string 设备ID(mqtt不需要传该参数)
password string 设备密码
component string 组件名称(适用于多组件的产品)
req_type int 请求类型(mqtt不需要传该参数)
req_id int 请求ID,由设备端生成,用于追踪请求

req_type:0 → 消费者程序使用

  1. {
  2. "type":"ota_check",
  3. "data":{
  4. "password": "112xx...",
  5. "component": "xxxx" # 可选参数
  6. "req_id":123...
  7. }
  8. }
  1. {
  2. "type": "ota_check",
  3. "meta":{
  4. "message":"ota file info",
  5. "code":0
  6. },
  7. "data":{
  8. "files":[
  9. {
  10. "file_url":"https://test.com/a.bin",
  11. "component":"test1",
  12. "md5":"1abx..",
  13. "version":"1.0.1",
  14. "customize":""
  15. },
  16. {
  17. "file_url":"https://test.com/a.bin",
  18. "component":"test2",
  19. "md5":"1safa...",
  20. "version":"1.0.1",
  21. "customize":""
  22. }
  23. ],
  24. "ot_id":25,
  25. "req_id": 123...
  26. }
  27. }

req_type:1 → 设备端通过HTTP方式解绑

返回值

  1. {
  2. "meta":{
  3. "message":"ota file info",
  4. "code":0
  5. },
  6. "data":{
  7. "files":[
  8. {
  9. "file_url":"https://test.com/a.bin",
  10. "component":"test1",
  11. "md5":"1abx..",
  12. "version":"1.0.1",
  13. "customize":""
  14. },
  15. {
  16. "file_url":"https://test.com/a.bin",
  17. "component":"test2",
  18. "md5":"1safa...",
  19. "version":"1.0.1",
  20. "customize":""
  21. }
  22. ],
  23. "ot_id":25
  24. }
  25. }

字段说明

返回值字段 字段类型 字段说明
need_upgrade bool 是否需要升级
ot_id int 任务ID
files list 升级文件列表
customize string 用户自定义字段(公版不需要)

说明

错误码

错误代码 错误说明
10000 参数错误:具体信息见Response的message字段

设备发送OTA完成的通知

PUT /v3_1/ota/device/log/

请求参数

参数名 类型 必须 说明
device_id string 设备ID
password string 设备密码
ot_id int 任务ID
update_ok bool 设备固件是否全部更新完成,默认为true
components string Array 本次完成更新的组件名称列表
customize string 用户自定义字符串(公版不需要)
req_type int 请求类型(mqtt方式调用不需要此参数)
req_id int 请求ID,由设备端生成,用于追踪请求

req_type:0 → 消费者程序使用

  1. {
  2. "type":"ota_log",
  3. "data":{
  4. "password": "112xx...",
  5. "ot_id": 1
  6. "update_ok": true,
  7. "components": ["bbbb", "aavc"] # 可选参数
  8. "req_id":123...
  9. }
  10. }
  1. {
  2. "type":"ota_log",
  3. "meta":{
  4. "message":"ota log ok",
  5. "code":0
  6. },
  7. "req_id":123
  8. "data":{
  9. }
  10. }

req_type:1 → 设备端通过HTTP方式上传log

返回值

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

错误码

错误代码 错误说明
10000 参数错误:具体信息见Response的message字段
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注