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.
  • Device connection logs

    [1626317181.277][LK-0313] MQTT user calls aiot_mqtt_connect api, connect
    [1626317181.277][LK-0317] LightSwitch&a1wP******
    [1626317181.277][LK-0318] 97B797D367BF307A0573979CF6CCA5675719F6790B361F2596E01B72AC6813B4
    core_sysdep_network_establish host iot-06******.mqtt.iothub.aliyuncs.comuncs.com port 1883, type 0
    establish tcp connection with server(host='iot-06******.mqtt.iothub.aliyuncs.comuncs.com', port=[1883])
    success to establish tcp, fd=3
    local port: 38522
    [1626317181.300][LK-1000] establish mbedtls connection with server(host='iot-06******.mqtt.iothub.aliyuncs.comuncs.com', port=[1883])
    [1626317181.388][LK-1000] success to establish mbedtls connection, (cost 44947 bytes in total, max used 47859 bytes)
    [1626317181.388][LK-0319] a1wP******.LightSwitch|timestamp=2524608000000,_ss=1,_v=sdk-c-4.1.0,securemode=2,signmethod=hmacsha256,ext=3,_conn=tls_6b|
    [1626317181.433][LK-0313] MQTT connect success in 161 ms
    AIOT_MQTTEVT_CONNECT
  • Logs generated when the device submits status data

    1. Request logs

      [1626317187.433][LK-0309] pub: /shadow/update/a1wP******/LightSwitch
      
      [LK-030A] > 7B 22 6D 65 74 68 6F 64  22 3A 22 75 70 64 61 74 | {"method":"update",
      [LK-030A] > 65 22 2C 22 73 74 61 74  65 22 3A 7B 22 72 65 70 | "state":{"reported"
      [LK-030A] > 6F 72 74 65 64 22 3A 7B  22 4C 69 67 68 74 53 77 | :{"LightSwitch"
      [LK-030A] > 69 74 63 68 22 3A 31 7D  7D 2C 22 76 65 72 73 69 | :1}},"versi
      [LK-030A] > 6F 6E 22 3A 30 7D                                | on":0}
    2. Response logs

      [1626317187.477][LK-0309] pub: /shadow/get/a1wP******/LightSwitch
      
      [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 72 65 70 6C 79 | {"method":"reply
      [LK-030A] < 22 2C 22 70 61 79 6C 6F  61 64 22 3A 7B 22 73 74 | ","payload":{"st
      [LK-030A] < 61 74 75 73 22 3A 22 73  75 63 63 65 73 73 22 2C | atus":"success",
      [LK-030A] < 22 76 65 72 73 69 6F 6E  22 3A 30 7D 2C 22 63 6C | "version":0},"cl
      [LK-030A] < 69 65 6E 74 54 6F 6B 65  6E 22 3A 22 6E 75 6C 6C | ientToken":"null
      [LK-030A] < 22 2C 22 74 69 6D 65 73  74 61 6D 70 22 3A 31 36 | ","timestamp":16
      [LK-030A] < 32 36 33 31 37 31 38 37  7D                      | 26317187}
      
      [1626317187.477][LK-1304] SHADOW recv get_reply message
      demo_shadow_recv_handler, type = 0, productKey = a1wP******, deviceName = LightSwitch
      payload = "{"status":"success","version":0}", status = success, timestamp = 1626317187
  • Logs generated when applications change the device status
    1. IoT Platform sends a desired property to the device.

      In this example, IoT Platform sends the {"LightSwitch":0} desired property to the device. After the device receives the message, the following log data is printed:

      [1626319658.166][LK-0309] pub: /shadow/get/a1wP******/LightSwitch
      
      [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 63 6F 6E 74 72 | {"method":"contr
      [LK-030A] < 6F 6C 22 2C 22 70 61 79  6C 6F 61 64 22 3A 7B 22 | ol","payload":{"
      [LK-030A] < 73 74 61 74 65 22 3A 7B  22 64 65 73 69 72 65 64 | state":{"desired
      [LK-030A] < 22 3A 7B 22 4C 69 67 68  74 53 77 69 74 63 68 22 | ":{"LightSwitch"
      [LK-030A] < 3A 30 7D 7D 2C 22 6D 65  74 61 64 61 74 61 22 3A | :0}},"metadata":
      [LK-030A] < 7B 22 64 65 73 69 72 65  64 22 3A 7B 22 4C 69 67 | {"desired":{"Lig
      [LK-030A] < 68 74 53 77 69 74 63 68  22 3A 7B 22 74 69 6D 65 | htSwitch":{"time
      [LK-030A] < 73 74 61 6D 70 22 3A 31  36 32 36 33 31 39 36 35 | stamp":162631965
      [LK-030A] < 38 7D 7D 7D 7D 2C 22 74  69 6D 65 73 74 61 6D 70 | 8}}}},"timestamp
      [LK-030A] < 22 3A 31 36 32 36 33 31  39 36 35 38 2C 22 76 65 | ":1626319658,"ve
      [LK-030A] < 72 73 69 6F 6E 22 3A 34  7D                      | rsion":0}
      
      [1626319658.166][LK-1304] SHADOW recv control message
      demo_shadow_recv_handler, type = 1, productKey = a1wP******, deviceName = LightSwitch
      payload = "{"state":{"desired":{"LightSwitch":0}},"metadata":{"desired":{"LightSwitch":{"timestamp":1626319658}}}}", version = 4
    2. The device submits the latest property after updating the local property.

      Important The sample code is for demonstration only. In actual business scenarios, you must specify the processing logic to automatically update the local property.
      [1626317203.433][LK-0309] pub: /shadow/update/a1wP******/LightSwitch
      
      [LK-030A] > 7B 22 6D 65 74 68 6F 64  22 3A 22 75 70 64 61 74 | {"method":"update",
      [LK-030A] > 65 22 2C 22 73 74 61 74  65 22 3A 7B 22 72 65 70 | "state":{"rep
      [LK-030A] > 6F 72 74 65 64 22 3A 7B  22 4C 69 67 68 74 53 77 | orted":{"LightSw
      [LK-030A] > 69 74 63 68 22 3A 31 7D  7D 2C 22 76 65 72 73 69 | itch":0}},"versi
      [LK-030A] > 6F 6E 22 3A 30 7D                                | on":1}
    3. The device sends a request to delete the desired property in IoT Platform.

      [1626320515.566][LK-0309] pub: /shadow/update/a1wP******/LightSwitch
      
      [LK-030A] > 7B 22 6D 65 74 68 6F 64  22 3A 22 75 70 64 61 74 | {"method":"update",
      [LK-030A] > 65 22 2C 22 73 74 61 74  65 22 3A 7B 22 64 65 73 | "state":{"desired"
      [LK-030A] > 69 72 65 64 22 3A 22 6E  75 6C 6C 22 7D 2C 22 76 | :"null"},"version"
      [LK-030A] > 65 72 73 69 6F 6E 22 3A  35 7D                   | :2}
      
                                  
    4. IoT Platform returns a response.

      [1626320515.600][LK-0309] pub: /shadow/get/a1wP******/LightSwitch
      
      [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 72 65 70 6C 79 | {"method":"reply
      [LK-030A] < 22 2C 22 70 61 79 6C 6F  61 64 22 3A 7B 22 73 74 | ","payload":{"st
      [LK-030A] < 61 74 75 73 22 3A 22 73  75 63 63 65 73 73 22 2C | atus":"success",
      [LK-030A] < 22 76 65 72 73 69 6F 6E  22 3A 35 7D 2C 22 63 6C | "version":5},"cl
      [LK-030A] < 69 65 6E 74 54 6F 6B 65  6E 22 3A 22 6E 75 6C 6C | ientToken":"null
      [LK-030A] < 22 2C 22 74 69 6D 65 73  74 61 6D 70 22 3A 31 36 | ","timestamp":16
      [LK-030A] < 32 36 33 32 30 35 31 35  7D                      | 26320515}
      
      [1626320515.600][LK-1304] SHADOW recv get_reply message
      demo_shadow_recv_handler, type = 0, productKey = a1wP******, deviceName = LightSwitch
      payload = "{"status":"success","version":5}", status = success, timestamp = 1626320515
  • Logs generated when the device requests the device shadow
    • Request logs

      [1626320690.499][LK-0309] pub: /shadow/update/a1wP******/LightSwitch
      
      [LK-030A] > 7B 22 6D 65 74 68 6F 64  22 3A 22 67 65 74 22 7D | {"method":"get"}
    • Response logs:

      The following log data indicates that the desired property and submitted property do not exist in the device shadow:

      [1626320690.522][LK-0309] pub: /shadow/get/a1wP******/LightSwitch
      
      [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 72 65 70 6C 79 | {"method":"reply
      [LK-030A] < 22 2C 22 70 61 79 6C 6F  61 64 22 3A 7B 22 73 74 | ","payload":{"st
      [LK-030A] < 61 74 75 73 22 3A 22 73  75 63 63 65 73 73 22 2C | atus":"success",
      [LK-030A] < 22 73 74 61 74 65 22 3A  7B 22 72 65 70 6F 72 74 | "state":{"report
      [LK-030A] < 65 64 22 3A 7B 7D 7D 2C  22 6D 65 74 61 64 61 74 | ed":{}},"metadat
      [LK-030A] < 61 22 3A 7B 22 72 65 70  6F 72 74 65 64 22 3A 7B | a":{"reported":{
      [LK-030A] < 7D 7D 7D 2C 22 74 69 6D  65 73 74 61 6D 70 22 3A | }}},"timestamp":
      [LK-030A] < 31 36 32 36 33 32 30 36  39 30 2C 22 76 65 72 73 | 1626320690,"vers
      [LK-030A] < 69 6F 6E 22 3A 35 2C 22  63 6C 69 65 6E 74 54 6F | ion":5,"clientTo
      [LK-030A] < 6B 65 6E 22 3A 22 6E 75  6C 6C 22 7D             | ken":"null"}
      
      [1626320690.522][LK-1304] SHADOW recv generic_reply message
      demo_shadow_recv_handler, type = 2, productKey = a1wP******, deviceName = LightSwitch
      payload = "{"status":"success","state":{"reported":{}},"metadata":{"reported":{}}}", version = 5
  • Logs generated when the device deletes all properties in the device shadow
    1. Request logs

      The following log data indicates that the device wants to delete all properties:

      [1626321049.222][LK-0309] pub: /shadow/update/a1wP******/LightSwitch
      
      [LK-030A] > 7B 22 6D 65 74 68 6F 64  22 3A 22 64 65 6C 65 74 | {"method":"delete",
      [LK-030A] > 65 22 2C 22 73 74 61 74  65 22 3A 7B 22 72 65 70 | "state":{"reported"
      [LK-030A] > 6F 72 74 65 64 22 3A 7B  22 4C 69 67 68 74 53 77 | :{"LightSwitch"
      [LK-030A] > 69 74 63 68 22 3A 22 6E  75 6C 6C 22 7D 7D 2C 22 | :"null"}},"
      [LK-030A] > 76 65 72 73 69 6F 6E 22  3A 39 7D                | version":2}
                                  
    2. Response logs

      The following log data indicates that IoT Platform receives the request:

      [1626321049.255][LK-0309] pub: /shadow/get/a1wP******/LightSwitch
      
      [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 72 65 70 6C 79 | {"method":"reply
      [LK-030A] < 22 2C 22 70 61 79 6C 6F  61 64 22 3A 7B 22 73 74 | ","payload":{"st
      [LK-030A] < 61 74 75 73 22 3A 22 73  75 63 63 65 73 73 22 2C | atus":"success",
      [LK-030A] < 22 76 65 72 73 69 6F 6E  22 3A 39 7D 2C 22 63 6C | "version":2},"cl
      [LK-030A] < 69 65 6E 74 54 6F 6B 65  6E 22 3A 22 6E 75 6C 6C | ientToken":"null
      [LK-030A] < 22 2C 22 74 69 6D 65 73  74 61 6D 70 22 3A 31 36 | ","timestamp":16
      [LK-030A] < 32 36 33 32 31 30 34 39  7D                      | 26321049}
      
      [1626321049.255][LK-1304] SHADOW recv get_reply message
      demo_shadow_recv_handler, type = 0, productKey = a1wP******, deviceName = LightSwitch
      payload = "{"status":"success","version":2}", status = success, timestamp = 1626321049

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 Devices > Devices. 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. View the device status
  • Operation logs

  • In the left-side navigation pane, choose Maintenance > Device Log. Select a product to Select a product to view logs about device shadows.