Search code examples
mqttcumulocity

cumulocity mqtt measurement


I am pretty new to Cumulocity and I am trying to get data into the platform from my own device using mqtt and the smartrest templates. I can get data in using the static templates but they only support certain data types. I am struggling to create the appropriate smartrest template in the UI and the documentation doesn't go into much detail.

I get that the template name goes in the MQTT topic (or selected on login as part of the username) in s/ut/template_name and the messageId of the messages in the template get matched to the first CSV field of the MQTT publish payload. What I don't get is the template terminology. In the UI I choose API->Measurement and Method->POST and I am presented with required values $.type and $.time. My questions:

  • Is $.type the "measurement fragment type" name or do I have to make it "c8y_CustomMeasurement"? Can I call it whatever I want?
  • $.time has a value field. Is this the default value if one is not supplied in the publish?
  • I assume I need to add a numerical value in the optional API values. To link it to the value of the data point should I make the key "c8y_CustomMeasurement.custom.value"?
  • Am I way off base here?

Every time I publish to my own smartrest template the server drops the connection so I assume its an error in my template setup but I don't see a way of accessing debug messages (also nothing is published back to me on s/e or s/dt).

For the sake of an example, lets say I wish to publish a unitless, timestamped pulse count with payload format "mId,ts,value" with example data "p01,'2017-07-17 12:34:00',1234"


Solution

  • What you wrote so far is mostly correct just to be a bit more precise:

    • The topic is s/uc/template_id (not the template name, this is just a label)
    • The $.type refers to the 'type' fragment in the measurement JSON. It is a free text field
    • In 99% of cases you want to leave the $.time empty. If you set something here it is not the default but fixed to that timestamp and you cannot change it when using the template. If you leave it empty and still not send something in
    • Example: p01,2017-07-17T12:34:00,1234 (no quotes arounf timestamp and ISO8601 format
    • Example without sending time: p01,,1234 (sending empty string as time results in server time beeing set. The template is the same)

    Hope these points help you to find you issue