After you run the MQTT connection sample code, on the device and in the IoT Platform console, you can view the logs.
Prerequisites
The MQTT connection sample code for the C Link SDK has been configured and run. For more information, see Usage example.
Device logs
View the running results on the device.
-
Connection logs:
The following logs indicate that the device has successfully connected to IoT Platform.
[1619768570.433][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1619768570.433][LK-0317] LightSwitch&a18wP****** [1619768570.433][LK-0318] 933FE333F78F42E2AAD384F629C771277E06D459577942EA1F04ACFDFE****** 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: 49122 [1619768570.599][LK-1000] establish mbedtls connection with server(host='a18wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443]) [1619768570.600][LK-1000] success to establish mbedtls connection, (cost 45134 bytes in total, max used 47870 bytes) [1619768570.644][LK-0313] MQTT connect success in 212 ms AIOT_MQTTEVT_CONNECT -
Topic subscription logs:
If you configured the code to subscribe to a topic, the device prints the following log, indicating that the device has subscribed to the topic, for example,
/a18wP******/LightSwitch/user/get.[1620373302.144][LK-0309] sub: /a18wP******/LightSwitch/user/getAfter you successfully subscribe to a topic, you can log in to the IoT Platform console. On the Device Details page, go to the Topic List tab, click Publish Message in the Actions column of the subscribed topic, and then in the Publish Message dialog box, enter a message (such as This is a test message from Alibaba Iot Platform.) in the message input box to simulate sending a message from the IoT Platform to the device.
After a message is sent, the device prints the following logs through demo_mqtt_default_recv_handler, 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. -
Message publishing logs:
If you configured the code to send messages, the device prints the following logs, indicating that the device has sent a message to IoT Platform over a topic, such as
/a18wP******/LightSwitch/user/update.[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
View the device status and logs in the IoT Platform console.
-
In the left-side navigation pane, choose . Find your device and check its status. A status of Online indicates that the device is successfully connected to IoT Platform.
-
In the left navigation bar, select , select a product, and then view the logs for device connections, topic subscriptions, and published messages.
Click the Cloud-side Run Logs tab and confirm that the status code for the device connection, subscription, and message publishing logs is 200. A status code of 200 indicates successful communication.
Next steps
For error messages in the run logs, see Common error codes and follow the instructions to resolve the issue.