Skip to content

Commit 05dbbbe

Browse files
committed
update cr changes
1 parent f90ab49 commit 05dbbbe

4 files changed

Lines changed: 106 additions & 96 deletions

File tree

documents/FAQ.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ If you are just getting started make sure you [install this sdk](https://github.
2020
### How do I enable logging?
2121

2222
``` c++
23-
ApiHandle apiHandle;
24-
apiHandle.InitializeLogging(Aws::Crt::LogLevel::Error, stderr);
23+
#include <aws/crt/Api.h>
24+
25+
Aws::Crt::ApiHandle apiHandle;
26+
apiHandle.InitializeLogging(Aws::Crt::LogLevel::Debug, stderr);
2527
```
28+
29+
**LogLevel**: LogLevel has the following options: `Trace`, `Debug`, `Info`, `Warn`, `Error`, `Fatal`, or `None`. Defaults to `Warn`.
30+
2631
You can also enable [CloudWatch logging](https://docs.aws.amazon.com/iot/latest/developerguide/cloud-watch-logs.html) for IoT which will provide you with additional information that is not available on the client side sdk.
2732

2833
### I keep getting AWS_ERROR_MQTT_UNEXPECTED_HANGUP

samples/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This directory contains sample applications for [aws-iot-device-sdk-cpp-v2](../R
66
* [MQTT5 Client Samples](#mqtt5-client-samples)
77
* [Service Client Samples](#service-client-samples)
88
* [Greengrass Samples](#greengrass-samples)
9+
* [Others](#others)
910
* [Instructions](#instructions)
1011
* [Sample Help](#sample-help)
1112
* [Enable Logging](#enable-logging)
@@ -18,7 +19,8 @@ This directory contains sample applications for [aws-iot-device-sdk-cpp-v2](../R
1819
|--------|-------------|
1920
| [X509-based mutual TLS](./mqtt/mqtt5_x509/README.md) | Demonstrates connecting to AWS IoT Core using X.509 certificates and private keys.
2021
| [Websockets with Sigv4 authentication](./mqtt/mqtt5_aws_websocket/README.md) | Shows how to authenticate over websockets using AWS Signature Version 4 credentials. |
21-
| [AWS Custom Authorizer Lambda Function](./mqtt/mqtt5_custom_auth_signed/README.md) | Examples of connecting with a signed and unsigned Lambda-backed custom authorizer.
22+
| [AWS Signed Custom Authorizer Lambda Function](./mqtt/mqtt5_custom_auth_signed/README.md) | Connecting with a signed Lambda-backed custom authorizer.
23+
| [AWS Unsigned Custom Authorizer Lambda Function](./mqtt/mqtt5_custom_auth_unsigned/README.md) | Connecting with an unsigned Lambda-backed custom authorizer.
2224
| [PKCS11](./mqtt/mqtt5_pkcs11/README.md) | Demonstrates connecting using a hardware security module (HSM) or smartcard with PKCS#11. |
2325
| [Other Connection Methods](../documents/MQTT5_Userguide.md#connecting-to-aws-iot-core) | More connection methods are available for review in the MQTT5 Userguide
2426

@@ -81,7 +83,7 @@ cmake -B build -S . -DCMAKE_PREFIX_PATH="<absolute path sdk-cpp-workspace dir>"
8183
cmake --build build --config "<Release|RelWithDebInfo|Debug>"
8284
```
8385

84-
This will compile all of the samples at once. You can then find the samples in the `aws-iot-device-sdk-cpp-v2/samples/build` folder. For example, the MQTT5 PubSub sample will be located at `aws-iot-device-sdk-cpp-v2/samples/build/mqtt/mqtt5_x509`.
86+
This will compile all of the samples at once. You can then find the samples in the `aws-iot-device-sdk-cpp-v2/samples/build` folder. For example, the MQTT5 X509 sample will be located at `aws-iot-device-sdk-cpp-v2/samples/build/mqtt/mqtt5_x509`.
8587

8688
For CMake versions that do not support the `-B` command, go to the `aws-iot-device-sdk-cpp-v2/samples` directory and run the following commands:
8789

samples/greengrass/basic_discovery/main.cpp

Lines changed: 94 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using namespace Aws::Crt;
1919
using namespace Aws::Discovery;
2020

21+
/* --------------------------------- ARGUMENT PARSING ----------------------------------------- */
2122
struct CmdArgs
2223
{
2324
String endpoint;
@@ -33,6 +34,98 @@ struct CmdArgs
3334
bool printDiscoverRespOnly = false;
3435
};
3536

37+
void printHelp()
38+
{
39+
printf("Greengrass Discovery Sample\n");
40+
printf("options:\n");
41+
printf(" --help show this help message and exit\n");
42+
printf("required arguments:\n");
43+
printf(" --cert Path to the certificate file\n");
44+
printf(" --key Path to the private key file\n");
45+
printf(" --thing_name Thing name\n");
46+
printf("optional arguments:\n");
47+
printf(" --client_id Client ID (default: test-<uuid>)\n");
48+
printf(" --topic Topic (default: test/topic)\n");
49+
printf(" --message Message to publish\n");
50+
printf(" --mode Mode: publish, subscribe, both (default: both)\n");
51+
printf(" --signing_region Signing region (default: us-east-1)\n");
52+
printf(" --proxy_host HTTP proxy host\n");
53+
printf(" --proxy_port HTTP proxy port\n");
54+
printf(" --print_discover_resp_only Print discovery response only\n");
55+
}
56+
57+
CmdArgs parseArgs(int argc, char *argv[])
58+
{
59+
CmdArgs args;
60+
for (int i = 1; i < argc; i++)
61+
{
62+
if (strcmp(argv[i], "--help") == 0)
63+
{
64+
printHelp();
65+
exit(0);
66+
}
67+
else if (i < argc - 1)
68+
{
69+
if (strcmp(argv[i], "--cert") == 0)
70+
{
71+
args.cert = argv[++i];
72+
}
73+
else if (strcmp(argv[i], "--key") == 0)
74+
{
75+
args.key = argv[++i];
76+
}
77+
else if (strcmp(argv[i], "--thing_name") == 0)
78+
{
79+
args.thingName = argv[++i];
80+
}
81+
82+
else if (strcmp(argv[i], "--topic") == 0)
83+
{
84+
args.topic = argv[++i];
85+
}
86+
else if (strcmp(argv[i], "--message") == 0)
87+
{
88+
args.message = argv[++i];
89+
}
90+
else if (strcmp(argv[i], "--mode") == 0)
91+
{
92+
args.mode = argv[++i];
93+
}
94+
else if (strcmp(argv[i], "--signing_region") == 0)
95+
{
96+
args.signingRegion = argv[++i];
97+
}
98+
else if (strcmp(argv[i], "--proxy_host") == 0)
99+
{
100+
args.proxyHost = argv[++i];
101+
}
102+
else if (strcmp(argv[i], "--proxy_port") == 0)
103+
{
104+
args.proxyPort = atoi(argv[++i]);
105+
}
106+
else
107+
{
108+
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
109+
printHelp();
110+
exit(1);
111+
}
112+
}
113+
else if (strcmp(argv[i], "--print_discover_resp_only") == 0)
114+
{
115+
args.printDiscoverRespOnly = true;
116+
}
117+
}
118+
if (args.cert.empty() || args.key.empty() || args.thingName.empty())
119+
{
120+
fprintf(stderr, "Error: --cert, --key, and --thing_name are required\n");
121+
printHelp();
122+
exit(1);
123+
}
124+
return args;
125+
}
126+
127+
/* --------------------------------- ARGUMENT PARSING END ----------------------------------------- */
128+
36129
static std::shared_ptr<Mqtt::MqttConnection> getMqttConnection(
37130
Aws::Iot::MqttClient &mqttClient,
38131
const Aws::Crt::Vector<GGGroup> &ggGroups,
@@ -145,103 +238,12 @@ static void printGreengrassResponse(const Aws::Crt::Vector<GGGroup> &ggGroups)
145238
}
146239
}
147240

148-
void printHelp()
149-
{
150-
printf("Greengrass Discovery Sample\n");
151-
printf("options:\n");
152-
printf(" --help show this help message and exit\n");
153-
printf("required arguments:\n");
154-
printf(" --cert Path to the certificate file\n");
155-
printf(" --key Path to the private key file\n");
156-
printf(" --thing_name Thing name\n");
157-
printf("optional arguments:\n");
158-
printf(" --client_id Client ID (default: test-<uuid>)\n");
159-
printf(" --topic Topic (default: test/topic)\n");
160-
printf(" --message Message to publish\n");
161-
printf(" --mode Mode: publish, subscribe, both (default: both)\n");
162-
printf(" --signing_region Signing region (default: us-east-1)\n");
163-
printf(" --proxy_host HTTP proxy host\n");
164-
printf(" --proxy_port HTTP proxy port\n");
165-
printf(" --print_discover_resp_only Print discovery response only\n");
166-
}
167-
168-
CmdArgs parseArgs(int argc, char *argv[])
169-
{
170-
CmdArgs args;
171-
for (int i = 1; i < argc; i++)
172-
{
173-
if (strcmp(argv[i], "--help") == 0)
174-
{
175-
printHelp();
176-
exit(0);
177-
}
178-
else if (i < argc - 1)
179-
{
180-
if (strcmp(argv[i], "--cert") == 0)
181-
{
182-
args.cert = argv[++i];
183-
}
184-
else if (strcmp(argv[i], "--key") == 0)
185-
{
186-
args.key = argv[++i];
187-
}
188-
else if (strcmp(argv[i], "--thing_name") == 0)
189-
{
190-
args.thingName = argv[++i];
191-
}
192-
193-
else if (strcmp(argv[i], "--topic") == 0)
194-
{
195-
args.topic = argv[++i];
196-
}
197-
else if (strcmp(argv[i], "--message") == 0)
198-
{
199-
args.message = argv[++i];
200-
}
201-
else if (strcmp(argv[i], "--mode") == 0)
202-
{
203-
args.mode = argv[++i];
204-
}
205-
else if (strcmp(argv[i], "--signing_region") == 0)
206-
{
207-
args.signingRegion = argv[++i];
208-
}
209-
else if (strcmp(argv[i], "--proxy_host") == 0)
210-
{
211-
args.proxyHost = argv[++i];
212-
}
213-
else if (strcmp(argv[i], "--proxy_port") == 0)
214-
{
215-
args.proxyPort = atoi(argv[++i]);
216-
}
217-
else
218-
{
219-
fprintf(stderr, "Unknown argument: %s\n", argv[i]);
220-
printHelp();
221-
exit(1);
222-
}
223-
}
224-
else if (strcmp(argv[i], "--print_discover_resp_only") == 0)
225-
{
226-
args.printDiscoverRespOnly = true;
227-
}
228-
}
229-
if (args.cert.empty() || args.key.empty() || args.thingName.empty())
230-
{
231-
fprintf(stderr, "Error: --cert, --key, and --thing_name are required\n");
232-
printHelp();
233-
exit(1);
234-
}
235-
return args;
236-
}
237-
238241
int main(int argc, char *argv[])
239242
{
240-
/************************ Setup ****************************/
241-
242243
// Parse command line arguments
243244
CmdArgs cmdData = parseArgs(argc, argv);
244245

246+
/************************ Setup ****************************/
245247
// Do the global initialization for the API.
246248
ApiHandle apiHandle;
247249

samples/greengrass/ipc/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ int main(int argc, char *argv[])
6767
};
6868

6969
CmdArgs cmdData = parseArgs(argc, argv);
70+
/* --------------------------------- ARGUMENT PARSING END ----------------------------------------- */
7071

7172
fprintf(stdout, "Running Greengrass IPC sample\n");
7273

0 commit comments

Comments
 (0)