aws-greengrass / aws-greengrass-shadow-manager

A GreengrassV2 Component that provides offline device shadow documents and optional synchronization to the IoT device shadow service.
Apache License 2.0
9 stars 6 forks source link

影子数据同步配置未生效、同步到云端监听到异常数据 #176

Closed ArvinSpace closed 1 year ago

ArvinSpace commented 1 year ago

Describe the bug

  1. 配置了不同步影子数据到云端,但是现在却同步到云端了
  2. 主题监听时发现多了两种数据更新,两种的version不正常(数字太小或者与delta的不符),而且没有clientToken 异常数据如下
    
    $aws/things/Arvin-One-Basic-11/shadow/update/accepted
    {
    "version": 1421,
    "timestamp": 1679400922,
    "state": {
    "desired": {
      "color": "green"
    },
    "reported": {
      "color": "green"
    }
    },
    "metadata": {
    "desired": {
      "color": {
        "timestamp": 1679400922
      }
    },
    "reported": {
      "color": {
        "timestamp": 1679400922
      }
    }
    }
    }

$aws/things/Arvin-One-Basic-11/shadow/update/accepted { "state": { "desired": { "color": "blue" }, "reported": { "color": "blue" } }, "metadata": { "desired": { "color": { "timestamp": 1679401009 } }, "reported": { "color": { "timestamp": 1679401009 } } }, "version": 654, "timestamp": 1679401009 }

$aws/things/Arvin-One-Basic-11/shadow/update/delta { "version": 1443, "timestamp": 1679401307, "state": { "color": "red" }, "metadata": { "color": { "timestamp": 1679401307 } } }


正常数据如下:

$aws/things/Arvin-One-Basic-11/shadow/update/accepted { "version": 3348, "clientToken": "166832f2-ded6-413a-9c93-93ce6b3a4f3d", "timestamp": 1679401156, "state": { "reported": { "color": "red" } }, "metadata": { "reported": { "color": { "timestamp": 1679401156 } } } }

$aws/things/Arvin-One-Basic-11/shadow/update/delta { "version": 3347, "timestamp": 1679401156, "state": { "color": "red" }, "metadata": { "color": { "timestamp": 1679401156 } }, "clientToken": "166832f2-ded6-413a-9c93-93ce6b3a4f3d" }


按照教程[第 5 步:开发与客户端设备影子交互的组件](https://docs.aws.amazon.com/zh_cn/greengrass/v2/developerguide/client-devices-tutorial.html#develop-client-device-shadow-component)

recipes/com.example.clientdevices.MySmartLightManager-1.0.0.json配置如下:

{ "RecipeFormatVersion": "2020-01-25", "ComponentName": "com.example.clientdevices.MySmartLightManager", "ComponentVersion": "1.0.0", "ComponentDescription": "A component that interacts with smart light client devices.", "ComponentPublisher": "Amazon", "ComponentDependencies": { "aws.greengrass.Nucleus": { "VersionRequirement": "^2.9.4" }, "aws.greengrass.ShadowManager": { "VersionRequirement": "^2.3.1" }, "aws.greengrass.clientdevices.mqtt.Bridge": { "VersionRequirement": "^2.2.4" } }, "ComponentConfiguration": { "DefaultConfiguration": { "smartLightDeviceNames": [], "accessControl": { "aws.greengrass.ShadowManager": { "com.example.clientdevices.MySmartLightManager:shadow:1": { "policyDescription": "Allows access to client devices' unnamed shadows", "operations": [ "aws.greengrass#GetThingShadow", "aws.greengrass#UpdateThingShadow" ], "resources": [ "$aws/things/Arvin-One-Basic-*/shadow" ] } }, "aws.greengrass.ipc.pubsub": { "com.example.clientdevices.MySmartLightManager:pubsub:1": { "policyDescription": "Allows access to client devices' unnamed shadow updates", "operations": [ "aws.greengrass#SubscribeToTopic" ], "resources": [ "$aws/things/+/shadow/update/accepted" ] } } } } }, "Manifests": [ { "Platform": { "os": "linux" }, "Lifecycle": { "Install": "python3 -m pip install --user awsiotsdk", "Run": "python3 -u {artifacts:path}/smart_light_manager.py" } }, { "Platform": { "os": "windows" }, "Lifecycle": { "Install": "py -3 -m pip install --user awsiotsdk", "Run": "py -3 -u {artifacts:path}/smart_light_manager.py" } } ] }


aws.greengrass.ShadowManager 配置

{ "reset": [], "merge": { "strategy": { "type": "realTime" }, "synchronize": { "coreThing": { "classic": false, "namedShadows": [] }, "direction": "betweenDeviceAndCloud" } } }


aws.greengrass.clientdevices.mqtt.Bridge 配置

{ "reset": [], "merge": { "mqttTopicMapping": { "HelloWorldIotCoreMapping": { "topic": "clients/+/hello/world", "source": "LocalMqtt", "target": "IotCore" }, "HelloWorldPubsubMapping": { "topic": "clients/+/hello/world", "source": "LocalMqtt", "target": "Pubsub" }, "ShadowsLocalMqttToPubsub": { "topic": "$aws/things/+/shadow/#", "source": "LocalMqtt", "target": "Pubsub" }, "ShadowsPubsubToLocalMqtt": { "topic": "$aws/things/+/shadow/#", "source": "Pubsub", "target": "LocalMqtt" } } } }



**Environment**
- OS: amazonlinux:2
- JDK 1.8:
- Nucleus 2.9.4:
- Shadow Manager 2.3.1:
MikeDombo commented 1 year ago

I think that you do not understand what "merge" and "reset" means in Greengrass configuration.

You previously configured Shadow manager to synchronize Arvin-One-Basic-11 and you did not remove this configuration. To remove it, you need to use "reset": ["/synchronize/shadowDocuments"] to remove the previous configuration you added.

Read more here: https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update

ArvinSpace commented 1 year ago

I think that you do not understand what "merge" and "reset" means in Greengrass configuration.

You previously configured Shadow manager to synchronize Arvin-One-Basic-11 and you did not remove this configuration. To remove it, you need to use "reset": ["/synchronize/shadowDocuments"] to remove the previous configuration you added.

Read more here: https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update

谢谢,aws.greengrass.ShadowManager 配置重置之后可以了 而且也没有监听到异常数据了,这个就有点奇怪了,不知道之前异常数据是怎么产生的