全部產品
Search
文件中心

:作業記錄

更新時間:Jun 30, 2024

裝置影子功能的常式運行後,您可以在裝置端和物聯網平台查看日誌資訊

背景資訊

已配置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
  • 裝置主動上報狀態:

    1. 裝置上報狀態到裝置影子的日誌:

      [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}
    2. 應答報文日誌:

      [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
  • 應用程式改變裝置狀態:
    1. 物聯網平台下發的期望屬性日誌:

      例如,從物聯網平台下發了一條期望屬性為{"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
    2. 上報更新到期望屬性後的最新屬性日誌:

      重要 範例程式碼僅做示範,實際業務中,您需自行編寫處理邏輯,實現自動更新接收的期望屬性。
      [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}
    3. 刪除期望屬性的日誌:

      [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}
      
                                  
    4. 刪除期望屬性的應答報文:

      [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
  • 裝置主動刪除影子屬性:
    1. 發送刪除屬性的請求日誌:

      該請求日誌表示刪除所有屬性。

      [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}
                                  
    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

物聯網平台日誌

您可以在物聯網平台控制台查看裝置的狀態和作業記錄。

  • 線上狀態:

    在左側導覽列,選擇裝置管理 > 裝置,找到裝置,查看裝置狀態。裝置狀態顯示為線上,則表示裝置與物聯網平台成功串連。查看裝置狀態

  • 作業記錄:

    在左側導覽列,選擇監控營運 > Log Service,選擇產品後,查看裝置影子相關日誌。裝置影子日誌