After you run the sample code to connect a device with IoT Platform by using an X.509 certificate, 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

The sample code in Link SDK for C is configured. 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.
    [1621852273.766][LK-0313] MQTT user calls aiot_mqtt_connect api, connect
    [1621852273.766][LK-0317] &
    [1621852273.766][LK-0318] B36DABAE2EBB7B8FA6FFD92B217E13D97C1AB196441561B0F71B3C3BF1******
    core_sysdep_network_establish host x509.itls.cn-shanghai.aliyuncs.com port 1883, type 0
    establish tcp connection with server(host='x509.itls.cn-shanghai.aliyuncs.com', port=[1883])
    success to establish tcp, fd=3
    local port: 54904
    [1621852273.766][LK-1000] establish mbedtls connection with server(host='x509.itls.cn-shanghai.aliyuncs.com', port=[1883])
    [1621852273.811][LK-1000] success to establish mbedtls connection, (cost 50730 bytes in total, max used 56818 bytes)
    [1621852273.899][LK-0313] MQTT connect success in 133 ms
    AIOT_MQTTEVT_CONNECT
  • Logs about downstream response

    After the device is connected to IoT Platform, IoT Platform returns the productKey and deviceName to the device. The following log data is printed.

    [1621852273.899][LK-0309] pub: /ext/auth/identity/response
    
    [LK-030A] < 7B 22 70 72 6F 64 75 63  74 4B 65 79 22 3A 22 61 | {"productKey":"a
    [LK-030A] < 31 76 63 61 4A 7A 48 50  50 61 22 2C 22 64 65 76 | 18wP******","dev
    [LK-030A] < 69 63 65 4E 61 6D 65 22  3A 22 4C 69 67 68 74 53 | iceName":"LightS
    [LK-030A] < 77 69 74 63 68 58 35 30  39 22 7D                | witch"}
    
    pub, qos: 0, topic: /ext/auth/identity/response
    pub, payload: {"productKey":"a18wP******","deviceName":"LightSwitch"}
    device productKey: a18wP******
    device deviceName: LightSwitch
    heartbeat response
    suback, res: -0x0000, packet id: 1, max qos: 1
  • Topic subscription logs

    If you configure the code to subscribe to a topic, the following log data is printed. The log data indicates that the device has subscribed to a topic. Example: /a18wP******/LightSwitch/user/get.
    [1620373302.144][LK-0309] sub: /a18wP******/LightSwitch/user/get
    After the topic subscription succeeds, you can log on to the IoT Platform console . On the Topic List tab of the Device Details page, find the topic and click Publish Message in the Actions column. In the Publish Message dialog box, enter a message. Example: This is a test message from Alibaba Iot Platform.. Then, send the message from IoT Platform to the device. topic
    After the message is sent, the device uses the demo_mqtt_default_recv_handler callback to print the log data. The following log data is printed based on the callback settings of demo_state_logcb.
    [1621912249.411][LK-0309] pub: /a18wP******LightSwitch/user/get
    
    [LK-030A] < 54 68 69 73 20 69 73 20  61 20 74 65 73 74 20 6D | This is a test m
    [LK-030A] < 65 73 73 61 67 65 20 66  72 6F 6D 20 41 6C 69 62 | essage from Alib
    [LK-030A] < 61 62 61 20 49 6F 54 20  50 6C 61 74 66 6F 72 6D | aba IoT Platform
    [LK-030A] < 2E                                               | .
    
    pub, qos: 0, topic: /a18wP******/LightSwitch/user/get
    pub, payload: This is a test message from Alibaba IoT Platform.
  • Logs about message sending

    If you configure the code to send a message sending code, the following log data is printed on the device.The log data indicates that the device uses a topic, for example, /a18wP******/LightSwitch/user/update, to send a message to IoT Platform.
    [1619768570.644][LK-0309] pub: /a18wP******/LightSwitch/user/update
    
    [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 4C 69 67  68 74 53 77 69 74 63 68 | s":{"LightSwitch
    [LK-030A] > 22 3A 30 7D 7D       

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 view the logs of the device that are generated when the device goes online, subscribes to the topic, and submits data to IoT Platform.

    Logs of X509 certificate-based connection