【发布时间】:2019-02-25 20:22:56
【问题描述】:
我已经注册了一个试用帐户来测试 Cumulocity 及其 mqtt api。 我想将操作发送到某个设备(当前由java服务模拟)并接收操作结果。
作为手册,我使用以下链接:
- https://www.cumulocity.com/guides/users-guide/device-management/#-a-name-operation-monitoring-a-working-with-operations
- https://cumulocity.com/guides/device-sdk/mqtt#hello-mqtt-java
以下代码用于对 Cumulocity 做出响应。
if (payload.startsWith("510")) {
System.out.println("Simulating device restart...");
client.publish("s/us", "501,c8y_Restart".getBytes(), 2, false);
System.out.println("...restarting...");
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
client.publish("s/us", "503,c8y_Restart".getBytes(), 2, false);
System.out.println("...done...");
}
501 代码表示重启操作开始,503 代码表示设备重启成功。
但实际上在 Cumulocity UI 中的操作状态已经变成了Pending。
如果我再次发送restart 操作,之前的操作将更改为Success,但新的操作将更改为Pending。
那么,我做错了什么?
我希望将操作标记为Failed 或Success。
【问题讨论】:
标签: java mqtt paho cumulocity