文档

运行日志

更新时间:

物模型功能的例程运行后,您可以在设备端和物联网平台查看日志信息

前提条件

已配置C Link SDK的物模型功能例程,详细信息,请参见使用示例

设备端日志

您可以在设备端查看运行结果。

  • 连接日志:

    出现如下日志,表示设备与物联网平台连接成功。

    [1624012656.944][LK-0313] MQTT user calls aiot_mqtt_connect api, connect
    [1624012656.944][LK-0317] LightSwitch&a18wP******
    [1624012656.944][LK-0318] ADE0BBAA0DFAC1CA3440DAB1D8B555EFD6E0AA0546A2312D0E1E1A60A******
    [1581401572.800][LK-0319] a18wP******.LightSwitch|timestamp=2524608000000,_ss=1,_v=sdk-c-4.0.0,securemode=2,signmethod=hmacsha256,ext=1,|
    establish mbedtls connection with server(host='a18wP******.iot-as-mqtt.cn-shanghai.aliyuncs.com', port=[443])
    success to establish tcp, fd=3
    local port: 43014
    [1624012657.133][LK-0313] MQTT connect success in 184 ms
    AIOT_MQTTEVT_CONNECT
  • 订阅Topic日志:

    如果您配置了订阅Topic相关代码,设备端打印如下日志。该日志表示设备已订阅Topic,例如/sys/a18wP******/LightSwitch/thing/event/property/batch/post_reply

    [1624012657.133][LK-0309] sub: /sys/a18wP******/LightSwitch/thing/event/property/batch/post_reply
  • 上报消息日志:

    • 设备通过物模型默认模块,发送属性消息的日志如下:

      [1624012657.133][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post
      
      [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 20 30 7D 2C 22 73  79 73 22 3A 7B 22 61 63 | ": 0},"sys":{"ac
      [LK-030A] > 6B 22 3A 31 7D 7D                                | k":1}}
    • 设备通过物模型默认模块,发送事件消息的日志如下:

      [1624012657.133][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/Error/post
      
      [LK-030A] > 7B 22 69 64 22 3A 22 32  22 2C 22 76 65 72 73 69 | {"id":"2","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 45 72 72  6F 72 43 6F 64 65 22 3A | s":{"ErrorCode":
      [LK-030A] > 20 30 7D 2C 22 73 79 73  22 3A 7B 22 61 63 6B 22 |  0},"sys":{"ack"
      [LK-030A] > 3A 31 7D 7D                                      | :1}}
    • 设备通过自定义模块,例如demo_extra_block,发送事件消息的日志如下:

      [1624012657.133][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post
      
      [LK-030A] > 7B 22 69 64 22 3A 22 33  22 2C 22 76 65 72 73 69 | {"id":"3","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 64 65 6D  6F 5F 65 78 74 72 61 5F | s":{"demo_extra_
      [LK-030A] > 62 6C 6F 63 6B 3A 4E 69  67 68 74 4C 69 67 68 74 | block:NightLight
      [LK-030A] > 53 77 69 74 63 68 22 3A  20 31 7D 2C 22 73 79 73 | Switch": 1},"sys
      [LK-030A] > 22 3A 7B 22 61 63 6B 22  3A 31 7D 7D             | ":{"ack":1}}
    • 设备通过物模型默认模块,批量发送属性消息的日志如下:

      [1624012657.133][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/batch/post
      
      [LK-030A] > 7B 22 69 64 22 3A 22 34  22 2C 22 76 65 72 73 69 | {"id":"4","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 70 72 6F  70 65 72 74 69 65 73 22 | s":{"properties"
      [LK-030A] > 3A 7B 22 50 6F 77 65 72  22 3A 20 5B 20 7B 22 76 | :{"Power": [ {"v
      [LK-030A] > 61 6C 75 65 22 3A 22 6F  6E 22 2C 22 74 69 6D 65 | alue":"on","time
      [LK-030A] > 22 3A 31 36 31 32 36 38  34 35 31 38 7D 5D 2C 22 | ":1612684518}],"
      [LK-030A] > 57 46 22 3A 20 5B 7B 22  76 61 6C 75 65 22 3A 20 | WF": [{"value":
      [LK-030A] > 33 2C 22 74 69 6D 65 22  3A 31 36 31 32 36 38 34 | 3,"time":1612684
      [LK-030A] > 35 31 38 7D 5D 7D 7D 2C  22 73 79 73 22 3A 7B 22 | 518}]}},"sys":{"
      [LK-030A] > 61 63 6B 22 3A 31 7D 7D                          | ack":1}}
  • 响应日志:

    设备向物联网平台发送消息后,物联网平台会做出响应,以下日志为响应报文:

    [1624012657.188][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post_reply
    
    [LK-030A] < 7B 22 63 6F 64 65 22 3A  32 30 30 2C 22 64 61 74 | {"code":200,"dat
    [LK-030A] < 61 22 3A 7B 7D 2C 22 69  64 22 3A 22 31 22 2C 22 | a":{},"id":"1","
    [LK-030A] < 6D 65 73 73 61 67 65 22  3A 22 73 75 63 63 65 73 | message":"succes
    [LK-030A] < 73 22 2C 22 6D 65 74 68  6F 64 22 3A 22 74 68 69 | s","method":"thi
    [LK-030A] < 6E 67 2E 65 76 65 6E 74  2E 70 72 6F 70 65 72 74 | ng.event.propert
    [LK-030A] < 79 2E 70 6F 73 74 22 2C  22 76 65 72 73 69 6F 6E | y.post","version
    [LK-030A] < 22 3A 22 31 2E 30 22 7D                          | ":"1.0"}
    
    [1624012657.188][LK-0A08] DM recv generic reply
    demo_dm_recv_handler, type = 0
    msg_id = 1, code = 200, data = {}, message = success
    [1624012657.199][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/property/post_reply
    
    [LK-030A] < 7B 22 63 6F 64 65 22 3A  32 30 30 2C 22 64 61 74 | {"code":200,"dat
    [LK-030A] < 61 22 3A 7B 7D 2C 22 69  64 22 3A 22 33 22 2C 22 | a":{},"id":"3","
    [LK-030A] < 6D 65 73 73 61 67 65 22  3A 22 73 75 63 63 65 73 | message":"succes
    [LK-030A] < 73 22 2C 22 6D 65 74 68  6F 64 22 3A 22 74 68 69 | s","method":"thi
    [LK-030A] < 6E 67 2E 65 76 65 6E 74  2E 70 72 6F 70 65 72 74 | ng.event.propert
    [LK-030A] < 79 2E 70 6F 73 74 22 2C  22 76 65 72 73 69 6F 6E | y.post","version
    [LK-030A] < 22 3A 22 31 2E 30 22 7D                          | ":"1.0"}
    
    [1624012657.199][LK-0A08] DM recv generic reply
    demo_dm_recv_handler, type = 0
    msg_id = 3, code = 200, data = {}, message = success
    [1624012657.200][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/event/Error/post_reply
    
    [LK-030A] < 7B 22 63 6F 64 65 22 3A  32 30 30 2C 22 64 61 74 | {"code":200,"dat
    [LK-030A] < 61 22 3A 7B 7D 2C 22 69  64 22 3A 22 32 22 2C 22 | a":{},"id":"2","
    [LK-030A] < 6D 65 73 73 61 67 65 22  3A 22 73 75 63 63 65 73 | message":"succes
    [LK-030A] < 73 22 2C 22 6D 65 74 68  6F 64 22 3A 22 74 68 69 | s","method":"thi
    [LK-030A] < 6E 67 2E 65 76 65 6E 74  2E 45 72 72 6F 72 2E 70 | ng.event.Error.p
    [LK-030A] < 6F 73 74 22 2C 22 76 65  72 73 69 6F 6E 22 3A 22 | ost","version":"
    [LK-030A] < 31 2E 30 22 7D                                   | 1.0"}
  • 处理设置属性的日志:

    设备连接物联网平台后,您可以通过以下方式,向设备发送指令。

    设备端接收物联网平台下发的指令后,执行回调函数的处理,示例仅做打印处理,日志如下:

    [1624246230.777][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/service/property/set
    
    [LK-030A] < 7B 22 6D 65 74 68 6F 64  22 3A 22 74 68 69 6E 67 | {"method":"thing
    [LK-030A] < 2E 73 65 72 76 69 63 65  2E 70 72 6F 70 65 72 74 | .service.propert
    [LK-030A] < 79 2E 73 65 74 22 2C 22  69 64 22 3A 22 31 34 30 | y.set","id":"140
    [LK-030A] < 37 31 32 32 37 39 32 22  2C 22 70 61 72 61 6D 73 | 7122792","params
    [LK-030A] < 22 3A 7B 22 4C 69 67 68  74 53 77 69 74 63 68 22 | ":{"LightSwitch"
    [LK-030A] < 3A 30 7D 2C 22 76 65 72  73 69 6F 6E 22 3A 22 31 | :0},"version":"1
    [LK-030A] < 2E 30 2E 30 22 7D                                | .0.0"}
    
    [1624246230.777][LK-0A08] DM recv property set
    demo_dm_recv_handler, type = 1
    msg_id = 1407122792, params = {"LightSwitch":0}
    [1624246230.777][LK-0309] pub: /sys/a18wP******/LightSwitch/thing/service/property/set_reply
    
    [LK-030A] > 7B 22 69 64 22 3A 22 31  34 30 37 31 32 32 37 39 | {"id":"140712279
    [LK-030A] > 32 22 2C 22 63 6F 64 65  22 3A 32 30 30 2C 22 64 | 2","code":200,"d
    [LK-030A] > 61 74 61 22 3A 7B 7D 7D                          | ata":{}}

物联网平台日志

您可以在物联网平台控制台查看设备的状态和运行日志。

  • 在线状态:

    在左侧导航栏,选择设备管理 > 设备,找到设备,查看设备状态。设备状态显示为在线,则表示设备与物联网平台成功连接。查看设备状态

  • 物模型数据:

    设备详情页面的物模型数据页签下,查看上报的物模型数据。物模型数据

  • 运行日志:

    在左侧导航栏,选择监控运维 > 日志服务,选择产品后,查看设备上线、订阅Topic和上报消息的日志。

    物模型日志

后续步骤

运行日志中出现的错误信息,请参见常见错误码aiot_dm_api.h中的状态码描述根据提示解决问题。