Subscribe device shadows using mqtt bridge component

0

Hi,

I want to subscribe to the device shadow changes on IoTCore. For example if someone changes the device shadow via AWS Greengrass console, I want to get the change on my local mqtt broker on the device. For this purpose I made a deployment to the device with this aws.greengrass.clientdevices.mqtt.Bridge configuration.

{
  "reset": [],
  "merge": {
    "mqttTopicMapping": {
      "HelloWorldIotCore": {
        "topic": "clients/{iot:thingName}/hello/world",
        "source": "LocalMqtt",
        "target": "IotCore"
      },
      "IotCoreToDevice": {
        "topic": "clients/{iot:thingName}/iotcore/to/device",
        "source": "IotCore",
        "target": "LocalMqtt"
      },
      "GetApplicationsShadowLocalMqttToIoTCore": {
        "topic": "$aws/things/+/shadow/name/applications-shadow/get",
        "source": "LocalMqtt",
        "target": "IotCore"
      },
      "PublishApplicationsShadowLocalMqttToIoTCore": {
        "topic": "$aws/things/+/shadow/name/applications-shadow/update",
        "source": "LocalMqtt",
        "target": "IotCore"
      },
      "GetApplicationsShadowAcceptedIotCoreToLocalMqtt": {
        "topic": "$aws/things/+/shadow/name/applications-shadow/get/accepted",
        "source": "IotCore",
        "target": "LocalMqtt"
      },
      "UpdateApplicationsShadowAcceptedIotCoreToLocalMqtt": {
        "topic": "$aws/things/+/shadow/name/applications-shadow/update/accepted",
        "source": "IotCore",
        "target": "LocalMqtt"
      },
    },
    "brokerUri": "tcp://localhost:1883"
  }
}

I can send a message using HelloWorldIoTCore topic from the local mqtt broker (localhost:1883) to cloud and receive a message from the cloud on local mqtt broker using IotCoreToDevice topic. But it seems if I make an update on the named shadow, applications-shadow, I can not get the change on local mqtt broker using $aws/things/+/shadow/name/applications-shadow/update/accepted topic. What am I missing here?

Thanks

질문됨 일 년 전289회 조회
1개 답변
1

Good afternoon savcuoglu,

Sorry for the issues you are going through.

My initial piece of advice will be to check your Greengrass Core Device policy, and make sure it allows subscribing, sending and/or receiving to/from shadow topics. Policy should include something like:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iot:Subscribe"
      ],
      "Resource": [
        "arn:aws:iot:region:account:topicfilter/$aws/things/thingName/shadow/name/applications-shadow/update/accepted"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iot:Receive"
      ],
      "Resource": [
        "arn:aws:iot:region:account:topic/$aws/things/thingName/shadow/name/applications-shadow/update/accepted"
      ]
    }
  ]
}

You can always refer to documentation here, to tailor your policy to the corresponding shadow topic you are willing to track.

profile pictureAWS
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인