OTA includes module upgrade and MCU application upgrade. The device to be upgraded performs data exchange with OneNET platform through HTTP protocol of RESTful standard format to complete the upgrade. RESTful API necessary for southern devices is divided into three categories at present, i.e. detect task, pull file and report status.
It mainly introduces the process testing and pulling the firmware by network debugging assistant using API in the part so as to provide reference for package testing carried out by R & D personnel.
Python is used to calculate Authorization here. It will only need to change product id and accesskey during actual operation. Please refer to Fig. 1 for Python code.
The code download address is as below:
◈ JAVA code, Python code download ◈ C code download
Authentication parameters calculated:
version=2018-10-31&res=products%2F198290&et=7555917657&method=sha1&sign=ZUXNMUqvAbuH0uHs0S1pd%2BgflNE%3D
POST http://ota.heclouds.com/ota/device/version?dev_id=522747162 HTTP/1.1
Content-Type: application/json
Authorization:version=2018-10-31&res=products%2F198290&et=7555917657&method=sha1&sign=ZUXNMUqvAbuH0uHs0S1pd%2BgflNE%3D
host:ota.heclouds.com
Content-Length:20
{"s_version":"V1.3"}
dev_id=522747162 needs to be changed to be the id of the device upgraded. Other parameters remain unchanged.
Chip platform | Chip model | Manufacturer Number | Chip number |
---|---|---|---|
nordic | ESP32 | 101 | 10101 |
FANLUN | nrf52832 | 102 | 10201 |
GigaDevice | GD32 | 103 | 10301 |
Miscellaneous | Miscellaneous | 100 | 10001 |
GET /ota/south/check?dev_id=522747162&manuf=102&model=10201&type=2&version=V11&cdn=false HTTP/1.1
Authorization:version=2018-10-31&res=products%2F198290&et=7555917657&method=sha1&sign=ZUXNMUqvAbuH0uHs0S1pd%2BgflNE%3D
host: ota.heclouds.com
//line feed here; please delete the contents of the line during use and keep the line break.
//line feed here; please delete the contents of the line during use and keep the line break.
GET /ota/south/download/ota_JcWgqjwXigKAfRayjjUW HTTP/1.1
Range:bytes=0-5
host: ota.heclouds.com
//line feed here; please delete the contents of the line during use and keep the line break.
//line feed here; please delete the contents of the line during use and keep the line break.
When pulling part of the file, the header Range field is modified.
Range: bytes={start}-{end}, only following modes are supported at present:
1. Range: bytes={start}-, get the data from the first byte ({start}+1) to the last one.
For example:
Range: bytes=0-, get all data.
Range: bytes=2-, get data from the 3rd one to the last one.
Note: if {start}>= total length of the file, then {start}=0 by default.
2. Range: bytes={start}-{end}, get the data from the first byte ({start}+1) to the byte of {end}+1.
For example:
Range: bytes=0-99, get the first 100 bytes.
Note: if end}>>= total length of the file, then end=len-1 by default.If {start}>
{end}, start is set to be 0.
3. Range: bytes=-{end}, get the data of the bytes from end to the last one.
For example:
Range: bytes=-100, get the data of the last 100 bytes.
If {end} is larger than the total length of the file (len), then end=len (get all files) by default.
Fragmented status code returned: 206;
Non-fragmented status code returned: 200
POST /ota/south/device/download/ota_3lI1NIMLB6E4u260cLRd/progress?dev_id=522747162 HTTP/1.1
Authorization:version=2018-10-31&res=products%2F198290&et=7555917657&method=sha1&sign=ZUXNMUqvAbuH0uHs0S1pd%2BgflNE%3D
host:ota.heclouds.com
Content-Type: application/json
Content-Length:11
{"step":54}//download report progress is 54%.
POST /ota/south/device/download/ota_3lI1NIMLB6E4u260cLRd/progress?dev_id=522747162 HTTP/1.1
Authorization:version=2018-10-31&res=products%2F198290&et=7555917657&method=sha1&sign=ZUXNMUqvAbuH0uHs0S1pd%2BgflNE%3D
host:ota.heclouds.com
Content-Type: application/json
Content-Length:12
{"step":201}//meaning the upgrade is completed.
When the device is downloading the upgrade package (fragmented download), download progress can be reported if necessary (step=[0,100] can only be reported when the device is “downloading”);
If the download progress reported by the device is 100 (i.e. step: 100), the platform will change the upgrade status of the device from “downloading” to “upgrading”.
If only the device is in “downloading” status, the device can report the download progress via the interface. The error of “invalid state” will be returned in other status.
If step is above 100, it will be used as reporting states (When the device is in following three states, i.e.: to be upgraded, downloading and upgrading, the upgrade process can be completed by reporting following codes. Following states cannot be reported when it is in other states such as canceled, upgrade failed, upgrade successful, suspended):
result Code | Description | result Code | Description |
---|---|---|---|
101 | Upgrade package downloaded successfully | 102 | Download failed, insufficient space |
103 | Download failed, memory overflow | 104 | Download failed, download request timed out |
105 | Download failed, battery low | 106 | Download failed, weak signal |
107 | Download failed, unknown exception | - | - |
201 | Upgrade succeed | 202 | Upgrade failed, battery low |
203 | Upgrade failed, memory overflow | 204 | Upgrade failed, inconsistent version |
203 | Upgrade failed, memory overflow | 204 | Upgrade failed, inconsistent version |
205 | Upgrade failed, MD5 verification failed | 206 | Upgrade failed, unknown exception |
207 | Maximum number of times of retry reached | 208 | Device upgrade expired |
The platform will display that the status of the task is completed after the upgrade status is reported successfully.