[关闭]
@soszrg 2018-02-13T06:46:35.000000Z 字数 9765 阅读 542

OTA接口文档_复杂版(V3.1)

V3.1

版本:v3.1


前端用OTA接口


固件上传(Token)

POST /ota/files/

请求参数

参数名 类型 必须 说明
product_id string 产品ID
file_name string 文件名
file_url string 固件下载链接
size int 固件大小
md5 string 固件的md5
version string 用户定义的固件版本号
component string 用户定义的固件名称
description string 固件描述

字段说明

返回值

  1. {
  2. "meta":{
  3. "message":"固件创建成功",
  4. "code":0
  5. },
  6. "data":{
  7. "of_id":3,
  8. "product":{
  9. "product_id":"d927a33cf7...",
  10. "name":"test"
  11. },
  12. "file_name":"ota_file",
  13. "file_url":"https://bcsaa...ota.bin",
  14. "size":"1kb",
  15. "md5":"dafab...",
  16. "version":"1.0.1",
  17. "component":"",
  18. "upload_time":"2017-10-12 12:50:55",
  19. "description":"ota file",
  20. "customize":"",
  21. "extend":{
  22. }
  23. }
  24. }

错误码

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

获取某个产品的固件列表(Token)

GET /ota/files/

请求参数

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

返回值

  1. {
  2. "meta":{
  3. "message":"OTA File列表",
  4. "code":0
  5. },
  6. "data":{
  7. "count":2,
  8. "next":null,
  9. "previous":null,
  10. "results":[
  11. {
  12. "of_id":2,
  13. "product":{
  14. "product_id":"d9afafa...",
  15. "name":"test"
  16. },
  17. "file_name":"ota_file",
  18. "file_url":"https://www.ota...le.bin",
  19. "size":"1kb",
  20. "md5":"fafavvx...",
  21. "version":"1.0.1",
  22. "component":"",
  23. "upload_time":"2017-1-12 11:40:00",
  24. "description":"123456",
  25. "customize":"",
  26. "extend":{
  27. }
  28. },
  29. {
  30. "of_id":1,
  31. "product":{
  32. "product_id":"d927a33cf75...",
  33. "name":"test"
  34. },
  35. "file_name":"test18012201",
  36. "file_url":"https://bce-b..ota.bin",
  37. "size":"12kb",
  38. "md5":"262e...",
  39. "version":"ota_version_v0.1",
  40. "component":"",
  41. "upload_time":"2017-1-12 11:50:00",
  42. "description":"",
  43. "customize":"",
  44. "extend":{
  45. }
  46. }
  47. ]
  48. }
  49. }

错误码

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

单个固件信息(Token)

GET /ota/files/<of_id>/

请求参数

参数名 类型 必须 说明
of_id int 固件ID

返回值

  1. {
  2. "meta":{
  3. "message":"固件信息",
  4. "code":0
  5. },
  6. "data":{
  7. "of_id":1,
  8. "product":{
  9. "product_id":"d927a33cf75211...",
  10. "name":"test"
  11. },
  12. "file_name":"test18012201",
  13. "file_url":"https://bc0...ota(1).bin",
  14. "size":"1kb",
  15. "md5":"262e75bf...",
  16. "version":"ota_version_v0.1",
  17. "component":"",
  18. "upload_time":"2017-10-10 13:10:11",
  19. "description":"",
  20. "customize":"",
  21. "extend":{
  22. }
  23. }
  24. }

错误码

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

创建OTA任务(Token)

POST /ota/tasks/

请求参数

参数名 类型 必须 说明
ota_files int list OTA文件ID list
status int 任务状态:0:测试,1:上线,2:无效
description string 任务描述
ug_type int 升级方式
mac_range string list 要升级的MAC地址范围

ug_type说明:

返回值

  1. {
  2. "meta":{
  3. "message":"任务创建成功",
  4. "code":0
  5. },
  6. "data":{
  7. "ot_id":8,
  8. "product":{
  9. "product_id":"d927a33..."
  10. "name":"test"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":1,
  15. "file_name":"test18012201",
  16. "component":"",
  17. "description":"",
  18. "version":"0.1",
  19. "upload_time":"2018-01-22 10:17:59"
  20. }
  21. ],
  22. "status":0,
  23. "onset_time":"2018-01-30 10:00:00",
  24. "description":"123456",
  25. "ug_type":0,
  26. "mac_range":[
  27. "ACFF...",
  28. "CCCC.."
  29. ],
  30. "update_time":"2018-01-30 10:15:44",
  31. "create_time":"2018-01-30 10:15:44",
  32. "extend":null
  33. }
  34. }

返回值说明

字段 类型 说明
ot_id int 任务ID,任务唯一标识,用于后续任务的修改和删除等

错误码

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

任务列表(Token)

GET /ota/tasks/

请求参数

参数名 类型 必须 说明
of_id int OTA文件ID list
product_id string 产品ID

说明

返回值

  1. {
  2. "meta":{
  3. "message":"OTA任务列表",
  4. "code":0
  5. },
  6. "data":{
  7. "count":4,
  8. "next":null,
  9. "previous":null,
  10. "results":[
  11. {
  12. "ot_id":8,
  13. "product":{
  14. "product_id":"d927a33c...",
  15. "name":"test"
  16. },
  17. "ota_files":[
  18. {
  19. "of_id":1,
  20. "file_name":"test18012201",
  21. "component":"",
  22. "description":"",
  23. "version":"v0.2",
  24. "upload_time":"2018-01-22 10:17:59"
  25. }
  26. ],
  27. "status":0,
  28. "onset_time":"2018-01-30 10:00:00",
  29. "description":"123456",
  30. "ug_type":0,
  31. "mac_range":[
  32. "aaa",
  33. "bbb"
  34. ],
  35. "update_time":"2018-01-30 10:15:44",
  36. "create_time":"2018-01-30 10:15:44",
  37. "extend":null
  38. },
  39. {
  40. "ot_id":6,
  41. "product":{
  42. "product_id":"d927a33cf75211e...",
  43. "name":"test"
  44. },
  45. "ota_files":[
  46. {
  47. "of_id":1,
  48. "file_name":"test18012201",
  49. "component":"",
  50. "description":"",
  51. "version":"v0.1",
  52. "upload_time":"2018-01-22 10:17:59"
  53. }
  54. ],
  55. "status":1,
  56. "onset_time":"2018-01-30 10:00:00",
  57. "description":"123456",
  58. "ug_type":0,
  59. "mac_range":[
  60. "aaa",
  61. "bbb"
  62. ],
  63. "update_time":"2018-01-30 10:03:46",
  64. "create_time":"2018-01-30 10:03:46",
  65. "extend":null
  66. },
  67. {
  68. "ot_id":5,
  69. "product":{
  70. "product_id":"d927a33cf75211e7804bfa163e431402",
  71. "name":"test"
  72. },
  73. "ota_files":[
  74. {
  75. "of_id":1,
  76. "file_name":"test18012201",
  77. "component":"",
  78. "description":"",
  79. "version":"ota_version_v0.1",
  80. "upload_time":"2018-01-22 10:17:59"
  81. }
  82. ],
  83. "status":2,
  84. "onset_time":"2018-01-30 10:00:00",
  85. "description":"123456",
  86. "ug_type":0,
  87. "mac_range":[
  88. "aaa",
  89. "bbb"
  90. ],
  91. "update_time":"2018-01-30 09:47:59",
  92. "create_time":"2018-01-30 09:47:59",
  93. "extend":null
  94. },
  95. ]
  96. }
  97. }

错误码

错误代码 错误说明
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":8,
  8. "product":{
  9. "product_id":"d927a33c...
  10. "name":"test"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":1,
  15. "file_name":"test18012201",
  16. "component":"",
  17. "description":"",
  18. "version":"ota_version_v0.1",
  19. "upload_time":"2018-01-22 10:17:59"
  20. }
  21. ],
  22. "status":0,
  23. "onset_time":"2018-01-30 10:00:00",
  24. "description":"123456",
  25. "ug_type":0,
  26. "mac_range":[
  27. "aaa",
  28. "bbb"
  29. ],
  30. "update_time":"2018-01-30 10:15:44",
  31. "create_time":"2018-01-30 10:15:44",
  32. "extend":null
  33. }
  34. }

错误码

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

任务发布(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":8,
  8. "product":{
  9. "product_id":"d927a33c...
  10. "name":"test"
  11. },
  12. "ota_files":[
  13. {
  14. "of_id":1,
  15. "file_name":"test18012201",
  16. "component":"",
  17. "description":"",
  18. "version":"ota_version_v0.1",
  19. "upload_time":"2018-01-22 10:17:59"
  20. }
  21. ],
  22. "status":1,
  23. "onset_time":"2018-01-30 10:00:00",
  24. "description":"123456",
  25. "ug_type":0,
  26. "mac_range":[
  27. "aaa",
  28. "bbb"
  29. ],
  30. "update_time":"2018-01-30 10:27:49",
  31. "create_time":"2018-01-30 10:15:44",
  32. "extend":null
  33. }
  34. }

错误码

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

OTA任务的设备列表(Token)

GET /ota/devices/

请求参数

参数名 类型 必须 说明
ot_id int 任务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. "id":8,
  13. "od_id":"3c58e198-...",
  14. "ot_id":2,
  15. "product_id":"d927a33cf75211...",
  16. "device_id":"3bc6d0a004a311e88...",
  17. "dsn":"B0F8931025AC",
  18. "status":1,
  19. "onset_time":"2018-01-22 10:31:31",
  20. "create_time":"2018-01-29 11:19:37"
  21. },
  22. {
  23. "id":7,
  24. "od_id":"6a934c72...",
  25. "ot_id":2,
  26. "product_id":"...",
  27. "device_id":"6a0e527e025c...",
  28. "dsn":"FCEEE6057262",
  29. "status":1,
  30. "onset_time":"2018-01-22 10:31:31",
  31. "create_time":"2018-01-26 13:47:38"
  32. }
  33. ],
  34. "complete_percentage":12.5
  35. }
  36. }

错误码

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

OTA设备的Log列表(Token)

GET /v3/ota/tasks/<od_id>/logs/

请求参数

参数名 类型 必须 说明
od_id string OTA设备ID,不是设备ID,放在URL中

返回值

  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":"8d01f204150911e7a554fa163e876164",
  14. "device_id":"bbddc751346311e7bc7bdc536017523b",
  15. "dsn":"zrgtest050901",
  16. "content":"OTA任务完成",
  17. "customize":"",
  18. "create_time":"2017-05-11T16:05:33.321000"
  19. },
  20. {
  21. "ol_id":"9b761530-3620-11e7-be45-dc536017523b",
  22. "product_id":"8d01f204150911e7a554fa163e876164",
  23. "device_id":"bbddc751346311e7bc7bdc536017523b",
  24. "dsn":"zrgtest050901",
  25. "content":"固件[test]更新完成",
  26. "customize":"",
  27. "create_time":"2017-05-11T16:05:33.315000"
  28. }
  29. ]
  30. }
  31. }

错误码

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

获取所有产品的OTA Log(Token)

GET /ota/logs/

返回值

  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":"8d01f204150911e7a554fa163e876164",
  14. "device_id":"bbddc751346311e7bc7bdc536017523b",
  15. "dsn":"zrgtest050901",
  16. "content":"OTA任务完成",
  17. "customize":"",
  18. "create_time":"2017-05-11T16:05:33.321000"
  19. },
  20. {
  21. "ol_id":"9b761530-3620-11e7-be45-dc536017523b",
  22. "product_id":"8d01f204150911e7a554fa163e876164",
  23. "device_id":"bbddc751346311e7bc7bdc536017523b",
  24. "dsn":"zrgtest050901",
  25. "content":"固件[test]更新完成",
  26. "customize":"",
  27. "create_time":"2017-05-11T16:05:33.315000"
  28. }
  29. ]
  30. }
  31. }

错误码

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

OTA任务的推送接口(Token)

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

请求参数

参数名 类型 必须 说明
ot_id int OTA任务ID,放在URL中
dsn_list string list 需要接收推送通知的设备的串号或MAC地址列表

返回值

  1. {
  2. "meta":{
  3. "message":"推送完成",
  4. "code":0
  5. },
  6. "data":{
  7. "successes":[
  8. "zrgtest051501"
  9. ],
  10. "errors":[
  11. ]
  12. }
  13. }

返回值字段说明

字段 说明
successes 推送成功的串号或MAC地址列表
errors 推送失败的串号或MAC地址列表

错误码

错误代码 错误说明
10000 参数错误,参考返回数据中的message

设备用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. }

字段说明

返回值字段 字段类型 字段说明
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字段
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注