Cumulocity integrates seamlessly with the Thingstream Global Connectivity Network, enabling device to enterprise connection almost anywhere in this world. Follow this guide to connect your IoT devices with the Cumulocity platform using Thingstream.
The easiest way of getting data from your devices into Cumulocity is via MQTT (MQ Telemetry Transport). Software AG has a number of MQTT static templates that you can use to quickly register a device in Cumulocity and send updates for common use cases e.g. location update, sending telemetry.
Using Cumulocity MQTT static templates in Thingstream flows
To use the static templates in a Thingstream Flow, you will need to add a function node to create a payload with the required format for the Cumulocity static template you wish to use.
MQTT publishes to Cumulocity need a unique Client ID for the device. A good idea is to derive this from the Thingstream Client ID which would be done using a Thingstream function node with the following code:
var id = msg.contextProperties.deviceId.split(':'); //This takes the unique device ID of your thing, splitting off the prefix "device:" to make it compatible with Cumulocity msg.clientid = id; // This sets the msg.clientid property which is used by the Thingstream MQTT Publish Node
Registering a new device in Cumulocity uses the static template “100” to create the device and static template “110” to update it with the Client ID . If the device already exists in Cumulocity, these requests are simply ignored. Add the following code to the the Thingstream function node:
msg.payload="100,"+msg.contextProperties.deviceName+",MQTT\n110,"+msg.clientid // This creates a device in Cumulocity using the display name of the Thingstream Thing and the client ID created in the previous step
Adding a location to the device in Cumulocity uses the static template “112” which can be done using using a Thingstream function node with the following code where lat and lon are variables that you have declared from the incoming payload of your device:
msg.payload = "112,"+lat+","+lon;
If you like, you can do the register, update and set location tasks one after the other by simply joining each static template publish with a line break:
Once your payload is ready, you would join the function node to an MQTT Publish Node configured with the credentials for your Cumulocity tenant. The server URL is mqtt.cumulocity.com and the topic to publish to is s/us. Leave the Client ID empty so that the msg.clientid value you set earlier is used and then set the username as your Cumulocity user ID prefixed with your tenant name e.g. mytenant/myusername. Set the password to the same password you use to login to Cumulocity