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

asked a year ago276 views
1 Answer
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
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions