-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Where is the documentation? #284
Comments
I'm sorry that you are still having problems using this sdk. We have made some improvements, but documentation is something that we are still working on and welcome any feedback for. Here is our API documentation Could you please elaborate about problems that you are having with the samples? Any suggestions are welcome. |
Thanks for the quick response. The problems I'm having is that the package went from a simple and understandable README with lovely small examples that have nice textual descriptions to explain what they do to a set of cryptic samples written in Typescript that are nested inside a
I would suggest rewriting the README that already exists for the old package to fit the new API. There are dozens of questions about this in these issues and many more on StackOverflow, so I don't think it's just me who is confused about this. |
async function main(argv: Args) {
/// parse the common command line arguments
common_args.apply_sample_arguments(argv);
/// build the mqtt connection
const connection = common_args.build_connection_from_cli_args(argv);
/// does what below comment says
// force node to wait 60 seconds before killing itself, promises do not keep node alive
// ToDo: we can get rid of this but it requires a refactor of the native connection binding that includes
// pinning the libuv event loop while the connection is active or potentially active.
const timer = setInterval(() => { }, 60 * 1000);
/// wait for connection to connect
await connection.connect()
/// publish and subscribe to messages
await execute_session(connection, argv)
/// call disconnect
await connection.disconnect()
// Allow node to die if the promise above resolved
clearTimeout(timer);
}
|
You can find a PubSub sample in JavaScript here, no need to code typeScript:
https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/node/pub_sub_js/index.js
Go to:
https://github.com/aws/aws-iot-device-sdk-js-v2#Installation
Build the JavaScript V2 SDK from source, do not use the NPM method to
install it
Make sure you have active AWS security certificates and have attached an
IoT policy to them.
in your RPi prompt:
cd ~
mkdir certs (add your security certificates here)
Goto the following directory on your RPi:
/samples/node/pub_sub_js/index.js
and build the program with dependencies: npm install
Finally execute your index.js pubsub program with:
node index.js --endpoint <Your-AWS-IoT-Endpoint> --ca_file
~/certs/Amazon-root-CA-1.pem --cert ~/certs/certificate.pem.crt --key
~/certs/private.pem.key
If you don't want to use yargs for your certificates from the command line
then you can hardocde them into the cli_args.js file which is a dependency
in your index.js program:
https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/util/cli_args.js
…On Tue, Sep 13, 2022 at 4:33 PM Joseph Klix ***@***.***> wrote:
1. No, you don't need yargs. They are used to command line input when
running the samples. These allow you to run the samples without having to
change any of the code, but can safely removed.
2. Here
<https://github.com/aws/aws-iot-device-sdk-js-v2/blob/336420386a8829fb5d6ddd010af2cef4ceec7b5a/samples/node/pub_sub/index.ts#L69-L85>
async function main(argv: Args) {
/// parse the common command line arguments
common_args.apply_sample_arguments(argv);
/// build the mqtt connection
const connection = common_args.build_connection_from_cli_args(argv);
/// does what below comment says
// force node to wait 60 seconds before killing itself, promises do not keep node alive
// ToDo: we can get rid of this but it requires a refactor of the native connection binding that includes
// pinning the libuv event loop while the connection is active or potentially active.
const timer = setInterval(() => { }, 60 * 1000);
/// wait for connection to connect
await connection.connect()
/// publish and subscribe to messages
await execute_session(connection, argv)
/// call disconnect
await connection.disconnect()
// Allow node to die if the promise above resolved
clearTimeout(timer);}
1. Most likely not. Your program will likely be running longer that
just a few publishes so you don't need to worry about node killing itself
to early.
2. No, we even have the pub_sub sample in javascript
<https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/node/pub_sub_js/index.js>.
I would recommend you use typescript and most of our examples are
typescript, but it is ultimately your choice.
—
Reply to this email directly, view it on GitHub
<#284 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD4KXRHC6WVLHONQG3HFSTTV6EFNLANCNFSM6AAAAAAQLGBUTA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Thanks for the quick replies. I do know the answers to these questions, and I'm simply answering your question about what people are having a hard time understanding with the current documentation. The old README worked really well and the new samples are wrapped in a I would normally not be so specific about this if it was an open source project, but since this is the only way for me to interact with an entire fleet of AWS services, I do expect the documentation to at least be on par with the package that I used when starting to use this service. |
Also, properties like keep alive and timeouts are no where documented? I can find what options there are, but not how they work, or what would be good values in different scenario's... |
I ran into the same issue as everyone mentioned above. For those looking for a quick sample: import { mqtt } from "aws-iot-device-sdk-v2";
import { iot } from "aws-iot-device-sdk-v2";
import { resolve } from "path";
const configs = {
topic: "test",
certPath: resolve("./secrets/certificate.pem.crt"),
privateKeyPath: resolve("./secrets/private.pem.key"),
caCertPath: resolve("./secrets/AmazonRootCA1.pem"),
clientId: "TestingClient",
endpointUrl: "xxxxx.iot.us-east-1.amazonaws.com",
};
const sendMessage = async (connection: mqtt.MqttClientConnection) => {
const msg = {
message: "This is my message",
dateTime: new Date().toISOString(),
};
const json = JSON.stringify(msg);
await connection.publish(configs.topic, json, mqtt.QoS.AtLeastOnce);
};
const createConnection = () => {
let config_builder =
iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(
configs.certPath,
configs.privateKeyPath
);
config_builder.with_certificate_authority_from_path(
undefined,
resolve(configs.caCertPath)
);
config_builder.with_clean_session(false);
config_builder.with_client_id(
`${configs.clientId}-${Math.floor(Math.random() * 100000000)}`
);
config_builder.with_endpoint(configs.endpointUrl);
const config = config_builder.build();
const client = new mqtt.MqttClient();
return client.new_connection(config);
};
const start = async () => {
const connection = createConnection();
const timer = setInterval(() => {}, 20 * 1000);
console.log("Connecting...");
await connection.connect();
console.log("Connection completed.");
await sendMessage(connection);
console.log("Disconnecting...");
await connection.disconnect();
console.log("Disconnect completed.");
// Allow node to die if the promise above resolved
clearTimeout(timer);
};
start(); |
Can you guide me to create the other 3 files? |
https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-create.html is a good starting point |
I'm getting to the connect() step, but haven't caught the connection.on event yet |
|
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the issue
This upgraded version of the SDK is now three years old, and there still isn't any documentation on how to use this package. The old package had a README detailing the installation and usage with AWS IoT Core, but there is nothing in this package like that. I've tried to go through the samples but they are honestly terribly confusing. Wouldn't it be a priority to give users a way to actually consume this package?
Links
https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/README.md
https://stackoverflow.com/questions/67451677/getting-started-with-aws-iot-publication-from-device
https://stackoverflow.com/questions/71388320/mirgration-aws-iot-device-sdk-js-to-aws-iot-device-sdk-js-v2
The text was updated successfully, but these errors were encountered: