0

I've registered a trial account to test Cumulocity and its mqtt api. I want to send operation to some device (currently emulated by java service) and receive operation result.

As manual I use the following links:

The following code is used to make a response to 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 code means that restart operation started and 503 code means that device restarted successfully.

But actually in Cumulocity UI operation status has changed to Pending.

Image

If I send restart operation again the previous operation will changed to Success but the new one to Pending.

Image 2

So, what am I doing wrong?

I expect to mark the operation as Failed or Success.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38

1 Answers1

0

The "PENDING" state is always the initial state of every operation in Cumulocity. The SmartREST MQTT for operations always follows the following order:

PENDING -> EXECUTING -> SUCCESSFUL/FAILED

SmartREST will always update the oldest operation (as we want to execute operations in the historical order).

So if you send 501 it will look for the oldest matching operation in PENDING state. If you send 503 it will look for the oldest matching operation in EXECUTING state.

From your explanation it is not fully clear if there were already 2 restart operations when you your code was executed. You code is fully correct but if there were already two restart operation this would explain why one is now SUCCESSFUL and the other still in PENDING.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
  • In my case was one restart operation from GUI, after receiving restart operation by device it send 501 code and 503 after some delay. State changed with the following flow: PENDING -> 501 -> EXECUTING -> 503 -> PENDING But I expected result as you say: PENDING -> 501 -> EXECUTING -> 503 -> SUCCESSFUL/FAILED – Vitaliy Mikhailov Feb 25 '19 at 14:05
  • When I send second restart operation - new operation will appears with PENDING status and previous (not the last) operation state will change to SUCCESSFUL – Vitaliy Mikhailov Feb 25 '19 at 14:16
  • So the behaviour PENDING -> EXECUTING -> PENDING is incorrect. I cannot reproduce it but if you have a way to reproduce it please report it as a bug directly. Afterwards the second behaviour makes sense because you now have 2 operations in PENDING and it will update the oldest one (not the latest) – TyrManuZ Feb 25 '19 at 14:19