Client Example Code (HU/TBM):

    package com.fca.uconnect.global;

    import java.util.UUID;

    import com.amazonaws.services.iot.client.AWSIotException;
    import com.amazonaws.services.iot.client.AWSIotMessage;
    import com.amazonaws.services.iot.client.AWSIotMqttClient;
    import com.amazonaws.services.iot.client.AWSIotQos;
    import com.amazonaws.services.iot.client.AWSIotTopic;
    import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
    import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteDoorRequest.CommandEnum;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest.ActionEnum;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationResponse;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum;
    import com.google.protobuf.ByteString;
    import com.google.protobuf.ExtensionRegistry;
    /**
     * This example class demonstrates how to use the AWS IoT mqtt client to send a Uconnect RemoteOperations message to the Client and wait for a response message.
     * This code is only for reference and is furnished without warranty.....
     *
     * @author FCA Global V2C API Team
     *
     */
    public class TBMExampleForRemoteOp  {

    	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
    	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
    	private int messageId ;// The messageId is a sequential number incremented and assigned to each message sent from the Service.
    	private AWSIotMqttClient mqttClient;// The mqtt client object from the AWS IoT client library.
    	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
    	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
    	private int correlationId = 0;// The correlationId is a sender messageId so that Sender can recognize the message once its received response.
    	private Semaphore semaphore;//The semaphore object is used to wait for a response.

    	public TBMExampleForRemoteOp() {
    		extRegistry = ExtensionRegistry.newInstance();
    		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationRequest);
    		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationSubscribeResponse);
    		this.semaphore = new Semaphore();
    	}
    	/**
    	 * This method demonstrates connecting to the AWS IoT mqtt broker and publishing an Login message to the RO topic.
    	 */
    	public void process() {

    		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
    	try {
    	mqttClient.connect();
    	iotTopic = new AWSIotTopic(clientId+"/RO/",AWSIotQos.QOS1){
    		public void onMessage(AWSIotMessage msg) {
    	try {

    		UconnectMessage	msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
    		if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest)) {
    				boolean validRemoteOperation = false;
    				GlobalUconnectExtRemoteOp.RemoteOperationRequest ro = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest);
    				if (ro.hasRemoteDoorRequest()) {
    					if (ro.getRemoteDoorRequest().getCommand() == CommandEnum.UNLOCK_DRIVER) {
    						correlationId = msgIn.getMessageId();
    						validRemoteOperation = true;
    						semaphore.unlock();
    						sendMessage(getRemoteOpRespMsg(correlationId,GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum.SUCCESS));
    						//Publish Remote operation Status if User subscribing
    						if(ro.getAction().equals(ActionEnum.SUBSCRIBE)){
    						GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum statusEnum=GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.REQUESTED;
    						UUID serviceId =UUID.randomUUID();
    						for(int i=0;i<4;i++){
    							Thread.sleep(1000);//wait and send remote operation status
    							if(i==1)
    								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.DELIVERED;
    							else if (i==2)
    								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.IN_PROGRESS;
    							else if (i==3)
    								statusEnum = GlobalUconnectExtRemoteOp.RemoteOperationStatus.StatusEnum.COMPLETE;
    						  sendMessage(getRemoteOpPubMsg(correlationId,serviceId,statusEnum));
    						 }
    						}
    					}else{
    						sendMessage(getRemoteOpRespMsg(correlationId,GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum.NOT_AUTHORIZED));
    					}
    				}
    			}

    	} catch( Exception ex) {
    		ex.printStackTrace();
    		System.out.println("Err processing message: "+ex+", try parsing Provisioning.");
    	  }
    	 }
    	};
    	mqttClient.subscribe(iotTopic);

    	} catch (AWSIotException e) {
    		System.out.println("Caught Exception "+e);
    		e.printStackTrace();
    	}
    	try {
    		semaphore.lock();
    	} catch (InterruptedException e) {

    	}
    	}
    	public UconnectMessage getRemoteOpPubMsg(int correlationId, UUID serviceRequestId, StatusEnum status) {
    		messageId++;
    		RemoteOperationStatus ros = RemoteOperationStatus.newBuilder()
    				.setStatus(status)
    				.build();

    		UconnectMessage msg = UconnectMessage.newBuilder()
    				.setTimestamp(System.currentTimeMillis())
    				.setMessageId(messageId)

    				.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus, ros))
    				.build();
    		return msg;
    	}
    	public UconnectMessage getRemoteOpRespMsg(int correlationId, GlobalUconnectExtRemoteOp.RemoteOperationResponse.ResponseEnum response) {
    		messageId++;
    		RemoteOperationResponse ro = RemoteOperationResponse.newBuilder()
    				.setResponse(response)
    				.build();

    		UconnectMessage msg = UconnectMessage.newBuilder()
    				.setTimestamp(System.currentTimeMillis())
    				.setSessionId(sessionId)
    				.setMessageId(messageId)
    				.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse, ro))
    				.build();
    		return msg;
    	}
    	public void sendMessage(UconnectMessage msg) {
    		final byte[] msgOut = msg.toByteArray();
    		new Thread(new Runnable() {

    		    @Override
    		public void run() {
    		try {
    			AWSIotMessage message = new
    					MessagePublisherListener("/RO/"+clientId,AWSIotQos.QOS1,msgOut);
    			mqttClient.publish(message);

    		} catch (AWSIotException e) {
    			System.out.println("Caught Exception "+e);
    						e.printStackTrace();
    					}
    			    }

    			}).start();
    }

    	public static void main(String[] args) {
    		TBMExampleForRemoteOp service = new TBMExampleForRemoteOp();
    		service.process();
    	}
    }

Service Example Code (SDP):

    package com.fca.uconnect.global;

    package com.fca.uconnect.global;

    import com.amazonaws.services.iot.client.AWSIotException;
    import com.amazonaws.services.iot.client.AWSIotMessage;
    import com.amazonaws.services.iot.client.AWSIotMqttClient;
    import com.amazonaws.services.iot.client.AWSIotQos;
    import com.amazonaws.services.iot.client.AWSIotTopic;
    import com.fca.uconnect.global.GlobalUconnectControl.UconnectAny;
    import com.fca.uconnect.global.GlobalUconnectControl.UconnectMessage;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteDoorRequest;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteDoorRequest.CommandEnum;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationRequest.ActionEnum;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationResponse;
    import com.fca.uconnect.global.GlobalUconnectExtRemoteOp.RemoteOperationStatus;
    import com.google.protobuf.ByteString;
    import com.google.protobuf.ExtensionRegistry;
    import com.google.protobuf.InvalidProtocolBufferException;

    public class SDPExampleForRemoteOp {
    	private String clientId; // The clientId is unique to the device and obtained from the client X.509 certificate CN.
    	private ByteString sessionId; // The sessionId is assigned by the SDP to maintain a session independent of connection protocols.
    	private AWSIotMqttClient mqttClient; // The mqtt client object from the AWS IoT client library.
    	private int messageId; // The messageId is a sequential number incremented and assigned to each message sent from the client.
    	private AWSIotTopic iotTopic; // The Topic object to subscribe for inbound messages.
    	private ExtensionRegistry extRegistry; // Google protocol buffers extension registry instance.
    	public SDPExampleForRemoteOp() {
    		extRegistry = ExtensionRegistry.newInstance();
    		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationResponse);
    		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationSubscribeResponse);
    		extRegistry.add(GlobalUconnectExtRemoteOp.remoteOperationStatus);
    	}
    	public void process() {

    		mqttClient = new AWSIotMqttClient("endpoint", clientId, "awsAccessKeyId", "awsSecretAccessKey");
     		if (mqttClient == null) {
     			System.out.println("Error init mqtt client.");
     			System.exit(0);
     		}
    		try {
    			mqttClient.connect();
    			iotTopic = new AWSIotTopic("/RO/#",AWSIotQos.QOS1){
    				public void onMessage(AWSIotMessage msg) {
    					UconnectMessage msgIn = null;
    					try {
    						msgIn = UconnectMessage.parseFrom(msg.getPayload(),extRegistry);
    					} catch (InvalidProtocolBufferException e) {
    					}
    					//  sync response
    				 	//Acknowledging Remote OperationRequest
    					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse)) {
    						RemoteOperationResponse roAckMsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationResponse);

    					// async status response after SUBSCRIBE Remote operation request
    					if (msgIn.getMessages(0).hasExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus)) {
    						RemoteOperationStatus roStatusmsg = msgIn.getMessages(0).getExtension(GlobalUconnectExtRemoteOp.remoteOperationStatus);
    					}
    				}
    			}};
    			mqttClient.subscribe(iotTopic);
    		} catch (AWSIotException e) {
    			System.out.println("Caught Exception "+e);
    			e.printStackTrace();
    		}
    		try {
    			sendMessage(getRemoteDoorsMsg(ActionEnum.SUBSCRIBE, CommandEnum.UNLOCK_DRIVER, 0));
    		} catch (AWSIotException e) {
    			e.printStackTrace();
    		}
    	}
    public UconnectMessage getRemoteDoorsMsg( RemoteOperationRequest.ActionEnum action, RemoteDoorRequest.CommandEnum command, int delay) {
    	messageId++;
    	RemoteOperationRequest ro = RemoteOperationRequest.newBuilder()
    			.setAction(action)
    			.setRemoteDoorRequest(
    			 RemoteDoorRequest.newBuilder()
    			 .setCommand(command)
    			 .setDelay(delay))
    			.build();
    	UconnectMessage msg = UconnectMessage.newBuilder()
    			.setTimestamp(System.currentTimeMillis())
    			.setMessageId(messageId)
    			.addMessages(UconnectAny.newBuilder().setExtension(GlobalUconnectExtRemoteOp.remoteOperationRequest,ro))
    			.build();
    	return msg;
    }

    	private void sendMessage(Object msgIn) throws AWSIotException {
    		UconnectMessage msg = (UconnectMessage)msgIn;
    		final byte[] msgOut =  msg.toByteArray();
    			new Thread(new Runnable() {
    			    @Override
    			public void run() {
    			try {
    				AWSIotMessage message = new
    						MessagePublisherListener(clientId+"/RO/",AWSIotQos.QOS1,msgOut);
    				mqttClient.publish(message);

    			} catch (AWSIotException e) {
    				System.out.println("Caught Exception "+e);
    							e.printStackTrace();
    						}
    				    }
    				}).start();
    			}

    	public static void main(String[] args) {
    		SDPExampleForRemoteOp client = new SDPExampleForRemoteOp();
    		client.process();
    	}
    }

The example code demonstrates how to connect with AWS IoT for publishing and subscribing to the RemoteOperations topic.

Download Client Example Code here

Download Service Example Code here