Skip to content

Update CRT to v0.4.6 for better error handling #51

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

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ is provided by code that been generated from a model of the service.

## Build from source
```
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
git clone https://github.com/awslabs/aws-iot-device-sdk-cpp-v2.git
mkdir aws-crt-cpp-build
cd aws-crt-cpp-build
Expand Down
2 changes: 1 addition & 1 deletion codebuild/common-posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

# build aws-crt-cpp
pushd $BUILD_PATH
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
cd aws-crt-cpp
cmake $CMAKE_ARGS -DBUILD_DEPS=ON ./
cmake --build . --target install
Expand Down
2 changes: 1 addition & 1 deletion codebuild/common-windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mkdir %INSTALL_DIR%
@rem build aws-crt-cpp
mkdir %BUILDS_DIR%\aws-crt-cpp-build
cd %BUILDS_DIR%\aws-crt-cpp-build
git clone --branch v0.4.5 https://github.com/awslabs/aws-crt-cpp.git
git clone --branch v0.4.6 https://github.com/awslabs/aws-crt-cpp.git
cmake %CMAKE_ARGS% -DCMAKE_INSTALL_PREFIX="%INSTALL_DIR%" -DCMAKE_PREFIX_PATH="%INSTALL_DIR%" -DCMAKE_BUILD_TYPE="Release" -DBUILD_DEPS=ON aws-crt-cpp || goto error
cmake --build . --target install || goto error

Expand Down
31 changes: 14 additions & 17 deletions samples/greengrass/basic_discovery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ char *s_getCmdOption(char **begin, char **end, const String &option)
int main(int argc, char *argv[])
{
/************************ Setup the Lib ****************************/
/*
* These make debug output via ErrorDebugString() work.
*/
LoadErrorStrings();

/*
* Do the global initialization for the API.
*/
Expand Down Expand Up @@ -124,6 +119,7 @@ int main(int argc, char *argv[])
stderr, "Event Loop Group Creation failed with error %s\n", ErrorDebugString(eventLoopGroup.LastError()));
exit(-1);
}

/*
* We're using Mutual TLS for Mqtt, so we need to load our client certificates
*/
Expand Down Expand Up @@ -168,10 +164,6 @@ int main(int argc, char *argv[])

DiscoveryClient discoveryClient(clientConfig);

GGGroup groupToUse;
Aws::Iot::MqttClientConnectionConfigBuilder connectionConfigBuilder(certificatePath.c_str(), keyPath.c_str());
Aws::Iot::MqttClientConnectionConfig connectionConfig;

Aws::Iot::MqttClient mqttClient(bootstrap);
std::shared_ptr<Mqtt::MqttConnection> connection(nullptr);

Expand All @@ -183,10 +175,7 @@ int main(int argc, char *argv[])
discoveryClient.Discover(thingName, [&](DiscoverResponse *response, int error, int httpResponseCode) {
if (!error && response->GGGroups)
{
groupToUse = std::move(response->GGGroups->at(0));
ByteCursor caCursor = ByteCursorFromArray(
reinterpret_cast<const uint8_t *>(groupToUse.CAs->at(0).data()), groupToUse.CAs->at(0).length());
connectionConfigBuilder.WithCertificateAuthority(caCursor);
auto groupToUse = std::move(response->GGGroups->at(0));

auto connectivityInfo = groupToUse.Cores->at(0).Connectivity->at(0);

Expand All @@ -198,10 +187,18 @@ int main(int argc, char *argv[])
connectivityInfo.HostAddress->c_str(),
(int)connectivityInfo.Port.value());

connectionConfigBuilder.WithPortOverride(connectivityInfo.Port.value());
connectionConfigBuilder.WithEndpoint(connectivityInfo.HostAddress.value());
connectionConfig = connectionConfigBuilder.Build();
connection = mqttClient.NewConnection(connectionConfig);
connection = mqttClient.NewConnection(
Aws::Iot::MqttClientConnectionConfigBuilder(certificatePath.c_str(), keyPath.c_str())
.WithCertificateAuthority(groupToUse.CAs->at(0).c_str())
.WithPortOverride(connectivityInfo.Port.value())
.WithEndpoint(connectivityInfo.HostAddress.value())
.Build());

if (!connection)
{
fprintf(stderr, "Connection setup failed with error %s", ErrorDebugString(mqttClient.LastError()));
exit(-1);
}

connection->OnConnectionCompleted =
[&, connectivityInfo](
Expand Down
10 changes: 4 additions & 6 deletions samples/jobs/describe_job_execution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ char *s_getCmdOption(char **begin, char **end, const String &option)
int main(int argc, char *argv[])
{
/************************ Setup the Lib ****************************/
/*
* These make debug output via ErrorDebugString() work.
*/
LoadErrorStrings();

/*
* Do the global initialization for the API.
*/
Expand Down Expand Up @@ -136,7 +131,10 @@ int main(int argc, char *argv[])

if (!clientConfig)
{
fprintf(stderr, "Client Configuration initialization failed with error %s\n", ErrorDebugString(LastError()));
fprintf(
stderr,
"Client Configuration initialization failed with error %s\n",
ErrorDebugString(clientConfig.LastError()));
exit(-1);
}

Expand Down
10 changes: 4 additions & 6 deletions samples/shadow/shadow_sync/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ static void s_changeShadowValue(
int main(int argc, char *argv[])
{
/************************ Setup the Lib ****************************/
/*
* These make debug output via ErrorDebugString() work.
*/
LoadErrorStrings();

/*
* Do the global initialization for the API.
*/
Expand Down Expand Up @@ -176,7 +171,10 @@ int main(int argc, char *argv[])

if (!clientConfig)
{
fprintf(stderr, "Client Configuration initialization failed with error %s\n", ErrorDebugString(LastError()));
fprintf(
stderr,
"Client Configuration initialization failed with error %s\n",
ErrorDebugString(clientConfig.LastError()));
exit(-1);
}

Expand Down