问题
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.
回答1:
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");
回答2:
aha, I had to cast it like this.
((c8y.Command)operation.get("c8y_Command")).setResult("165711141901401");
来源:https://stackoverflow.com/questions/37422626/setting-c8y-command-result-string-from-java