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

已提問 1 年前檢視次數 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
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南