You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for AWS IoT to send and receive messages through an MQTT connection using MQTT5.
15
15
16
+
This is the **TypeScript version** of the JavaScript sample found in `samples/node/mqtt/mqtt5_x509`.
17
+
16
18
You can read more about MQTT5 for the JavaScript IoT Device SDK V2 in the [MQTT5 user guide](https://github.com/awslabs/aws-crt-nodejs/blob/main/MQTT5-UserGuide.md).
17
19
18
20
## Requirements
@@ -69,37 +71,68 @@ Note that in a real application, you may want to avoid the use of wildcards in y
69
71
70
72
## How to run
71
73
72
-
To Run this sample from the `samples/node/mqtt/mqtt5_x509` folder, use the following command:
74
+
### Prerequisites
75
+
- Node.js v14+
76
+
- TypeScript (installed as dev dependency)
77
+
78
+
### Installation and Running
79
+
80
+
To run this sample from the `samples/node/mqtt/mqtt5_x509_ts` folder:
73
81
82
+
1. Install dependencies:
74
83
```sh
75
84
npm install
76
-
node index.js \
85
+
```
86
+
87
+
2. Run using npm script (builds and runs):
88
+
```sh
89
+
npm start -- \
77
90
--endpoint <AWS IoT endpoint> \
78
91
--cert <Path to certificate file> \
79
92
--key <Path to private key file>
80
93
```
81
-
If you would like to see what optional arguments are available, use the `--help` argument:
If you would like to see what optional arguments are available, use the `--help` argument:
115
+
```sh
116
+
npm start -- --help
100
117
```
101
118
102
-
The sample will not run without the required arguments and will notify you of missing arguments.
119
+
This will show all available options including:
120
+
-`--endpoint` (required): IoT endpoint hostname
121
+
-`--cert` (required): Path to certificate file
122
+
-`--key` (required): Path to private key file
123
+
-`--client_id`: Client ID (default: auto-generated)
124
+
-`--topic`: Topic name (default: "test/topic")
125
+
-`--message`: Message payload (default: "Hello from mqtt5 sample")
126
+
-`--count`: Number of messages to publish (default: 5, 0 = infinite)
127
+
128
+
## TypeScript Features
129
+
130
+
This TypeScript version includes:
131
+
-**Type Safety**: Full TypeScript type annotations for better development experience
132
+
-**Interface Definitions**: Proper typing for command line arguments
133
+
-**Event Type Safety**: Typed event handlers for MQTT5 client events
134
+
-**Build Process**: Compilation to JavaScript with source maps
135
+
-**Development Mode**: Direct TypeScript execution with ts-node
103
136
104
137
## Additional Information
105
138
Additional help with the MQTT5 Client can be found in the [MQTT5 Userguide](https://github.com/awslabs/aws-crt-nodejs/blob/main/MQTT5-UserGuide.md). This guide will provide more details on MQTT5 operations, lifecycle events, connection methods, and other useful information.
"strictFunctionTypes": true, /* Enable strict checking of function types. */
28
+
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
29
+
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
30
+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
31
+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
32
+
33
+
/* Additional Checks */
34
+
"noUnusedLocals": true, /* Report errors on unused locals. */
35
+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
36
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
37
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
38
+
39
+
/* Module Resolution Options */
40
+
"esModuleInterop": true/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
43
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
44
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
45
+
// "typeRoots": [], /* List of folders to include type definitions from. */
46
+
// "types": [], /* Type declaration files to be included in compilation. */
47
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
48
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
49
+
50
+
/* Source Map Options */
51
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
52
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
53
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
54
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
55
+
56
+
/* Experimental Options */
57
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
58
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
0 commit comments