How to connect IoT devices to Cumulocity with Thingstream

2 mins read

Cumulocity is an IoT platform by Software AG which provides IoT device management, data visualisation and APIs for interfacing IoT with the rest of the enterprise network.

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.

Connect Thingstream to Cumulocity today

Create a free account

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.

Thingstream function node

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[1]; // 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:

msg.payload="100,"+msg.contextProperties.deviceName+",MQTT\n110,"+msg.clientid+"\n112,"+lat+","+lon;

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

Connect Thingstream to Cumulocity today

Create a free account
Resource

MQTT QoS explained

In this article, you’ll learn how, where and when to use MQTT QoS and which levels are right for your own IoT applications.

Resource

How does MQTT work?

This video gives a brief overview of how Thingstream uses MQTT to communicate between remote low-power IoT devices and the enterprise.

Globally connect your business

Get in touch with Thingstream to bring global IoT connectivity to your devices.

Get started