1

I am trying to implement the c8y_Command (Shell) OperationType in the java-agent. I got to the point where I can run the command on the device, I can also set the OperationStatus but I did not find the way to send back the result (command output) string.

http://www.cumulocity.com/guides/reference/device-management/ says:

To communicate the results of a particular command, the device adds a property "result":

"c8y_Command": {
    "text": "get uboot.sn",
    "result": "165711141901401"
}

if this is how the agent can set the status:

operation.setStatus(OperationStatus.SUCCESSFUL.toString());

then could you show please how to send back the Command result String!

Thanks a bunch.

Peter
  • 73
  • 1
  • 7

2 Answers2

2

The class that corresponds to the "c8y_Command" object in Json is c8y.Command. So the code to set the result would be:

operation.get(Command.class).setResult("165711141901401");
André
  • 668
  • 6
  • 11
  • Thanks André, operation.get(Command.class) gave null. operation.get("c8y_Command") gives me some object but I am not sure what type it is. I did not find setResult method in the javadoc http://resources.cumulocity.com/documentation/javasdk/current/ did you perhaps mean com.cumulocity.sdk.client.buffering.Result.setResponse(object) ? – Peter May 25 '16 at 10:00
  • You might have used the wrong Command.class. Check if it's the one from the package c8y in your imports. If it returns null, it means that it hasn't found an object of exactly that class. – André May 27 '16 at 08:02
1

aha, I had to cast it like this.

((c8y.Command)operation.get("c8y_Command")).setResult("165711141901401");
Peter
  • 73
  • 1
  • 7