Datacake Docs
  • Welcome
  • Get Started
  • Changelog
  • Best practices
    • Best practices: Getting started
    • Best practices: Resolution (Timeframe)
    • Best practices: Dashboards
    • Best practices: Reports
    • Best practices: Grouping Devices
  • Datacake LNS
    • Getting Started
    • Gateways
      • Milesight LoRaWAN Gateway - UG6x
      • RAKwireless WisGate Edge Light 2
    • Devices
    • Add Devices without Gateway
  • Wireless IoT Hub
    • Overview
    • Datasheet
    • Getting Started
  • Device
    • Product
    • Configuration
    • Claiming
    • Historical Data
    • Database
      • Configuration Fields
      • Fields
        • Manual input
        • Field Roles
        • Formulas
        • Mapping Fields
      • Data retention & Datapoints
      • Examples
        • Mapping 4-20mA Signals
        • Converting Units
  • Dashboards
    • Global Dashboards
      • Setting Homepage
    • Device Dashboards
    • Multi-Device Dashboards
    • Widgets
      • Value Widget
      • Chart Widget
      • Image Map
      • Map Widget
      • Text Widget
      • SOS Widget
      • Boolean Widget
      • iFrame Widget
      • Downlink Widget
      • Set Value Widget
      • Measurement List Widget
      • Heatmap Widget
      • Table Widget
      • Image Widget
  • Portal
    • Multi-Tenancy (Workspaces)
    • Reports
      • Energy Report
    • Administrators
    • Members
      • API Users
    • Security & Privacy
    • Billing
      • Support Packages
      • VAT Exemption / Tax ID
      • SMS Credits
      • Access Invoices
      • Unused time and Remaining time in Invoices (Prorations)
      • Codes
    • White Label
    • Rules
      • Legacy Rule Engine
        • Sending notifications via Telegram
      • New Rule Engine
        • Rule Engine Table Overview
        • Copy/Paste and Template Functionality
        • Advanced Rule Engine E-Mail and Webhook Templates
        • Time Restrictions
        • Actions
          • Set Value
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
        • How to create a device without a product template
    • Configuring LNS
      • The Things Stack (TTN / TTI) Automated Setup
      • The Things Stack (TTN / TTI) Manual Setup
      • Loriot
      • Kerlink Wanesy
      • Helium
      • ChirpStack
      • Tektelic
      • Actility ThingPark
      • Senet
      • Milesight Gateway
      • KPN
    • Downlinks (LoRaWAN)
      • Set Time Frame
    • Securing Webhooks
    • Payload Decoders
      • Location and GPS
      • Access Gateway Metadata
      • Access Measurements
      • Global Variables
    • Using Cayenne LPP
    • Converting Payload
  • Generic API Devices
    • HTTP Downlinks
  • Integrations
    • MQTT
    • Particle
      • Get Started
      • Adding Integrations
      • Decoding Payloads
      • Calling Functions
      • Templates
        • Particle Tracker One
    • Incoming Webhooks
    • Outgoing Webhooks
      • Securing Outgoing Webhooks in Datacake
    • Golioth
    • Blues Wireless Notecard
    • Sigfox
    • Swarm Asset Tracker
    • Grandcentrix Modbus Cloud Connect
    • YuDash LYNX IoT Gateway
    • Dragino NB-IoT
      • Changing NB-IoT Bands
    • Hardwario CHESTER
    • 1NCE OS
  • API
    • Exporting Data
    • Record Measurements via API
    • Node RED to Datacake
    • Generate Access Token
    • Internal MQTT
      • Get Started
      • MQTT Documentation
      • MQTT over WebSocket
      • Example Code
    • GraphQL API
      • Using GraphQL
      • Device Creation
      • Tutorials
        • Read Group via Tags
  • Guides
    • Python
    • Send Slack Notifications
    • Forward Data to Cake Red
    • Multiple Data Feeds
    • Automated Dynamic Downlinks
    • Ingesting JSON Data into Datacake API Devices
    • Working with Default HTTP Decoder on API Devices and Code Examples
    • Accessing Measurements in Decoders
    • Connecting Datacake to Notion Using Zapier
    • How to set up and use location on non-GPS devices
    • How to integrate with AWS IoT Core
    • How to Schedule Mass-Downlinks (Multicast) using Datacake Rule Engine
    • How to Map Sensor Values to Ranges or Booleans, Strings using Mapping Fields
    • Understanding Internal vs. External MQTT Brokers on Datacake
    • Sending UDP Messages between 1NCE OS and Datacake
    • Concepts of LoRaWAN Payload Decoders on Datacake
    • How to check if a value stays above or below limits for given time
Powered by GitBook
On this page
  • Node-RED Nodes
  • Installing the Extension
  • Configuring the Nodes
  • Sending Data
  • Node-RED Function Code
  • Script

Was this helpful?

  1. API

Node RED to Datacake

Last updated 1 year ago

Was this helpful?

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.

Node-RED Nodes

Datacake does provide custom Node-RED extension:

Installing the 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

Configuring the Nodes

  • 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:

Add Datacake Node 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:

Add Key to Node-RED Node

  • 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:

Sending 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:

Node-RED Function Code

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 GraphQL-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.

Script

// 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;
API Users
node-red-contrib-datacakenodered
Logo