I want to register custom measurement templates via MQTT

What product/components do you use and which version/fix level?

Are you using a free trial or a product with a customer license?

What are trying to achieve? Please describe in detail.

I need to register a custom measurement template using SmartREST 2.0 via MQTT.

From the documents provided I am able to register and and verify a custom template using API’s via Postman.

But now I want to achieve the same thing using MQTT.

I went through all the resources but there’s nothing mentioned or any topic about registering templates via MQTT.

I need two things basically:

  1. Steps to register custom template via MQTT.
  2. How to verify if a template is already registered via MQTT ?

Do you get any error messages? Please provide a full error message screenshot and log file.

No error messages.

Have you installed latest fixes for the products

1 Like

Hi,

to create a SR2 template you need to publish to s/ut/<template_ID> with a payload of request and response templates denoted by message IDs 10 and 11 respectively. To create a measurement request template you need to follow this notation:

10,msgId,method,api,response,type,time,<n custom property triples>

Where always contains three parameters that define a single value in the output data. The parameters are path, type, value exactly in that order.
An example for a template with one fragment and three series would be like this:

10,100,POST,MEASUREMENT,,my_type,,my_fragment.myseries.value,NUMBER,,my_fragment.myseries2.value,NUMBER,,my_fragment.myseries3.value,NUMBER,

This leaves the time and the three declared values empty, meaning they must be supplied as payload when using this template. Time is also optional in SR2 and can be set on server side if not otherwise present. This means in use when sending data with this template the payload looks like this:

100,,1,2,3

This creates a measurement like this for the connected MQTT device:

{
  "my_fragment": {
    "myseries": {
      "value": 1
    },
    "myseries2": {
      "value": 2
    },
    "myseries3": {
      "value": 3
    }
  },
  "time": "<server time at the time of arrival>",
  ...
}

You can find our public documentation about the topic here: SmartREST 2.0 - Cumulocity IoT Guides

Hi,

Thanks for the update…

I tried the above steps mentioned for registration of a custom template.
I was successful in registering the template and also am able to check if the template is registered or not.

But I am still not bale to send the measurement.
Can you please share the topic to which we can publish our measurements or an example would be really helpful.

This is what I am trying to do,

  • This is the topic I published to - s/ut/Custom_1
  • This is the template body - 10,1500,POST,MEASUREMENT,Type_cov,Cov_Value.value,NUMBER

Now I want to send measurement like this - 1500,67 (here 1500 is template ID and 67 is the value)
However I do not have any idea as to which topic should I send this data.

Hi Prasad,

if you have defined your templates within a template collection, you can use these templates by publishing to the topic s/uc/{{TemplateCollectionId}}. In your case, it would be s/uc/Custom_1.

Best regards
Christian

Hi Christian,

As you mentioned I am trying the same thing… but my data is not going to the device in ‘All Devices’ section in Device Management section.

Do I need to use deviceID, or any such identification of the device I want to send data to using this custom template ?
or
Can you please share detailed steps on how we can send measurement using custom template via ‘MQTT Box’ application.

Hi Christian,

I am still facing the issue. So I am listing down detailed steps I have carried out till now to publish data on a custom topic.

  1. Created a custom template named - ‘Custom_1’ by publishing to topic,

    Topic = ‘s/ut/Custom_1’

    This is the template body I used,
    10,Custom_1,POST,MEASUREMENT,Type_cov,Cov_Value.value,NUMBER,

  2. After that I verified if the template is registered on Cumulocity IoT.
    Refer below screenshot ‘Custom_1_register’

  1. After verification that template is successfully registered, I tried sending a numerical value(data) to the following topic,

    Topic = ‘s/uc/Custom_1’

    The data was sent to a device with External Id - ‘cc_EE11’
    (similar to what we do when we use static templates).
    The external Id was used in ‘MQTT Client Id’ section in MQTTBox.

  2. However I am getting an error as -

50,Error of type: MeasurementManagementServiceException with message: Invalid value for source argument!

Refer below screenshot ‘Custom_1_publish’

What am I missing ??

Hi Prasad,

there are a couple of issues with your SmartRest template and how you try to send data. Philipp provided detailed information on how a measurement template should be structured. You can find additional information here.

Issues I see for your current template:

  • response property is ignored. Leave it empty as a response isn’t required for sending a measurement
  • the time property is totally ignored in your template. Best is to leave it empty as well to use server time instead
  • path for your measurement isn’t correct. Path always needs to have following structure {{fragment}}.{{series}}.value. Fragment and series are placeholder and need to be defined by you. An example for a correct structure is c8y_Humidity.H.value
  • best practice: use numbers instead of strings as message identifier

a fixed version for your template could look like this: 10,100,POST,MEASUREMENT,,cov_Measurement,,cov_Measurement.M.value,NUMBER,

payload for a measurement using the template 100 could look like this: 100,,30. This needs to be pushed on the topic, which defines your custom template collection s/uc/{{TemplateCollectionId}}.

Best regards
Christian

1 Like

Hi Christian,

That worked like a charm…

Thank you so much for the support !!!

Thanks,
Prasad

1 Like