Currently the tedge measurement api is fairly restrictive (due to minimum via product implementation). We already have some open tickets to expand support for it, below are the open tickets that we have, though the priority is generally set via feedback from people using tedge because as much as we would like to implement everything at once, we just can’t.
We can look at prioritising these tickets if it is an urgent, though feedback on the GitHub tickets would be appreciated.
However the good news is that for occasions like this you can still use the direct Cumulocity topics (e.g. c8y/*
, and you can still refer to the child device using the external identity (e.g. what you have to use in the MQTT topic to refer to the child device anyway).
Main device: Publishing custom measurement
Using the c8y/measurement/measurements/create
MQTT topic is not bad for the main device as you don’t have to reference the external id of the main device as the linking is implicit. Note, you do have to specific the time
property in the body.
tedge mqtt pub "c8y/measurement/measurements/create" '{"time":"2023-03-20T08:03:56.940907Z","environment":{"temperature":{"value":29.9,"unit":"°C"}},"type":"10min_average","meta":{"sensorLocation":"Brisbane, Australia"}}'
Output measurement (retrieved from Cumulocity IoT using api)
{
"environment": {
"temperature": {
"unit": "°C",
"value": 29.9
}
},
"id": "812904",
"meta": {
"sensorLocation": "Brisbane, Australia"
},
"self": "https://{example}.c8y.io/measurement/measurements/812904",
"source": {
"id": "60812900",
"self": "https://{example}.c8y.io/inventory/managedObjects/60812900"
},
"time": "2023-03-20T08:03:56.940Z",
"type": "10min_average"
}
Child device: Publishing custom measurement
Publishing a custom Cumulocity IoT measurement to a child device requires an additional fragment externalId
which contains the external id of the child device (Note, this is not the same as the id in Cumulocity IoT!). The external identity is essentially the name of the child device that you referenced, and you would have to refer to this name anyway when using the tedge measurement topic (tedge/measurements/{child_sn}
).
tedge mqtt pub "c8y/measurement/measurements/create" '{"time":"2023-03-20T08:03:56.940907Z","externalSource":{"externalId":"{child_sn}","type":"c8y_Serial"},"environment":{"temperature":{"value":29.9,"unit":"°C"}},"type":"10min_average","meta":{"sensorLocation":"Brisbane, Australia"}}'
Output
{
"environment": {
"temperature": {
"unit": "°C",
"value": 29.9
}
},
"id": "812896",
"meta": {
"sensorLocation": "Brisbane, Australia"
},
"self": "https://{example}.c8y.io/measurement/measurements/812896",
"source": {
"id": "66812895",
"self": "https://{example}.c8y.io/inventory/managedObjects/66812895"
},
"time": "2023-03-20T08:03:56.940Z",
"type": "10min_average"
}
Main differences between tedge/measurements and c8y/measurement/measurements/create
When using c8y/measurement/measurements/create
you have to:
- Specify the
time
field yourself following the standard Cumulocity IoT timestamp format (e.g. ISO8601). See docs under the “Date format” section.
- Add the
externalSource
fragment if you want to create a measurement for a child device