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 or in IoT Platform.
Prerequisites
A sample program that is written based on Link SDK for C is configured and run. 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.
[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 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.
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
. 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
In the left-side navigation pane, choose . 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.
What to do next
For more information about the error messages in logs, see Common error codes. You can resolve the issues based on the instructions.