Bidirectional communication between c8y platform and edge

Product/components used and version/fix level:

thin edge latest, cumulocity platform

Question related to a free trial, or to a production (customer) instance?

customer instance

Detailed explanation of the problem:

Hello Cumulocity Community,

I have a question for SmartRest and custom SmartRest templates. We want to trigger an operation on the thinEdge edge device in a microservice to send data from the edge device to the cloud. Currently only one way works. We create an operation via the rest API with:

POST {{tenant_domain}}/devicecontrol/operations
Authorization: Basic {{user}} {{password}}

{
  "deviceId": "...",
  "description": "Execute maintenance command",
  "MaintenanceInformation": {
    "text": "maintenance command"
  }
}

And the microservice receives the message via smart rest. Now we also want to send specific data upstream into the cloud.

Probably I am misunderstanding something, but when the operation is triggered only the “response” is called and not the “message” part of the smart rest template. I thought that when I trigger an operation via the rest API it would send a message and not the response part of the smart rest template:

What I tried for sending the appropriate message was using the mqtt messages:

mqtt pub c8y/s/uc/MaintenanceInformation 5557,9876543210,test
mqtt pub c8y/s/uc/MaintenanceInformation 9876543210,test
mqtt pub c8y/s/uc/MaintenanceInformation/9876543210 test
mqtt pub c8y/s/uc/MaintenanceInformation/thinEdge-ID 9876543210,test
mqtt pub c8y/s/uc/MaintenanceInformation 5557,9876543210,test
mqtt pub c8y/s/us 501,MaintenanceInformation,test
mqtt pub c8y/s/us 501,MaintenanceInformation,test
mqtt pub c8y/s/us 504,MaintenanceInformation,test
mqtt pub c8y/s/us 504,9876543210,test
mqtt pub c8y/s/us 502,MaintenanceInformation,test
mqtt pub c8y/s/us 5557,9876543210,test
mqtt pub c8y/s/us/MaintenanceInformation 5557,9876543210,test
mqtt pub c8y/s/us/MaintenanceInformation 9876543210,test
mqtt pub c8y/s/us 506,9876543210,test
mqtt pub c8y/s/us 506,5557,test
mqtt pub c8y/s/us 506,5557
mqtt pub c8y/s/us 506,9876543210
mqtt pub c8y/s/us 501,MaintenanceInformation
mqtt pub c8y/s/us 506,MaintenanceInformation
mqtt pub c8y/s/us 503,MaintenanceInformation,test

The messages for setting the status of the operation worked for the smart rest template id. But I did not see any message related to an answer or possible data I need in the c8y platform. Or should I configure the smart rest template to another rest endpoint e.g. measurement or event API? Or am I using the wrong mqtt message path? I tried us and uc.

Also is there a detailed explaination somewhere what the different channels mean? I tried to figure it out like “u” for upstream and “d” for downstream and “us” would be upstream static for static templates etc. but I am not 100% sure.

Thank you in advance!

The response templates are intended to be messages that are created in C8Y and should be handled by any device which are subscribed. Therefor if you create a message via REST and a fragment is matching the defined condition, it will always generate response messages (only).

Vice versa if a message should be created from a device into C8Y you can define message templates. It will be used by a device to send data to C8Y.

In your example you are trying to update an operation which is only meant to update the status of an operation with additionally adding fragments. See this example from the documentation:

# Creation:
# 10,msgId,method,api,response,fragment,custom1.path,custom1.type,custom1.value
10,999,PUT,OPERATION,,c8y_MyOperation,status,OPERATIONSTATUS,SUCCESSFUL,c8y_Fragment.val,NUMBER,
# Usage:
999,24

Which will add a new fragment “c8y_Fragment” with value “val” 24 and sets the status of the operation to successful. Btw. it will always take the latest Operation type Executing and Pending.
For you the message should look like this:

mqtt pub c8y/s/uc/MaintenanceInformation 5557,MaintenanceInformation,test

MaintenanceInformation should be the fragment that is used to identify the operation, test is the message send to your “text” fragment. You could also hard code “MaintenanceInformation” in your template, so it will only be 5557,test

If you want in general send additional data I would suggest to create new events instead updating an operation which is kind of limited in its functionality due to the updating of latest Executing/Pending functionality.

Thank you, for your anwer. We are now using the operation just to trigger the data transmission on edge and we send the response over the normal REST API.