Get Started

In this tutorial, we show you how you create your first device on Datacake and how you can connect your physical End-Devices to it using:

  • MQTT over Datacake MQTT Broker

Register on the Datacake Cloud

This tutorial assumes that you have already created a user account on the Datacake platform. If this is not the case, please register now. Your first five devices are free and registration only takes a few minutes.

Please use the following link:

MQTT vs. REST-API

You can connect your devices to Datacake and record measurement values using MQTT or the Datacake REST-API. However, there are very clear use cases for both variants.

Using MQTT

MQTT is for Real-Time Communication. Choose MQTT if you want to exchange measurement data in real-time between device and platform or between devices.

Using REST-API

Alternatively, use the Datacake REST-API if you need to transfer multiple readings in one go.

Individual Timestamps

Using the REST-API also provides additional features such as setting an individual timestamp. This allows measured values to be imported retroactively.

Create a new Device

To store readings via MQTT, you will need an appropriate device on the Datacake platform. To do so, navigate to the fleet view of your workspace.

There you will find a button "Add Device" in the upper right area of the listing. With one click you can create a new device. The following dialog appears:

Here you select the device type "API" and assign a name to your device (in the example we named it "My MQTT Device").

Confirm the creation of the device by clicking on the button "Add Device and configure". This takes us directly to the next step.

Add Database Field

Now a field has to be created in the database of the device, which will later carry the measured values that are sent via MQTT (or REST-API).

By pressing the "Add Device and configure" button, you can directly access the configuration of your device. Then scroll down a little until you reach the section where you can create the database fields.

For this example, we will now create a field that will contain a temperature. To do this, click on the button "Add Field". A dialog will appear where you can enter the details for the new field.

Enter the required information in the input areas. Select a name for the field and an identifier (In this example, we will call the field "Temperature"). The latter can only be defined once during the assignment. You can change the name at any time.

Various types are available for the way data is stored. For this example we choose the type "Float".

If you want to learn more about the different data types or how database fields behave in general, please use the following link:

Once the field has been created, it will also appear in the database field list.

Everything is now prepared for the next steps.

Connect to Datacake MQTT Broker

In order to be able to import measured values into the field via MQTT, you need to connect to the Datacake MQTT Broker. This uses the following URL:

mqtt.datacake.co

To connect, you must authenticate yourself using an access token. The easiest way to start is to use your personal token. You can find out exactly how this works and which steps are required in the MQTT documentation:

Record Measurement Values

If you are connected to the Datacake Broker, you can use a Publish with measured value to upload the values to the "Temperature" database field. The topic structure looks like the following according to the general Datacake-Topic-Structure:

publish("dtck-pub/my-mqtt-device/b4fb3cae-9387-46ac-8d6c-687f3d94f1e2/TEMPERATURE", 23.02)

You only need to change the device ID in the topic to the ID of your device. You can find this in the metadata overview (if your device does not have its own serial number) or in any case in the URL of the current device.

In the following screenshot we used the free tool MQTT Explorer to simulate the recording of measured values via MQTT.

If you now perform a publish, the measured value is also shown next to the field in the configuration overview.

Troubleshooting

If you cannot see any change in the values shown in the database table, it could be the case that your client is incorrectly configured or that your access token (if you have created one yourself) does not have the required rights.

Another indicator for this is that the broker is disconnecting the client. Therefore please check the settings of your client and the token (if applicable).

If you still have problems, please contact our support via support@datacake.co​

Record programatically

Of course the recording of measured values via MQTT is not limited to programs like the MQTT Explorer. You can use various programs, libraries and devices for communication via MQTT. You will find a few examples in the following section:

Using Javascript

The following code-snippet demonstrates how to use Javascript and MQTT functionality to send values from a device to Datacake.

const mqtt = require('mqtt');
​
const client = mqtt.connect('mqtts://mqtt.datacake.co', {
username: "yourauthtoken",
password: "yourauthtoken"
});
​
client.on('connect', () => {
console.log('Connected to Datacake Cloud');
// subscribe to all fields from that devices
// can be used to send messages from datacake onto device
client.subscribe('dtck/my-mqtt-device/b4fb3cae-9387-46ac-8d6c-687f3d94f1e2/+');
});
​
client.on('message', (topic, message) => {
// do something here
});
​
// Publish a value of 23.02 to Datacake and Device Field
client.publish('dtck-pub/my-mqtt-device/b4fb3cae-9387-46ac-8d6c-687f3d94f1e2/TEMPERATURE', 23.02);

Republish

If you import measured values into a database field of your device, then this change will also be published from the device. You can subscribe to this republish as a client via the following Topic-Structure:

dtck/my-mqtt-device/b4fb3cae-9387-46ac-8d6c-687f3d94f1e2/TEMPERATURE

M2M

You can also use these republics as a basis for M2M communication. For more information on this topic, please click on the following link:

Next steps

In this tutorial we have gone through all the steps necessary to connect your devices via MQTT to the Datacake platform. The next steps are to create more fields, create dashboards and define rules. Just follow the documentation.

Record using REST API

Another interesting feature is the use of the REST-API for importing data. In this way, several measured values can be imported at the same time and provided with an individual timestamp.