setting c8y_Command result String from Java

淺唱寂寞╮ 提交于 2020-01-06 02:20:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!