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.
Background information
For more information, see Example.
Device logs
You can view the running result on the device.Request logs
The following log data indicates that the device initiates a distribution request to IoT Platform.
core_sysdep_network_establish host iot-auth-global.aliyuncs.com port 443, type 0 establish tcp connection with server(host='iot-auth-global.aliyuncs.com', port=[443]) success to establish tcp, fd=3 local port: 37124 [1626074474.366][LK-1000] establish mbedtls connection with server(host='iot-auth-global.aliyuncs.com', port=[443]) [1626074474.466][LK-1000] success to establish mbedtls connection, (cost 45366 bytes in total, max used 48070 bytes) [1626074474.466][LK-040B] > POST /auth/bootstrap HTTP/1.1 [1626074474.466][LK-040B] > Host: iot-auth-global.aliyuncs.com [1626074474.466][LK-040B] > Accept: text/xml,text/javascript,text/html,application/json [1626074474.466][LK-040B] > Content-Type: application/x-www-form-urlencoded;charset=utf-8 [1626074474.466][LK-040B] > Content-Length: 111 [1626074474.466][LK-040B] > [LK-040C] > 70 72 6F 64 75 63 74 4B 65 79 3D 67 37 68 30 67 | productKey=a18** [LK-040C] > 35 77 72 79 34 51 26 64 65 76 69 63 65 4E 61 6D | ******&deviceNam [LK-040C] > 65 3D 4C 69 67 68 74 53 77 69 74 63 68 42 6F 6F | e=LightSwitch&cl [LK-040C] > 74 73 74 72 61 70 26 63 6C 69 65 6E 74 49 64 3D | ientId=a18****** [LK-040C] > 67 37 68 30 67 35 77 72 79 34 51 2E 4C 69 67 68 | **.LightSwitch&r [LK-040C] > 74 53 77 69 74 63 68 42 6F 6F 74 73 74 72 61 70 | esources=mqtt [LK-040C] > 26 72 65 73 6F 75 72 63 65 73 3D 6D 71 74 74 |
- Logs about downstream response
The following log data indicates that IoT Platform receives the request, and then returns an endpoint and port number to the device.
[1626074474.566][LK-040D] < HTTP/1.1 200 OK [1626074474.566][LK-040D] < Server: Tengine [1626074474.566][LK-040D] < Date: Mon, 12 Jul 2021 07:21:14 GMT [1626074474.566][LK-040D] < Content-Type: text/xml [1626074474.566][LK-040D] < Content-Length: 174 [1626074474.566][LK-040D] < Connection: keep-alive [1626074474.566][LK-040D] < X-Application-Context: iotx-base:oxs-shanghai-global-dns:7001 [1626074474.566][LK-040D] < [LK-040E] < 7B 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 61 74 | {"code":200,"dat [LK-040E] < 61 22 3A 7B 22 69 6E 73 74 61 6E 63 65 49 64 22 | a":{"instanceId" [LK-040E] < 3A 22 69 6F 74 2D 30 36 30 61 30 35 66 63 22 2C | :"iot-06******", [LK-040E] < 22 72 65 73 6F 75 72 63 65 73 22 3A 7B 22 6D 71 | "resources":{"mq [LK-040E] < 74 74 22 3A 7B 22 68 6F 73 74 22 3A 22 69 6F 74 | tt":{"host":"iot [LK-040E] < 2D 30 36 30 61 30 35 66 63 2E 6D 71 74 74 2E 69 | -06******.mqtt.i [LK-040E] < 6F 74 68 75 62 2E 61 6C 69 79 75 6E 63 73 2E 63 | othub.aliyuncs.c [LK-040E] < 6F 6D 22 2C 22 69 70 22 3A 22 31 30 31 2E 31 33 | om","ip":"101.13 [LK-040E] < 33 2E 31 36 36 2E 31 37 32 22 2C 22 70 6F 72 74 | 3.***.***","port [LK-040E] < 22 3A 31 38 38 33 7D 7D 7D 2C 22 6D 65 73 73 61 | ":1883}}},"messa [LK-040E] < 67 65 22 3A 22 73 75 63 63 65 73 73 22 7D | ge":"success"} status code: 200 host: iot-06******.mqtt.iothub.aliyuncs.com, port: 1883
Device connection logs
The following log data indicates that the device establishes a connection with IoT Platform by using the endpoint and port number.
[1626074474.566][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1626074474.566][LK-0317] LightSwitch&a18******** [1626074474.566][LK-0318] 7E8240C1708B26EEF60062B1CAF756DE2016FA5D7A780B0FC334702A37****** [1626074474.566][LK-031D] 101.133.***.*** core_sysdep_network_establish host iot-06******.mqtt.iothub.aliyuncs.com port 1883, type 0 establish tcp connection with server(host='iot-06******.mqtt.iothub.aliyuncs.com', port=[1883]) success to establish tcp, fd=4 local port: 60686 [1626074474.611][LK-1000] establish mbedtls connection with server(host='iot-06******.mqtt.iothub.aliyuncs.com', port=[1883]) [1626074474.677][LK-1000] success to establish mbedtls connection, (cost 44947 bytes in total, max used 47859 bytes) [1626074474.677][LK-0319] a18********.LightSwitch|timestamp=2524608000000,_ss=1,_v=sdk-c-4.1.0,securemode=2,signmethod=hmacsha256,ext=3,_conn=tls_72| [1626074474.733][LK-0313] MQTT connect success in 170 ms AIOT_MQTTEVT_CONNECT
Downstream notification logs
If you distribute the device again after the device is connected to IoT Platform, IoT Platform sends a notification to the device and the following log data is generated. The log data indicates that the device is distributed to a new region and deleted from the original region.
Important The following log data is generated only if you distribute the device again in IoT Platform.[1626163769.222][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/bootstrap/notify [LK-030A] < 7B 22 6D 65 74 68 6F 64 22 3A 22 74 68 69 6E 67 | {"method":"thing [LK-030A] < 2E 62 6F 6F 74 73 74 72 61 70 2E 6E 6F 74 69 66 | .bootstrap.notif [LK-030A] < 79 22 2C 22 69 64 22 3A 22 31 30 33 39 31 37 35 | y","id":"1039175 [LK-030A] < 33 38 31 22 2C 22 70 61 72 61 6D 73 22 3A 7B 22 | 381","params":{" [LK-030A] < 63 6D 64 22 3A 30 7D 2C 22 76 65 72 73 69 6F 6E | cmd":0},"version [LK-030A] < 22 3A 22 31 2E 30 2E 30 22 7D | ":"1.0.0"} AIOT_BOOTSTRAPRECV_NOTIFY, cmd: 0 [1626163769.222][LK-0309] pub: /sys/a1wP******/LightSwitch/thing/bootstrap/notify_reply [LK-030A] > 7B 22 69 64 22 3A 22 31 30 33 39 31 37 35 33 38 | {"id":"103917538 [LK-030A] > 31 22 2C 22 63 6F 64 65 22 3A 32 30 30 2C 22 64 | 1","code":200,"d [LK-030A] > 61 74 61 22 3A 7B 7D 7D | ata":{}} [1626163769.311][LK-0309] pub: /ext/notify [LK-030A] < 7B 22 74 69 74 6C 65 22 3A 22 6B 69 63 6B 22 2C | {"title":"kick", [LK-030A] < 22 63 6F 6E 74 65 6E 74 22 3A 22 4B 69 63 6B 65 | "content":"Kicke [LK-030A] < 64 20 64 75 65 20 74 6F 20 64 65 76 69 63 65 20 | d due to device [LK-030A] < 64 65 6C 65 74 65 64 22 7D | deleted"} pub, qos: 0, topic: /ext/notify pub, payload: {"title":"kick","content":"Kicked due to device deleted"}
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
After the device goes online, it automatically subscribes to system topics. The following log data is generated.