Insights

|

18 Nov 2019

How to connect IoT devices to Cumulocity with u-blox Thingstream

Connect IoT devices to Cumulocity anywhere in the world via MQTT with u-blox IoT Communication-as-a-Service platform, Thingstream.

cumulocity iot

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

Cumulocity integrates seamlessly with the u-blox Global Connectivity Network via the Thingstream service delivery platform, enabling device-to-enterprise connection almost anywhere in this world. Follow this guide to connect your IoT devices with the Cumulocity platform using u-blox 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 Cumulocity to u-blox Thingstream today

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 (pictured below) to create a payload with the required format for the Cumulocity static template you wish to use.

Function node - Thingstream

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 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 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 Cumulocity to u-blox Thingstream today

Nick Hayes

Head of customer operations - u-blox Services

You might also be interested in