设备影子功能的例程运行后,您可以在设备端和物联网平台查看日志信息。
背景信息
已配置C Link SDK的设备影子功能例程,详细信息,请参见使用示例。
设备端日志
您可以在设备端查看运行结果。-
连接日志:
[1626317181.277][LK-0313] MQTT user calls aiot_mqtt_connect api, connect [1626317181.277][LK-0317] LightSwitch&a1wP****** [1626317181.277][LK-0318] 97B797D367BF307A0573979CF6CCA5675719F6790B361F2596E01B72AC****** 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
-
设备主动上报状态:
-
设备上报状态到设备影子的日志:
[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":{"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":1}},"versi [LK-030A] > 6F 6E 22 3A 30 7D | on":0}
-
应答报文日志:
[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
-
- 应用程序改变设备状态:
- 物联网平台下发的期望属性日志:
例如,从物联网平台下发了一条期望属性为
{"LightSwitch":0}
的消息,设备接收消息后,打印日志如下。[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
-
上报更新过期望属性后的最新属性日志:
重要 示例代码仅做演示,实际业务中,您需自行编写处理逻辑,实现自动更新接收的期望属性。[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}
-
删除期望属性的日志:
[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":{"des [LK-030A] > 69 72 65 64 22 3A 22 6E 75 6C 6C 22 7D 2C 22 76 | ired":"null"},"v [LK-030A] > 65 72 73 69 6F 6E 22 3A 35 7D | ersion":2}
-
删除期望属性的应答报文:
[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
- 物联网平台下发的期望属性日志:
- 设备主动获取设备影子内容:
-
发送查询属性的请求日志:
[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"}
-
返回应答报文日志:
该日志表示设备影子中,期望属性和上报属性均为空。
[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
-
- 设备主动删除影子属性:
-
发送删除属性的请求日志:
该请求日志表示删除所有属性。
[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":{"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 22 6E 75 6C 6C 22 7D 7D 2C 22 | itch":"null"}}," [LK-030A] > 76 65 72 73 69 6F 6E 22 3A 39 7D | version":2}
-
返回应答报文日志:
该日志表示删除指令已发送成功。
[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
-
物联网平台日志
您可以在物联网平台控制台,查看设备的状态和运行日志。
-
在线状态:
在左侧导航栏,选择 ,找到设备,查看设备状态。设备状态显示为在线,则表示设备与物联网平台成功连接。 -
运行日志:
在左侧导航栏,选择查看设备影子相关日志。 ,选择产品后,