After you use the sample code to connect a device to IoT Platform over Message Queuing Telemetry Transport (MQTT), you can view logs on the device.
Prerequisites
For more information, see Example.
Device logs
You can view the running result on the device.Device connection logs
The following log data indicates that the device is connected to IoT Platform.[1626431132.366][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1626431132.366][LK-0317] LightSwitch&a1wP****** [1626431132.366][LK-0318] 5C54B1B76214AC58DAB9F83927719D3340B105E20C40DDA68B659DF7E0****** core_sysdep_network_establish host iot-06******.mqtt.iothub.aliyuncs.com port 443, type 0 establish tcp connection with server(host='iot-06******.mqtt.iothub.aliyuncs.com', port=[443]) success to establish tcp, fd=3 local port: 38884 [1626431132.399][LK-1000] establish mbedtls connection with server(host='iot-06******.mqtt.iothub.aliyuncs.com', port=[443]) [1626431132.466][LK-1000] success to establish mbedtls connection, (cost 44947 bytes in total, max used 47859 bytes) [1626431132.466][LK-0319] a1wP******.LightSwitch|timestamp=2524608000000,_ss=1,_v=sdk-c-4.1.0,securemode=2,signmethod=hmacsha256,ext=3,_conn=tls_66| [1626431132.500][LK-0313] MQTT connect success in 146 ms AIOT_MQTTEVT_CONNECT
Logs generated when you initiate a log uploading request to IoT Platform
Request logs
[1626431132.500][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/config/log/get [LK-030A] > 7B 22 69 64 22 3A 22 31 22 2C 22 76 65 72 73 69 | {"id":"1","versi [LK-030A] > 6F 6E 22 3A 22 31 2E 30 22 2C 22 70 61 72 61 6D | on":"1.0","param [LK-030A] > 73 22 3A 7B 22 67 65 74 54 79 70 65 22 3A 22 63 | s":{"getType":"c [LK-030A] > 6F 6E 74 65 6E 74 22 2C 22 63 6F 6E 66 69 67 53 | ontent","configS [LK-030A] > 63 6F 70 65 22 3A 22 64 65 76 69 63 65 22 7D 7D | cope":"device"}} [1626431132.500][LK-1507] sys log config is on, toggle it using AIOT_LOGPOSTOPT_SYS_LOG.
- Response logs
The following log data indicates that IoT Platform returns a response:
[1626431132.544][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/config/log/get_reply [LK-030A] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"dat [LK-030A] < 61 22 3A 7B 22 63 6F 6E 74 65 6E 74 22 3A 7B 22 | a":{"content":{" [LK-030A] < 6D 6F 64 65 22 3A 31 7D 2C 22 67 65 74 54 79 70 | mode":1},"getTyp [LK-030A] < 65 22 3A 22 63 6F 6E 74 65 6E 74 22 7D 2C 22 69 | e":"content"},"i [LK-030A] < 64 22 3A 22 31 22 2C 22 6D 65 74 68 6F 64 22 3A | d":"1","method": [LK-030A] < 22 74 68 69 6E 67 2E 63 6F 6E 66 69 67 2E 6C 6F | "thing.config.lo [LK-030A] < 67 2E 67 65 74 22 2C 22 76 65 72 73 69 6F 6E 22 | g.get","version" [LK-030A] < 3A 22 31 2E 30 22 7D | :"1.0"} [1626431132.544][LK-1507] LOGPOST user log config arrived user log switch state is: 1 toggle it using the switch in device detail page in https://iot.console.aliyun.com
Logs generated when you upload system logs
[1626431132.500][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/log/post [LK-030A] > 7B 22 69 64 22 3A 22 32 22 2C 22 76 65 72 73 69 | {"id":"2","versi [LK-030A] > 6F 6E 22 3A 22 31 2E 30 22 2C 22 70 61 72 61 6D | on":"1.0","param [LK-030A] > 73 22 3A 5B 7B 22 75 74 63 54 69 6D 65 22 3A 22 | s":[{"utcTime":" [LK-030A] > 32 30 32 31 2F 37 2F 31 36 20 31 38 3A 32 35 3A | 2021/7/16 18:25: [LK-030A] > 33 32 22 2C 22 6C 6F 67 4C 65 76 65 6C 22 3A 22 | 32","logLevel":" [LK-030A] > 49 4E 46 4F 22 2C 22 6D 6F 64 75 6C 65 22 3A 22 | INFO","module":" [LK-030A] > 6E 65 74 5F 63 6F 6E 6E 22 2C 22 63 6F 64 65 22 | net_conn","code" [LK-030A] > 3A 22 32 30 30 22 2C 22 74 72 61 63 65 43 6F 6E | :"200","traceCon [LK-030A] > 74 65 78 74 22 3A 22 30 22 2C 22 6C 6F 67 43 6F | text":"0","logCo [LK-030A] > 6E 74 65 6E 74 22 3A 22 74 69 6D 65 3D 31 36 32 | ntent":"time=162 [LK-030A] > 36 34 33 31 31 33 32 33 36 31 5E 63 6F 6E 6E 5F | 6431132361^conn_ [LK-030A] > 74 79 70 65 3D 54 4C 53 5E 63 6F 6E 6E 5F 63 6F | type=TLS^conn_co [LK-030A] > 73 74 3D 31 30 32 5E 63 6F 6E 6E 5F 72 65 74 3D | st=102^conn_ret= [LK-030A] > 30 22 7D 5D 7D | 0"}]} [1626431132.500][LK-1507] sys log config is on, toggle it using AIOT_LOGPOSTOPT_SYS_LOG.
Logs generated when you upload business logs
[1626431142.500][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/log/post [LK-030A] > 7B 22 69 64 22 3A 22 34 22 2C 22 76 65 72 73 69 | {"id":"4","versi [LK-030A] > 6F 6E 22 3A 22 31 2E 30 22 2C 22 70 61 72 61 6D | on":"1.0","param [LK-030A] > 73 22 3A 5B 7B 22 75 74 63 54 69 6D 65 22 3A 22 | s":[{"utcTime":" [LK-030A] > 32 30 32 31 2F 37 2F 31 36 20 31 38 3A 32 35 3A | 2021/7/16 18:25: [LK-030A] > 34 32 22 2C 22 6C 6F 67 4C 65 76 65 6C 22 3A 22 | 42","logLevel":" [LK-030A] > 44 45 42 55 47 22 2C 22 6D 6F 64 75 6C 65 22 3A | DEBUG","module": [LK-030A] > 22 41 50 50 22 2C 22 63 6F 64 65 22 3A 22 32 30 | "APP","code":"20 [LK-030A] > 30 22 2C 22 74 72 61 63 65 43 6F 6E 74 65 78 74 | 0","traceContext [LK-030A] > 22 3A 22 30 22 2C 22 6C 6F 67 43 6F 6E 74 65 6E | ":"0","logConten [LK-030A] > 74 22 3A 22 6C 6F 67 20 69 6E 20 77 68 69 6C 65 | t":"log in while [LK-030A] > 28 31 29 22 7D 5D 7D | (1)"}]}
IoT Platform logs
Log on to the IoT Platform console to view the device status and operation logs.
Device status
In the left-side navigation pane, choose . Then, find the device and view the device status. If the value in the State/Enabled column is Online, the device is connected to IoT Platform.Operation logs
In the left-side navigation pane, choose After select the product, click . Select a product to Cloud run log and Device local log to view IoT Platform logs and local device logs generated when you upload logs.- IoT Platform logs
- Local device logs