This topic uses the demo file./demos/mqtt_upload_basic_demo.c in the Link SDK for C as an example to describe how to call the Link SDK APIs to upload files to IoT Platform over MQTT, reducing hardware resource consumption and development costs.
Background
-
For an overview of the file upload feature, see File Upload Overview.
-
The file upload feature is based on MQTT connections. For MQTT connection code examples, see Connect to IoT Platform over MQTT.
Step 1: Initialize file upload
-
Add the header files.
…… …… #include "aiot_mqtt_api.h" #include "aiot_mqtt_upload_api.h" #include "core_crc64.h" …… -
Configure the underlying dependencies and log output.
/* A collection of system adaptation functions located in the portfiles/aiot_port/ directory. */ extern aiot_sysdep_portfile_t g_aiot_sysdep_portfile; /* The server certificate located in external/ali_ca_cert.c. */ extern const char *ali_ca_cert; /* The log callback, where SDK logs are output. */ static int32_t demo_state_logcb(int32_t code, char *message) { printf("%s", message); return 0; } -
Call aiot_mqtt_upload_init to create a file upload client instance and initialize its default parameters.
mqtt_handle = aiot_mqtt_upload_init();
Step 2: Configure file upload
Call aiot_mqtt_upload_setopt to configure the following options.
-
Associate the MQTT connection handle.
ImportantBefore you configure parameters for the file upload feature, make sure you have configured device authentication credentials and related parameters. Configure MQTT connection parameters.
File upload requests use MQTT connections. Associate the MQTT connection handle with this option.
void *up_handle = aiot_mqtt_upload_init(); aiot_mqtt_upload_setopt(up_handle, AIOT_MQTT_UPLOADOPT_MQTT_HANDLE, mqtt_handle); -
(Optional)
Configure file upload parameters.
-
Sample code:
uint32_t rsp_timeout = 2000; aiot_mqtt_upload_setopt(up_handle, AIOT_MQTT_UPLOADOPT_RSP_TIMEOUT_MS, &rsp_timeout); uint32_t rety_count = 5; aiot_mqtt_upload_setopt(up_handle, AIOT_MQTT_UPLOADOPT_RETRY_COUNT, &rety_count); uint32_t block_size = 1024; aiot_mqtt_upload_setopt(up_handle, AIOT_MQTT_UPLOADOPT_DEFAULT_BLOCK_SIZE, &block_size); -
Parameters:
Parameter
Description
rsp_timeout
The timeout for retransmitting each data chunk, in milliseconds.
Default: 5,000 ms (5 seconds). Set to 0 to use the default.
Sample value: 2,000 ms.
AIOT_MQTT_UPLOADOPT_RSP_TIMEOUT_MS
Sets the timeout for retransmitting each data chunk during file upload.
rety_count
The number of retry attempts on timeout.
Default: 10.
Sample value: 5.
AIOT_MQTT_UPLOADOPT_RETRY_COUNT
Sets the number of retry attempts on timeout during file upload.
block_size
The maximum size of each data chunk, in bytes.
Valid range: 256–131,072. Default: 2,048 bytes.
Sample value: 1,024 bytes.
AIOT_MQTT_UPLOADOPT_DEFAULT_BLOCK_SIZE
Sets the maximum size of each data chunk sent during file upload.
-
(Optional) Step 3: Calculate CRC64 checksum
By default, the protocol performs CRC16 calculation on each data chunk. You can optionally use CRC64 for full-file validation. The SDK includes a C library for CRC64 calculation.
The following code calculates the CRC64 checksum for a file:
uint64_t crc = mqtt_upload_get_file_crc64(MQTT_UPLOAD_FILE_NAME);
Step 4: Request a file upload
-
Call aiot_mqtt_upload_open_stream to send a file upload request to IoT Platform.
Important-
When uploading a file, do not call aiot_mqtt_upload_open_stream multiple times for the same file. If an upload fails, you can resend the request to resume it.
-
When uploading different files, you can call aiot_mqtt_upload_open_stream multiple times. The SDK supports uploading multiple files concurrently.
-
Sample code:
-
Define the file sizes and names:
#define MQTT_UPLOAD_FILE_SIZE (2 * 1024) #define MQTT_UPLOAD_FILE_NAME ("mqttuploadfile001.txt") #define MQTT_UPLOAD_FILE_SIZE2 (1 * 1024 + 127) #define MQTT_UPLOAD_FILE_NAME2 ("mqttuploadfile002.txt") -
Send requests to upload the files:
uint32_t test_userdata = 100; aiot_mqtt_upload_open_stream(up_handle, MQTT_UPLOAD_FILE_NAME, MQTT_UPLOAD_FILE_SIZE, AIOT_MQTT_UPLOAD_FILE_MODE_OVERWRITE, &crc, mqtt_upload_read_data_handler, &test_userdata); mqtt_upload_create_upload_file(MQTT_UPLOAD_FILE_NAME2, MQTT_UPLOAD_FILE_SIZE2); aiot_mqtt_upload_open_stream(up_handle, MQTT_UPLOAD_FILE_NAME2, MQTT_UPLOAD_FILE_SIZE2, AIOT_MQTT_UPLOAD_FILE_MODE_OVERWRITE, NULL, mqtt_upload_read_data_handler, NULL);
-
-
Description of the sample code:
-
The sample code calls this API to upload two files concurrently:
mqttuploadfile001.txtandmqttuploadfile002.txt.Important-
File names have the following restrictions:
-
Contain only digits, letters, underscores (_), and periods (.).
-
Start with a digit or a letter.
-
Be 100 bytes or less in length.
-
-
The maximum file size is 16 MB.
-
-
The file
mqttuploadfile001.txtuses CRC64 validation and passes theuserdataparameter. -
The file
mqttuploadfile002.txtdoes not use CRC64 validation, and nouserdataparameter is passed. -
The sample code uses the overwrite processing policy. The following table describes the available processing policies.
Policy
Description
overwrite
Default policy. IoT Platform deletes the existing file with the same name and keeps only the newly uploaded file.
append
When a device sends a file upload request, IoT Platform returns information about any existing file with the same name. The device can then:
-
If the existing file was incompletely uploaded, the device can resume the upload.
NoteIoT Platform retains incomplete uploads for only 24 hours.
-
If the file was already uploaded completely, the device must use the overwrite policy or rename the local file before re-uploading.
reject
IoT Platform returns an error code indicating that the file already exists and rejects the upload request.
-
-
-
-
IoT Platform responds to the file upload request and triggers a callback on the device.
In the callback, the SDK reads file content or memory data in chunks and performs a CRC16 calculation on each chunk.
ImportantDuring chunked transfer, each data chunk must not exceed the
AIOT_MQTT_UPLOADOPT_DEFAULT_BLOCK_SIZEvalue. Except for the last chunk, each chunk must be at least 256 bytes.The following callback function
mqtt_upload_read_data_handlerreads file data in chunks:int32_t mqtt_upload_read_data_handler(const aiot_mqtt_upload_recv_t *packet, uint8_t *data, uint32_t size, void *userdata) { int32_t read_len = 0; if (userdata != NULL) { uint32_t *test_userdata = (uint32_t *)userdata; printf("test_userdata:%d\r\n", *test_userdata); } if (packet == NULL) { return 0; } if (packet->desc.code == UPLOAD_FILE_OK) { if (data != NULL && size != 0) { uint32_t read_size = size; FILE *fp; char* file_name = packet->desc.file_name; fp = fopen(file_name, "r"); uint32_t offset = packet->desc.file_offset; fseek(fp, offset, SEEK_SET); printf("Open %s read at: %d\r\n", file_name, offset); read_len = fread(data, sizeof(uint8_t), read_size, fp); printf("Read_len: %d\r\n", read_len); fclose(fp); } } else { printf("Error code:%d, message:%s\r\n", packet->desc.code, packet->desc.message); } return read_len; } -
(Optional)
To cancel an upload in progress, call aiot_mqtt_upload_cancel_stream.
API reference: aiot_mqtt_upload_cancel_stream.
Step 5: Handle upload status
During file upload, call aiot_mqtt_upload_process in a loop to check upload status:
while(1) {
aiot_mqtt_upload_result_t result = aiot_mqtt_upload_process(up_handle);
if (result.code == STATE_MQTT_UPLOAD_FINISHED) {
/* Upload successful. */
printf("MQTT Upload file(%s) success\r\n", result.file_name);
uploaded_file++;
if (uploaded_file == 2) {
break;
}
} else if (result.code == STATE_MQTT_UPLOAD_FAILED ||
result.code == STATE_MQTT_UPLOAD_FAILED_TIMEOUT ||
result.code == STATE_MQTT_UPLOAD_CANCEL_FAILED ) {
/* Upload failed. */
printf("MQTT Upload file(%s) failed,res:-0x%.4X\r\n", result.file_name, -result.code);
/* Destroy the MQTT UPLOAD instance. */
} else if (result.code == STATE_MQTT_UPLOAD_CANCEL_SUCCESS) {
printf("MQTT Upload file(%s) cancel success,res:-0x%.4X\r\n", result.file_name, -result.code);
} else if (result.code == STATE_MQTT_UPLOAD_FAILED_WHOLE_CHECK) {
printf("MQTT Upload file(%s) whole file md5 failed,res:-0x%.4X\r\n", result.file_name, -result.code);
}
sleep(1);
}
Step 6: Deinitialize file upload
Call aiot_mqtt_upload_deinit to destroy the file upload client instance and release resources:
aiot_mqtt_upload_deinit(&up_handle);
Device-side logs
View runtime results on the device side.
-
Connection logs:
A successful device connection to IoT Platform produces the following log:
[1637138922.457][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1637138922.457][LK-032A] mqtt host: iot-******.iot-as-mqtt.unify.aliyuncs.com [1637138922.457][LK-0317] user name: LightSwitch&a18wP****** [1637138922.457][LK-0318] password: 2AE57DEEAADE002064F87DEC55EE2EDD2A1996E44BA8F5622507D1EFD6****** success to establish tcp, fd=5 local port: 57139 [1637138922.488][LK-1000] establish mbedtls connection with server(host='iot-******.iot-as-mqtt.unify.aliyuncs.com', port=[1883]) [1637138922.507][LK-1000] success to establish mbedtls connection, (cost 45247 bytes in total, max used 47983 bytes) [1637138922.654][LK-0313] MQTT connect success in 197 ms AIOT_MQTTEVT_CONNECT -
File upload topic subscriptions:
[1637138922.654][LK-2013] aiot_mqtt_upload_init init [1637138922.654][LK-0309] sub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/init_reply [1637138922.654][LK-0309] sub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send_reply [1637138922.654][LK-0309] sub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/cancel_reply -
File upload request logs:
The device sends upload requests for two files:
File name
Size (bytes)
CRC64 validation
mqttuploadfile001.txt
2048
Yes
mqttuploadfile002.txt
1151
No
[1637138922.655][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/init [LK-030A] > 7B 22 69 64 22 3A 22 31 22 2C 22 70 61 72 61 6D | {"id":"1","params" [LK-030A] > 73 22 3A 7B 22 66 69 6C 65 4E 61 6D 65 22 3A 22 | :{"fileName":" [LK-030A] > 6D 71 74 74 75 70 6C 6F 61 64 66 69 6C 65 30 30 | mqttuploadfile001.txt" [LK-030A] > 31 2E 74 78 74 22 2C 22 66 69 6C 65 53 69 7A 65 | ,"fileSize [LK-030A] > 22 3A 32 30 34 38 2C 22 63 6F 6E 66 6C 69 63 74 | ":2048,"conflictStrategy" [LK-030A] > 53 74 72 61 74 65 67 79 22 3A 22 6F 76 65 72 77 | :"overwrite" [LK-030A] > 72 69 74 65 22 2C 22 66 69 63 4D 6F 64 65 22 3A | ,"ficMode": [LK-030A] > 22 63 72 63 36 34 22 2C 22 66 69 63 56 61 6C 75 | "crc64","ficValue" [LK-030A] > 65 22 3A 22 66 34 38 66 34 33 37 64 35 35 64 34 | :"f48f437d55** [LK-030A] > 37 31 34 63 22 7D 7D | ****"}} [1637138922.655][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/init [LK-030A] > 7B 22 69 64 22 3A 22 32 22 2C 22 70 61 72 61 6D | {"id":"2","params" [LK-030A] > 73 22 3A 7B 22 66 69 6C 65 4E 61 6D 65 22 3A 22 | :{"fileName":" [LK-030A] > 6D 71 74 74 75 70 6C 6F 61 64 66 69 6C 65 30 30 | mqttuploadfile002.txt" [LK-030A] > 32 2E 74 78 74 22 2C 22 66 69 6C 65 53 69 7A 65 | ,"fileSize [LK-030A] > 22 3A 31 31 35 31 2C 22 63 6F 6E 66 6C 69 63 74 | ":1151,"conflictStrategy" [LK-030A] > 53 74 72 61 74 65 67 79 22 3A 22 6F 76 65 72 77 | :"overwrite" [LK-030A] > 72 69 74 65 22 7D 7D | }} -
File upload response logs:
Response logs for the two files:
-
mqttuploadfile001.txt
[1637138923.214][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/init_reply [LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"data" [LK-030A] < 61 22 3A 7B 22 66 69 6C 65 4E 61 6D 65 22 3A 22 | :{"fileName":" [LK-030A] < 6D 71 74 74 75 70 6C 6F 61 64 66 69 6C 65 30 30 | mqttuploadfile001.txt" [LK-030A] < 31 2E 74 78 74 22 2C 22 75 70 6C 6F 61 64 49 64 | ,"uploadId [LK-030A] < 22 3A 22 6B 54 48 76 63 47 45 31 78 58 56 48 33 | ":"kTHvcGE1xXVH3 [LK-030A] < 46 79 44 4C 34 4C 55 30 31 30 32 30 30 22 2C 22 | FyDL4LU******"," [LK-030A] < 6F 66 66 73 65 74 22 3A 30 2C 22 66 69 6C 65 53 | offset":0,"fileSize" [LK-030A] < 69 7A 65 22 3A 32 30 34 38 2C 22 63 6F 6E 66 6C | :2048,"conflictStrategy" [LK-030A] < 69 63 74 53 74 72 61 74 65 67 79 22 3A 22 6F 76 | :"overwrite"} [LK-030A] < 65 72 77 72 69 74 65 22 7D 2C 22 69 64 22 3A 22 | ,"id":"1" [LK-030A] < 31 22 2C 22 6D 65 73 73 61 67 65 22 3A 22 73 75 | ,"message": [LK-030A] < 63 63 65 73 73 22 7D | "success"} test_userdata:100 Open mqttuploadfile001.txt read at: 0 -
mqttuploadfile002.txt
[LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"data" [LK-030A] < 61 22 3A 7B 22 66 69 6C 65 4E 61 6D 65 22 3A 22 | :{"fileName":" [LK-030A] < 6D 71 74 74 75 70 6C 6F 61 64 66 69 6C 65 30 30 | mqttuploadfile002.txt" [LK-030A] < 32 2E 74 78 74 22 2C 22 75 70 6C 6F 61 64 49 64 | ,"uploadId [LK-030A] < 22 3A 22 6B 6F 48 54 45 4B 46 34 59 58 31 6E 61 | ":"koHTEKF4YX1na [LK-030A] < 46 30 74 49 33 43 35 30 31 30 32 30 30 22 2C 22 | F0tI3C5******"," [LK-030A] < 6F 66 66 73 65 74 22 3A 30 2C 22 66 69 6C 65 53 | offset":0,"fileSize" [LK-030A] < 69 7A 65 22 3A 31 31 35 31 2C 22 63 6F 6E 66 6C | :1151, [LK-030A] < 69 63 74 53 74 72 61 74 65 67 79 22 3A 22 6F 76 | "conflictStrategy": [LK-030A] < 65 72 77 72 69 74 65 22 7D 2C 22 69 64 22 3A 22 | "overwrite"},"id":" [LK-030A] < 32 22 2C 22 6D 65 73 73 61 67 65 22 3A 22 73 75 | 2","message": [LK-030A] < 63 63 65 73 73 22 7D | "success"}
-
-
File read logs:
After IoT Platform responds and triggers the callback, the file read logs are:
-
mqttuploadfile001.txt
Open mqttuploadfile001.txt read at: 0 Read_len: 1024 [1637138923.215][LK-2014] Read data_len:1024[1637138923.215][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send [LK-030A] > 00 55 7B 22 69 64 22 3A 22 34 22 2C 22 70 61 72 | .U{"id":"4","params" [LK-030A] > 61 6D 73 22 3A 7B 22 75 70 6C 6F 61 64 49 64 22 | :{"uploadId" [LK-030A] > 3A 22 6B 54 48 76 63 47 45 31 78 58 56 48 33 46 | :"kTHvcGE1xXVH3F [LK-030A] > 79 44 4C 34 4C 55 30 31 30 32 30 30 22 2C 22 6F | yDL4LU******", [LK-030A] > 66 66 73 65 74 22 3A 30 2C 22 62 53 69 7A 65 22 | "offset":0,"bSize" [LK-030A] > 3A 31 30 32 34 7D 7D 55 4E 41 56 41 4F 4F 56 4C | :1024}}UNAVAOOVL [LK-030A] > 53 43 58 4C 57 59 43 54 5A 58 45 4C 47 43 4E 57 | SCXLWYCTZXELGCNW [LK-030A] > 58 55 55 41 46 54 47 46 46 42 4D 46 48 48 54 59 | XUUAFTGFFBMFHHTY [LK-030A] > 52 59 46 58 44 49 57 45 4A 4E 50 47 46 4A 49 45 | RYFXDIWEJNPGFJIE [LK-030A] > 4E 43 55 43 50 4B 54 57 54 50 4F 4F 49 45 4B 4C | NCUCPKTWTPOOIEKL [LK-030A] > 4F 5A 54 55 55 42 4C 4B 58 5A 48 59 4D 4A 49 43 | OZTUUBLKXZHYMJIC [LK-030A] > 46 41 4E 54 49 41 59 41 46 4E 4B 4D 52 4F 43 51 | FANTIAYAFNKMROCQ [LK-030A] > 48 4F 43 56 44 59 54 51 59 57 52 4D 48 4E 42 50 | HOCVDYTQY****** ...... ...... ...... -
mqttuploadfile002.txt
Open mqttuploadfile002.txt read at: 0 Read_len: 1024 [1637138923.216][LK-2014] Read data_len:1024[1637138923.216][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send [LK-030A] > 00 55 7B 22 69 64 22 3A 22 33 22 2C 22 70 61 72 | .U{"id":"3","params" [LK-030A] > 61 6D 73 22 3A 7B 22 75 70 6C 6F 61 64 49 64 22 | :{"uploadId" [LK-030A] > 3A 22 6B 6F 48 54 45 4B 46 34 59 58 31 6E 61 46 | :"koHTEKF4YX1naF [LK-030A] > 30 74 49 33 43 35 30 31 30 32 30 30 22 2C 22 6F | 0tI3C5******", [LK-030A] > 66 66 73 65 74 22 3A 30 2C 22 62 53 69 7A 65 22 | "offset":0,"bSize" [LK-030A] > 3A 31 30 32 34 7D 7D 55 4E 41 56 41 4F 4F 56 4C | :1024}}UNAVAOOVL [LK-030A] > 53 43 58 4C 57 59 43 54 5A 58 45 4C 47 43 4E 57 | SCXLWYCTZXELGCNW [LK-030A] > 58 55 55 41 46 54 47 46 46 42 4D 46 48 48 54 59 | XUUAFTGFFBMFHHTY [LK-030A] > 52 59 46 58 44 49 57 45 4A 4E 50 47 46 4A 49 45 | RYFXDIWEJNPGFJIE [LK-030A] > 4E 43 55 43 50 4B 54 57 54 50 4F 4F 49 45 4B 4C | NCUCPKTWTPOOIEKL [LK-030A] > 4F 5A 54 55 55 42 4C 4B 58 5A 48 59 4D 4A 49 43 | OZTUUBLKXZHYMJIC [LK-030A] > 46 41 4E 54 49 41 59 41 46 4E 4B 4D 52 4F 43 51 | FANTIAYAFNKMROCQ [LK-030A] > 48 4F 43 56 44 59 54 51 59 57 52 4D 48 4E 42 50 | HOCVDYTQYW****** ...... ...... ......
-
-
Upload status monitoring logs:
After upload completes, IoT Platform returns status information:
-
mqttuploadfile001.txt
NoteThis file uses CRC64 integrity validation, so the log includes the validated CRC64 value.
[1637138924.099][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send_reply [LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"data" [LK-030A] < 61 22 3A 7B 22 66 69 63 56 61 6C 75 65 43 6C 69 | :{"ficValueCli [LK-030A] < 65 6E 74 22 3A 22 66 34 38 66 34 33 37 64 35 35 | ent":"f48f437d55 [LK-030A] < 64 34 37 31 34 63 22 2C 22 66 69 63 4D 6F 64 65 | ******","ficMode [LK-030A] < 22 3A 22 63 72 63 36 34 22 2C 22 75 70 6C 6F 61 | ":"crc64","uploadId" [LK-030A] < 64 49 64 22 3A 22 6B 54 48 76 63 47 45 31 78 58 | :"kTHvcGE1xX [LK-030A] < 56 48 33 46 79 44 4C 34 4C 55 30 31 30 32 30 30 | VH3FyDL4LU****** [LK-030A] < 22 2C 22 6F 66 66 73 65 74 22 3A 31 30 32 34 2C | ","offset":1024, [LK-030A] < 22 63 6F 6D 70 6C 65 74 65 22 3A 74 72 75 65 2C | "complete":true, [LK-030A] < 22 66 69 63 56 61 6C 75 65 53 65 72 76 65 72 22 | "ficValueServer" [LK-030A] < 3A 22 66 34 38 66 34 33 37 64 35 35 64 34 37 31 | :"f48f437d55**** [LK-030A] < 34 63 22 2C 22 62 53 69 7A 65 22 3A 31 30 32 34 | **","bSize":1024 [LK-030A] < 7D 2C 22 69 64 22 3A 22 36 22 2C 22 6D 65 73 73 | },"id":"6","message" [LK-030A] < 61 67 65 22 3A 22 73 75 63 63 65 73 73 22 7D | :"success"} [1637138924.099][LK-2014] Upload total size:2048 -
mqttuploadfile002.txt
[1637138923.884][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send_reply [LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"data" [LK-030A] < 61 22 3A 7B 22 75 70 6C 6F 61 64 49 64 22 3A 22 | :{"uploadId":" [LK-030A] < 6B 6F 48 54 45 4B 46 34 59 58 31 6E 61 46 30 74 | koHTEKF4YX1naF0t [LK-030A] < 49 33 43 35 30 31 30 32 30 30 22 2C 22 6F 66 66 | I3C5******","offset" [LK-030A] < 73 65 74 22 3A 31 30 32 34 2C 22 63 6F 6D 70 6C | :1024,"complete" [LK-030A] < 65 74 65 22 3A 74 72 75 65 2C 22 62 53 69 7A 65 | :true,"bSize [LK-030A] < 22 3A 31 32 37 7D 2C 22 69 64 22 3A 22 35 22 2C | ":127},"id":"5", [LK-030A] < 22 6D 65 73 73 61 67 65 22 3A 22 73 75 63 63 65 | "message":"success" [LK-030A] < 73 73 22 7D | } [1637138923.884][LK-2014] Upload total size:1151
-
-
Program exit logs:
After upload completes, the program unsubscribes from related topics and exits.
[1637648533.379][LK-2124] Complete upload total size:2048 MQTT Upload file(mqttuploadfile001.txt) success [1637648534.407][LK-2100] Finish upload,Deleted upload task. MQTT Upload file(mqttuploadfile002.txt) success [1637648534.407][LK-210F] aiot_mqtt_upload_deinit [1637648534.407][LK-0309] unsub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/init_reply [1637648534.408][LK-0309] unsub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/send_reply [1637648534.408][LK-0309] unsub: /sys/a18wP******/LightSwitch/thing/file/upload/mqtt/cancel_reply [1637648534.513][LK-1000] adapter_network_deinit
IoT Platform logs
Manage uploaded files and view runtime logs in the IoT Platform console.
-
To view uploaded files, go to Device Management > Devices. Click View for the target device, and then select the File Management tab.
The file list shows the file name, size, upload time, and operations. You can Download or Delete uploaded files.
-
In the left-side navigation pane, go to . Select the relevant product to view device file upload logs.
On the Cloud-side Runtime Log tab, the log list displays Time, TraceID, Message Content, DeviceName, Business Type, Operation, Content, and Status. For device file uploads, the business type is Device File Upload and the operation is FileUploadFinished. Status 200 indicates success.
Next steps
-
After configuring the sample file, compile it to create the executable file ./output/mqtt-upload-basic-demo. Compile and run the demo.
-
To troubleshoot error messages in the runtime logs, check the status code descriptions in aiot_mqtt_upload_api.h.