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

feita há um ano289 visualizações
1 Resposta
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
ESPECIALISTA
respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas