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:
- https://cumulocity.com/docs/device-integration/fragment-library/#tracking
- https://cumulocity.com/docs/smartrest/mqtt-static-templates/#402
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](https://private-user-images.githubusercontent.com/3029781/311658027-085e1d95-9183-46e6-8146-e324e431c353.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMzI3MTEsIm5iZiI6MTcyMTIzMjQxMSwicGF0aCI6Ii8zMDI5NzgxLzMxMTY1ODAyNy0wODVlMWQ5NS05MTgzLTQ2ZTYtODE0Ni1lMzI0ZTQzMWMzNTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTdUMTYwNjUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZTdiMWMxYWFlOWMzOTllNzJkODYwMzU4MmQyMWM3MzQ1MzMyZjY3OTBkOGJjY2VjMDg0ZGNkNGU2OTc4YmJmYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.n8s3b0d3iZxF_9vLEejv9QDyD3q_r-Asek94htB0VAQ)