Node RED to Datacake
In this tutorial we will show you how you bring your devices into the Datacake Portal using Node-RED.
Node-RED is a popular tool that can be installed on smaller Linux Computers and help you create things without the need to write code.
Datacake does provide custom Node-RED extension:
- Navigate into the "Manage Palette" setting on your Node-RED

- Select "Install" and enter "Datacake" as the search term
- If not yet installed press "Install" on the element in the List
- The Datacake Nodes will now automatically installed
- To start with Datcake Node-RED Nodes simply drag one of the Nodes onto an empty flow
- Double-Click on the Node to open up Configuration:

- Each Datacake Node can access a Device
- To access Devices the Node needs to communicate with a Workspace
- You do this by providing an Access Key
- Now click on the "Edit"-Icon next to "Add new Datacake-Configuration":

- Now you have to enter an API Key which you need to create in your Workspace
- This API Key needs all rights so that you can access all devices
- Also it makes sense to give this API Key permission for all Devices in Workspace so that all current and future devices will be automatically added to the Node-RED Node.
Learn More about creating API Keys here:
- The key should look like:

- Now you add the Key to your Node-RED configuration in your Node-RED

- Shortly after entering you can select the Workspace
- Select one Workspace and press "Add"
- This will bring you back to the configuration of the Node and here you can now select the Device + Field from which you want to receive data:

- If you want to Send Data from Node-RED into Datacake via Nodes simply drag the Output Node onto your flow and configure the Node like the input node:

Datacake does provide custom Node-RED Nodes that interact with Node-RED over the MQTT API. These are however more suitable for real-time use-cases as they report live measurement value changes.
If you are however looking for a way to record multiple measurements simultaneously you should go for using the REST-API instead.
This following example shows a script that can be embedded in a Node-RED function-Node which then needs to be hooked up to an HTTP-Request-Node.
When a message hits the function-Node, the script performs a write operation with the Datacake API and records measurement values send through the function into a given Datacake Device.
// Set device_id to serial-number of Datacake API Device
var device_id = "be525e29-4398-4fc1-a928-dead7fdfe218";
// Set Token to your personal access token or individual token
var token = "put your token in here";
// This is the API Information for the HTTP Request Node
msg.url = "https://api.datacake.co/v1/devices/"+device_id+"/record/?batch=true"
// Create Header for Node-RED HTTP Node
msg.headers = {
"Authorization": "Token "+token,
"Content-Type": "application/json"
};
// Now we are going to create the Payload we forward to Datacake API
msg.payload = [
{
"field": "WATT",
"value": msg.payload.watt
},
{
"field": "AMPERE",
"value": msg.payload.ampere
},
{
"field": "VOLT",
"value": msg.payload.volt
}
];
// Return it - were all set!
return msg;
Last modified 2yr ago