# OTA

数据上行: fogcloud/{productKey}/{deviceName}/thing/up/ota 数据下行: fogcloud/{productKey}/{deviceName}/thing/down/ota

具体数据类型根据 json 数据的 method 字段进行区分:

method

说明

version.post

设备上报 OTA 版本

firmware.post

云端推送 OTA 升级包信息

firmware.get

设备主动检查 OTA 升级

upgrade.post

设备上报升级信息

sub.version.post

子设备上报 OTA 版本

sub.firmware.post

云端推送子设备 OTA 升级包信息

sub.upgrade.post

子设备上报 OTA 版本

# 1 设备上报版本

您的设备应该在升级完成后上报该消息,云端会依据此消息判断固件升级任务是否完成。

  • 设备上行数据格式:
{
  "id": 123,
  "version": "1.0",
  "method": "version.post",
  "params": {
    "version": "1.0.0",
    "module": "default" //升级包所属模块
  }
}

# 2 设备上报升级进度

您的设备通过该消息上报固件下载进度,云端会依据此消息更新固件升级任务进度。

  • 设备上行数据格式:
{
  "id": 123,
  "version": "1.0",
  "method": "upgrade.post",
  "params": {
    "step": -1, // 有符号32位整型, 0~100升级进度,-1升级失败
    // "desc": "OTA升级失败,请求不到升级包信息。",
    "module": "mcu",
    "task_id": "123"
  }
}

# 3 云端推送 OTA 升级包信息

您的设备在收到该消息后,可以从url下载固件,并通过sign来验证固件文件合法性。

  • 云端下行数据格式:
{
  "id": 123,
  "version": "1.0",
  "method": "firmware.post",
  "params": {
    "size": 93796291, //单位:字节
    "sign": "f8d85b250d4d787a9f483d89a974****",
    "version": "1.0.1",
    "url": "https://the_firmware_url",
    "sign_method": "MD5",
    "checksum": "xxxxxxxx", //累加和检验值,小端4字节hex数据
    "module": "mcu",
    "description": "string", //固件描述
    "task_id": "123" //整型字符串,当前升级任务唯一标识,设备上报进度时携带
  }
}

# 4 网关上报子设备版本

  • 设备上行数据格式:
{
    "id": 123,
    "version": "1.0",
    "method": "sub.version.post",
    "params": [
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "version": "1.0.0",
            "module": "default" //升级包所属模块
        },
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "version": "1.2.0",
            "module": "default" //升级包所属模块
        }
    ]
}

# 5 网关上报子设备升级进度

  • 设备上行数据格式
{
    "id": 123,
    "version": "1.0",
    "method": "sub.upgrade.post",
    "params": [
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "step": -1, // 有符号32位整型, 0~100升级进度,-1升级失败
            "module": "mcu",
            "task_id": "123"
        },
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "step": -1, // 有符号32位整型, 0~100升级进度,-1升级失败
            "module": "mcu",
            "task_id": "123"
        }
    ]
}

# 6 云端推送子设备 OTA 升级包信息

  • 云端下行数据格式
{
    "id": 123,
    "version": "1.0",
    "method": "sub.firmware.post",
    "params": [
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "size": 93796291, //单位:字节
            "sign": "f8d85b250d4d787a9f483d89a974****",
            "version": "1.0.1",
            "url": "https://the_firmware_url",
            "sign_method": "MD5",
            "module": "mcu",
            "desc": "string", //固件描述
            "task_id": "123" //整型字符串,当前升级任务唯一标识,设备上报进度时携带
        },
        {
            "identity": {
                "product_key": "12097812",
                "device_name": "00000001"
            },
            "size": 93796291, //单位:字节
            "sign": "f8d85b250d4d787a9f483d89a974****",
            "version": "1.0.1",
            "url": "https://the_firmware_url",
            "sign_method": "MD5",
            "module": "mcu",
            "desc": "string", //固件描述
            "task_id": "123" //整型字符串,当前升级任务唯一标识,设备上报进度时携带
        }
    ]
}

# 7 设备主动检查 OTA 升级

您的设备可以主动向云端发起 ota 升级请求,云端收到请求后,会给设备发送最新的固件升级信息

  • 设备上行数据格式
{
    "id": 123,
    "version": "1.0",
    "method": "firmware.get",
    "params": {
        "module": "string"
    }
}
  • 云端响应数据格式
{
  "id": 123,
  "version": "1.0",
  "method": "firmware.post",
  "params": {
    "size": 93796291, //单位:字节
    "sign": "f8d85b250d4d787a9f483d89a974****",
    "version": "1.0.1",
    "url": "https://the_firmware_url",
    "sign_method": "MD5",
    "module": "mcu",
    "description": "string", //固件描述
    "task_id": "123" //整型字符串,当前升级任务唯一标识,设备上报进度时携带
  }
}
更新时间: 2023/7/21 11:41:17