Skip to content

Instantly share code, notes, and snippets.

@reubenmiller
Last active March 11, 2024 09:49
Show Gist options
  • Save reubenmiller/0fb8ddb59a56df90fe26c8b208017a59 to your computer and use it in GitHub Desktop.
Save reubenmiller/0fb8ddb59a56df90fe26c8b208017a59 to your computer and use it in GitHub Desktop.
Update Cumulocity Location using thin-edge.io

Updating the location information in Cumulocity IoT should not be a problem with thin-edge.io.

For reference, I created the options by reading the following Cumulocity IoT documentation links:

In summary, updating a location of a device (in the backend) involves creating an event and then updating a fragment on the device's managed object, however you have a few different options on how to achieve this with thin-edge.io:

Option 1: Using a SmartREST 2.0 static template

The 402 SmartREST 2.0 static template will take care of both creating the event and updating the inventory managed object fragment in one single message (though you have less control over the additional fields).

tedge mqtt pub c8y/s/us '402,<latitude>,<longitude>,<altitude>,<accuracy>,<time>'

Not all of the fields are mandatory (check the Cumulocity docs for details: https://cumulocity.com/docs/smartrest/mqtt-static-templates/#402)

But an example would be:

tedge mqtt pub c8y/s/us '402,51.151977,6.95173,67'

There is a slight variation to this which involves sending two different SmartREST 2.0 message, 401 (event) and 112 (inventory update), however the 402 is more convenient as it combines both into one single message.

Option 2: Using te/ topics

This is a two step process as you have to send both the event and the inventory managed object update (e.g. update the fragment)

Create an event with the type c8y_LocationUpdate and setting the c8y_Position fragment within the event.

tedge mqtt pub te/device/main///e/c8y_LocationUpdate '{
    "c8y_Position": {
       "alt": 67,
       "lng": 9.992036,
       "lat": 53.553582
    },
    "text": "Sudo stocktake with predefined Discovery"
}
'

Then update the c8y_Position fragment in the managed object of the device so that the UI will also track the location

tedge mqtt pub -r te/device/main///twin/c8y_Position '{
    "alt": 67,
    "lng": 9.992036,
    "lat": 53.553582
}'

Afterwards the location should be visible in the Cumulocity IoT Device Management Application.

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment