2 Answers
- Newest
- Most votes
- Most comments
1
Hello
Thanks for the answer and sorry for the late reply. I found a solution and I would like to post it here for other people to help. A few things that might be interesting for my context:
- I am completely new to AWS and by reading a lot I'm getting more and more familiar with the design concepts
- I am a Typescript/javascript developer, so I would like to use the
Greengrass Core SDK for JS
- This SDK doesn't support IPC (local Pub/sub), so all communication of the components needs to go through the local
MQTT Broker
component
What I tried to do
- I wanted to create a single deployment in the AWS console which would work for all future devices and which contains the complete component configuration
- All core device <-> IoT <-> App traffic is routed to each device using this pattern
coreThingName/things/....
- I was trying to dynamically configure the
MQTT Bridge
from this deployment - The MERGE configuration I was trying to do is something like this:
{ "reset": [], "merge": { "ThingQuestions": { "topic": "{iot:thingName}/things/request/#", "source": "IotCore", "target": "LocalMqtt" }, "ThingResponses": { "topic": "{iot:thingName}/things/responses/#", "source": "LocalMqtt", "target": "IotCore" } } } }
- But parameters like
{iot:thingName}
do not seem to be supported.
The solution
- The design guideline seems to be: the Deployment created in the console contains all global configuration and, when needed, the components on the core device can MERGE local configuration updates.
- I discovered that the Java, C++ and Python Greengrass Core SDKs have methods to edit the component configurations locally from within a custom Greengrass component.
- This functionality isn't implemented yet in the Javascript SDK
- Therefor I change the
MQTT Bridge
configuration dynamically from within the components using theexec
function running thegreengrass-cli
command:
/** * Update the configuration of an existing GG component */ import { exec } from 'child_process' /** * * @param {*} component aws.greengrass.clientdevices.mqtt.Bridge=2.1.0 COMPONENT_NAME=VERSION * @param {*} config * @returns */ export default async function updateConfig (component, config) { return new Promise( (resolve, reject) => { exec(`/greengrass/v2/bin/greengrass-cli deployment create --merge ${component} --update-config '${JSON.stringify(config)}'`, (err, stdout, stderr) => { if (err) { reject(err) } else { resolve(stdout) } }) }) }
I hope this helps other new Greengrass users Best regards
Hacor
answered 2 years ago
0
For those (like myself) whose search ended up on this thread, just a quick follow-up to say that recent versions of MQTT Bridge (e.g. 2.2.6), under Nucleus (e.g. 2.11.0) configured with interpolateComponentConfiguration: "true", do support the {iot:thingName} recipe variable in the component configuration, so something like this:
{
"reset": [
"/mqttTopicMapping"
],
"merge": {
"mqttTopicMapping": {
"EdgeToCloud": {
"topic": "etoc/{iot:thingName}/#",
"source": "LocalMqtt",
"target": "IotCore"
},
"CloudToEdge": {
"topic": "ctoe/{iot:thingName}/#",
"source": "IotCore",
"target": "LocalMqtt"
}
}
}
}
works as expected.
answered 9 months ago
Relevant content
- Accepted Answerasked 2 months ago
- asked 3 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 3 years ago
It is not clear from your question what is your intention: MQTT Bridge is used to relay messages between the client devices connecting to Moquette and the Greengrass PubSub or AWS IoT Core. Can you give an example of which topics would the client devices subscribe to and if that communication should be between the client device and IoT Core or the client device and Greengrass Pub/Sub?