Skip to content

Greengrass Subscribe to Topic

0

My greengrass uses a custom component which publishes events from greengrass up to the cloud. I use the publish_binary_message_to_topic(ipc_client, <topic>, <data>). Works great.

I now want to have my custom component subscribe to messages on the same topic. So, I tried <topic>/<filter> and the ipc_client.subscribe_to_topic(<topic>/<filter>, on_stream_event=....) but nothing is coming through from AWS down to my green grass node? What am I doing wrong and/or what is the best practice here?

Thanks, Will

asked 2 years ago679 views

5 Answers
0
Accepted Answer

Hi. SubscribeToTopic and PublishToTopic are for local communications to other components on Greengrass. To interact with AWS IoT Core, there are different IPC methods: https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-iot-core-mqtt.html

AWS
EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Yeah, this is exactly the code I'm trying to get to work. I'm using Nuc version 2.12.2. The example code is not working for me -- only for the publish.

answered 2 years ago

  • You can merge the resources together so you only have 1 policy block in the access control: "resources": [ "thio_bin_demo", "thio_bin_demo/request"]

    Could you provide the code block you are using to publish and subscribe with. Are you using the same component to publish and subscribe, i.e communicate with itself? The IPC is used to communicate information between different components and/or to IoT Core. Where are your messages coming from which you are testing with?

0

Hey Will, One thing you can check is to make sure you have the proper "accessControl" policies setup for your component.

You can use this documentation section as a guide for example code and how to publish and subscribe to topics using the ipc_client. https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html

AWS

answered 2 years ago

0

This is my access control policy in my custom component: "accessControl": { "aws.greengrass.ipc.pubsub": { "com.thio.coredevice.thio_bp:pubsub:1": { "policyDescription": "Allows access to publish/subscribe to topics.", "operations": [ "aws.greengrass#SubscribeToTopic", "aws.greengrass#PublishToTopic" ], "resources": [ "thio_bin_demo" ] }, "com.thio.coredevice.thio_bp:pubsub:2": { "policyDescription": "Allows access to publish/subscribe to topics.", "operations": [ "aws.greengrass#SubscribeToTopic", "aws.greengrass#PublishToTopic" ], "resources": [ "thio_bin_demo/request" ] } } },

answered 2 years ago

0

Ok. I got it. Thank you.

answered 2 years 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.