Data visualisation – connecting TTN to Datacake - Part 2


Note: most of the instructions below relate to Board 4, as the procedure seems to remain the same for Board 6. We will be returning to Board 6 in the section ‘Webhook Integration on TTN’.

Configuring your Arduino device on Datacake

In a previous tutorial, Data visualisation – connecting TTN to Datacake - Part 1, we created a webhook in your TTN account. We now need to configure Datacake to use this webhook to receive and display data from TTN.

Datacake homepage

Return to your Datacake account, if you have not already done so, and on the ‘Devices’ page, click on the name of your recently added board to be taken to this page: 



Configuration page

Click on the ‘Configuration’ tab to be taken to this page.

There’s a lot going on in this page. This screenshot just shows you the name of the board. Now, scroll down the page.


Configuration continued

Scroll down to see this.

Here you can see the Dev EUI of your board. Immediately below the Dev EUI you will see a section called ‘Network Server’. Here, you can see the message ‘Downlinks not configured’. We will be configuring them in the next section.

For now, the important bit is the section called 'Payload Decoder'. This is the bit where we display the uploads from your Arduino. You will see it initially contains some placeholder code, written in JavaScript. We will be replacing this with our own decoder.



More configuration

Scroll down to see this page.

The ‘Fields’ panel is where we create fields or ‘datapoints’ in which to store the data uploaded from the Arduino device. This is what we will do next.

Configuring fields in Datacake

We will start by setting up a ‘temperature’ field to store the data from our DS18B20 temperature sensor.

Add field

Click the blue ‘Add Field’ button at the top right of the ‘Fields’ section. You should then see this.



Add temperature field

To create a field to hold temperature data, write a name in the ‘Name’ field. In this case ‘Temperature’. The ‘Identifier’ field will be filled in automatically. Leave everything else on their default settings.

Field added

Click the blue ‘Add Field’ button to see this.

Here you see the new field in the ‘Fields’ section. In order to retrieve the temperature measurements, we now have to set up the payload decoder.



Configuring the payload decoder

Debug page

Return to the top of the page and click on the ‘Debug’ tab. You should see something like this.

Here you will see that data is being sent to Datacake, but it is not being read because we have yet to configure the payload decoder.

Return to the Configuration page and scroll down to the Payload Decoder section. Currently, we have:

function Decoder(payload, port) {
    /*
    return [
        {
            field: "TEST",
            value: 123
        }
    ];
    */
}

‘field’ and ‘value’ are a ‘key - value pair’. In order to decode the data from your Arduino, we need to replace the field ‘TEST’ with whatever you have called it in the ‘Fields’ section that you have just set up. In the example above, that would be TEMPERATURE. As you can see, we are using the ‘Identifier’, not the name we gave it.

Also note that this section of code lies between the lines ‘/*’ and ‘*/’. These are opening and closing ‘comment’ tags. All code lying between these two tags is ignored, so you will have to remove them when you add your real code.

We first have to change this code to reflect what is written in the Arduino sketch. Open the sketch you created and you will see: 

byte payload[1]; // The [1] means we are sending one item in the array. Arrays start at zero.
payload[0] = tempVariable; // Send temperature by LoRa.

We now have to reference the first (in this case only) item in the array, and then save it in the ‘Temperature’ field we set up earlier. When counting items in an array, remember that arrays start at 0 (as in zero), so the second item would be 1, the third would be 2, and so on. The code then becomes:

function Decoder(payload, port) {

    var decoded = [];

        return [
            {
                "field": "TEMPERATURE",
                "value": payload[0]
            },
        ];
    

    return decoded;

}

Payload decoder

Copy and paste this code into the 'Payload Decoder' section.



Try decoder

You can test your code by scrolling down to the foot of the Payload Decoder. Type the number 10 into the Payload box (this is hexadecimal for the number 16) and click the blue ‘Try Decoder’ button.

Don’t forget to click the black ‘Save’ button to update your payload decoder.

View debug data

If you return to the ‘Debug’ tab, you should see this.

Looking along the top line of data, you will see the field marked TEMPERATURE, and the value ‘19’.

Returning to the ‘Configuration’ tab and scrolling down to the ‘Fields’ section, you should see the value of 19 now inserted into the ‘CURRENT VALUE’ column.

You can now retrieve and save data from your Arduino sensors. 


The example above is for just one piece of data. If you have more, just add more JavaScript (and more fields). For example, for two items,

function Decoder(payload, port) {

    var decoded = [];

        return [
            {
                "field": "TEMPERATURE",
                "value": payload[0]
            },
            {
                "field": "SOMETHINGELSE",
                "value": payload[1]
            },

        ];

    return decoded;
}

Don’t forget to increment your payload value by ‘1’ for every additional field. And to add the extra field to the ‘Fields’ in the Payload Decoder section.

The data is sent from the Arduino to Datacake as hexadecimal code. This code can only deal with integers between 0 and 255. We will deal with sending number larger than this (and numbers with decimal points) in a separate section. 

Creating a dashboard for your device

Datacake allows you to set up a dashboard in your account that lets you graphically view the data coming from your sensors. We will set one up for our temperature measurements.

Scroll to the top of the page and click on the ‘Dashboard’ tab.  

Edit dashboard

Then click on the ‘Edit’ symbol on the right:

Add widget

Next, click on the blue 'Add widget' button.


Add value widget

Next, click on the ‘Value’ widget.

Widget name

Under the ‘Basics’ tab, give your widget a name. I called mine ‘Current Temperature’.


Name data

Under the ‘Data’ tab, select ‘Temperature’ from the dropdown.

Gauge name

Under the ‘Gauge’ tab select the style of gauge you would like. I chose circular and added some colours to display a range of temperatures from 0 to 30 degrees. But you can choose whatever style or colour you like.

You can leave the other tabs as their defaults. Then click the blue ‘Save’ button.

Widget added

You have added your first widget.

Now add a chart widget. Click the blue ‘Add Widget’ button again, but this time add a ‘Chart’ widget.

Under the ‘Basic’ tab, add a title such as ‘Today’s Temperature Measurements’.

Under the ‘Data’ tab, click ‘Add’ and then select ‘Temperature’ from the drop-down list in the ‘Field’ box.

Under ‘Timeframe’ select ‘Day’.

Add chart widget

Leave everything else as default. Click the blue ‘Save’ button. You should see something like this.

You can now rearrange your widgets and resize your boxes. 

Configure mobile

If you click on ‘Mobile’, you can specify the view on your phone.

Click on the ‘More’ dropdown and select ‘Create from desktop’. Again, you can drag and resize the widgets.

When done, toggle the yellow button at the top right to save your layout. 

We can now save and view data from our Arduino and associated sensors. Next, we will see how to send data back down to the Arduino in response to uploaded data. This will allow us to control devices connected to our Arduino.

In the next section we will cover sending instructions back to your sensor by configuring downlinks with Datacake. Click here for the next steps.

© Copyright 2025 Dr Dulcamara - All Rights Reserved