Skip to content

Implement service client for IoT commands #630

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 android/iotdevicesdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ repositories {
}

dependencies {
api 'software.amazon.awssdk.crt:aws-crt-android:0.38.1'
api 'software.amazon.awssdk.crt:aws-crt-android:0.38.3'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'com.google.code.gson:gson:2.9.0'
Expand Down
2 changes: 1 addition & 1 deletion sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.38.1</version>
<version>0.38.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*
* This file is generated.
*/

package software.amazon.awssdk.iot.iotcommands;

import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionEvent;
import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionStatus;
import software.amazon.awssdk.iot.iotcommands.model.CommandExecutionsSubscriptionRequest;
import software.amazon.awssdk.iot.iotcommands.model.DeviceType;
import software.amazon.awssdk.iot.iotcommands.model.RejectedErrorCode;
import software.amazon.awssdk.iot.iotcommands.model.StatusReason;
import software.amazon.awssdk.iot.iotcommands.model.UpdateCommandExecutionRequest;
import software.amazon.awssdk.iot.iotcommands.model.UpdateCommandExecutionResponse;
import software.amazon.awssdk.iot.iotcommands.model.V2ErrorResponse;

import java.nio.charset.StandardCharsets;

import software.amazon.awssdk.crt.mqtt.MqttClientConnection;
import software.amazon.awssdk.crt.mqtt.QualityOfService;
import software.amazon.awssdk.crt.mqtt.MqttException;
import software.amazon.awssdk.crt.mqtt.MqttMessage;

import software.amazon.awssdk.iot.Timestamp;
import software.amazon.awssdk.iot.EnumSerializer;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

/**
* The AWS IoT commands service is used to send an instruction from the cloud to a device that is connected to AWS IoT.
*
* AWS documentation: https://docs.aws.amazon.com/iot/latest/developerguide/iot-remote-command.html
*
*/
public class IotCommandsClient {
private MqttClientConnection connection = null;
private final Gson gson = getGson();

/**
* Constructs a new IotCommandsClient
* @param connection The connection to use
*/
public IotCommandsClient(MqttClientConnection connection) {
this.connection = connection;
}

private Gson getGson() {
GsonBuilder gson = new GsonBuilder();
gson.disableHtmlEscaping();
gson.registerTypeAdapter(Timestamp.class, new Timestamp.Serializer());
gson.registerTypeAdapter(Timestamp.class, new Timestamp.Deserializer());
addTypeAdapters(gson);
return gson.create();
}

private void addTypeAdapters(GsonBuilder gson) {
gson.registerTypeAdapter(CommandExecutionStatus.class, new EnumSerializer<CommandExecutionStatus>());
gson.registerTypeAdapter(DeviceType.class, new EnumSerializer<DeviceType>());
gson.registerTypeAdapter(RejectedErrorCode.class, new EnumSerializer<RejectedErrorCode>());
}

}
Loading
Loading