IoT thing shadow and Greengrass component

0

Is it possible to work with IoT thing shadow from Greengrass component without any extra configs and connections?
We can subscribe to IoT core topicts by using IPC client as described in https://github.com/aws/aws-iot-device-sdk-python-v2/blob/463d72ea1ecb501322c467b103f1a0ee3f45f969/samples/ipc_greengrass.py
ipc_client = awsiot.greengrasscoreipc.connect() - makes all authentication stuff.
But interaction with shadows requires additional configuration: certificates, endpoint etc.- https://github.com/aws/aws-iot-device-sdk-python-v2/blob/463d72ea1ecb501322c467b103f1a0ee3f45f969/samples/shadow.py
After that IotShadowClient provides all needed methods to subscribe and publish to shadow topics.
Does IotShadowClient support work through IPC when it is used in component without establishing a dedicated connection to AWS IoT custom endpoint?
What is the best way in general to communicate GGv2 component and IoT shadow?

已提问 3 年前555 查看次数
2 回答
0

Hi lacteolus,

The device SDK provides clients and APIs for accessing the AWS IoT cloud data plane services. It also provides a client for talking with the Greengrass v2 IPC.

The IoTShadowClient in the device SDK is a client for talking directly with the AWS IoT Device Shadow Service in the cloud.
It maintains its own connection - hence the need for the device certificate information. This client does not work through the Greengrass IPC.

At this time, there is no equivalent to the local shadow service / sync that Greengrass v1 provides.

In order to talk to the cloud shadow service, you do not need to use the IoT shadow client. A V2 component can talk with IoT Shadow via the Greengrass managed MQTT connection.

The following access control policy allows your component to subscribe and publish to the shadow MQTT topics

      "accessControl": {
        "aws.greengrass.ipc.mqttproxy": {
          "shadow-mqtt-example": {
            "policyDescription": "Allows access to shadow.",
            "operations": [
              "*"
            ],
            "resources": [
              "$aws/things/+/shadow/#"
            ]
          }
        }
      }

Your python component can follow the MQTT pub/sub example here: https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-iot-core-mqtt.html

You can subscribe to $aws/things/thingName/shadow/update/accepted to get any remote shadow updates
and publish state to $aws/things/thingName/shadow/update

In this case, thingName is the name of the thing you want to update.

You can use the environment variable $AWS_IOT_THING_NAME to use the thing name of the core device

See https://docs.aws.amazon.com/iot/latest/developerguide/device-shadow-mqtt.html for more detail about using the shadow MQTT topics.

Edited by: rob-aws on Mar 8, 2021 11:05 AM

AWS
Rob
已回答 3 年前
0

Hi rob-aws,
Thanks for info. So it means that we need to implement something similar to IoTShadowClient but using IPC and subscriptions to all needed shadow topics (update, delta, get etc.).
I looked at https://github.com/aws/aws-iot-device-sdk-python-v2/blob/main/samples/shadow.py example and it seemed to be convenient - it has special classes for different shadow requests and methods for publishing and subscribing to named and classis shadow topice etc.

已回答 3 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则