Hi,
I have the below code to use the IPC socket on any device registered to Greengrass.
But I could find a nice example to do it in nodejs. Is there a way to do it? I could not find where to set SVCUID parameter as in python version. My current non-working nodejs version is as follows:
Nodejs Version:
import { greengrass, iot, io, mqtt } from 'aws-iot-device-sdk-v2';
...
const hostname =
process.env.AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT;
const clientBootstrap = new io.ClientBootstrap();
const configBuilder =
iot.AwsIotMqttConnectionConfigBuilder.new_websocket_builder()
.with_clean_session(false)
.with_socket_options(
new io.SocketOptions(io.SocketType.STREAM, io.SocketDomain.LOCAL, 3000)
);
const config = configBuilder.build();
config.host_name = hostname;
config.port = 8033;
const client = new mqtt.MqttClient(clientBootstrap);
const connection = client.new_connection(config);
Python version:
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import os
from awscrt.io import (
ClientBootstrap,
DefaultHostResolver,
EventLoopGroup,
SocketDomain,
SocketOptions,
)
from awsiot.eventstreamrpc import Connection, LifecycleHandler, MessageAmendment
TIMEOUT = 10
class IPCUtils:
def connect(self):
elg = EventLoopGroup()
resolver = DefaultHostResolver(elg)
bootstrap = ClientBootstrap(elg, resolver)
socket_options = SocketOptions()
socket_options.domain = SocketDomain.Local
amender = MessageAmendment.create_static_authtoken_amender(os.getenv("SVCUID"))
hostname = os.getenv("AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT")
connection = Connection(
host_name=hostname,
port=8033,
bootstrap=bootstrap,
socket_options=socket_options,
connect_message_amender=amender,
)
self.lifecycle_handler = LifecycleHandler()
connect_future = connection.connect(self.lifecycle_handler)
connect_future.result(TIMEOUT)
return connection
Thanks,
Sukru