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.
    MQTT user calls aiot_mqtt_connect api, connect
    [1626148815.622][LK-0317] LightSwitch&a18wP******
    [1626148815.622][LK-0318] 728C51A4282A798B10D05C0B43CAFA81DF59D4AE6602901A426C149C76******
    core_sysdep_network_establish host a18wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com port 443, type 0
    establish tcp connection with server(host='a18wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443])
    success to establish tcp, fd=3
    local port: 48434
    [1626148815.699][LK-1000] establish mbedtls connection with server(host='a18wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443])
    [1626148815.755][LK-1000] success to establish mbedtls connection, (cost 44947 bytes in total, max used 47859 bytes)
    [1626148815.755][LK-0319] a18wP******.LightSwitch|timestamp=2524608000000,_ss=1,_v=sdk-c-4.1.0,securemode=2,signmethod=hmacsha256,ext=3,_conn=tls_7f|
    [1626148815.822][LK-0313] MQTT connect success in 197 ms
    AIOT_MQTTEVT_CONNECT
  • Request logs

    After the connection is established, the device sends an NTP service request to IoT Platform and submits the current time of the device by using the /ext/ntp/a18wP******/LightSwitch/request topic.

    [1626148815.822][LK-0309] pub: /ext/ntp/a18wP******/LightSwitch/request
    
    [LK-030A] > 7B 22 64 65 76 69 63 65  53 65 6E 64 54 69 6D 65 | {"deviceSendTime
    [LK-030A] > 22 3A 22 31 36 32 36 31  34 38 38 31 35 38 32 35 | ":"1626148815825
    [LK-030A] > 22 7D                                            | "}
  • Logs about downstream response

    After IoT Platform receives the NTP service request, IoT Platform returns the server time to the device by using the /ext/ntp/a18wP******/LightSwitch/response topic. After the device parses and processes the response data, the following log data is printed.

    The time zone that is set in the request is UTC+8. 1626148815862 indicates the local time of the device, which is 2021/07/13-12:00:15:862 UTC+8.

    [1626148815.844][LK-0309] pub: /ext/ntp/a18wP******/LightSwitch/response
    
    [LK-030A] < 7B 22 64 65 76 69 63 65  53 65 6E 64 54 69 6D 65 | {"deviceSendTime
    [LK-030A] < 22 3A 22 31 36 32 36 31  34 38 38 31 35 38 32 35 | ":"1626148815825
    [LK-030A] < 22 2C 22 73 65 72 76 65  72 53 65 6E 64 54 69 6D | ","serverSendTim
    [LK-030A] < 65 22 3A 22 31 36 32 36  31 34 38 38 31 35 38 35 | e":"162614881585
    [LK-030A] < 35 22 2C 22 73 65 72 76  65 72 52 65 63 76 54 69 | 5","serverRecvTi
    [LK-030A] < 6D 65 22 3A 22 31 36 32  36 31 34 38 38 31 35 38 | me":"16261488158
    [LK-030A] < 35 34 22 7D                                      | 54"}
    
    local time: 1626148815862, 2021/07/13-12:00:15:862

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

    After the device goes online, it automatically subscribes to system topics. The following log data is generated.