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
  • 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
    • Zones
  • Cake Red
    • Get Started
    • Overview
  • LoRaWAN
    • Get Started
      • CSV Import
      • Custom LoRaWAN Device
    • 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
  • Device Creation
  • Important Notes
  • Add Fields to Product
  • Important Notes
  • Node-RED Example
  • Function Node Code

Was this helpful?

  1. API
  2. GraphQL API

Device Creation

Device Creation

mutation {
  createLoraDevices(input:{
    workspace:"e55e1602-c4a8-4d2e-9848-f44296667c5f",
    plan:"free",
    planCode:"",
    productKind:NEW,
    newProductName:"My New Product",
    networkServer:"Helium",
    devices:[
      {
        devEui:"99f83ad2b5c7dead", 
        name:"My First Device"
      }
    ],
  }) {
    ok
    devices {
      id
      verboseName
      serialNumber
      product {
        id
      }
    }
  }
}

Important Notes

For the plan:"" and planCode:"" parts you can as well select the plan you want your devices to be in. For paid plans, make sure that you have setup your billing information under Billing. The options are:

plan:"free",
planCode:""
    
plan:"light",
planCode:""
    
plan:"standard",
planCode:""
    
plan:"plus",
planCode:""

You can use your personalised plan and code, in case you bought a package. In that case, ask the support team about the plan and use your code to redeem devices on the planCode:""section.

// E.g.
plan:"light",
planCode:"YOURCODEGOESHERE"

If you create a device this way, then a new product is also created automatically (the Product Type is set to NEW).

Therefore, in the above mutation, the Product ID is also requested as the return type.

Please make a note of this ID for subsequent mutations, such as creating fields on the product (see below).

For the networkServer:"" part you have of course various options. You can add your devices to any of the integrated LNS:

DATACAKELNS
TTI
HELIUM
HELIUMIOTCREATORS
LORIOT
CHIRPSTACK
ACTILITY
SENET
MELITA
WANESY
KPN
WIOTYS
TEKTELIC
MILESIGHTGATEWAY
EVERYNET
CATTELECOM
ORBIWISE

The field is not case-sensitive, so you can indifferently write: networkServer:"TTI" or networkServer:"tti" and they both should work.

For adding devices to our Datacake LNS you will have to provide extra information about your devices, including the AppEUI (or JoinEUI), the AppKey, the device class and the frequency range you are working with.

The supported frequency ranges are:

EU_863_870_TTN
US_902_928_FSB_2
AU_915_928_FSB_2
AU_915_928_FSB_2_NAM
AS_920_923
AS_920_923_LBT

The supported classes are:

A
C

Here an example:

mutation {
  createLoraDevices(input:{
    workspace:"YOUR_WORKSPACE_UUID",
    plan:"free",
    planCode:"",
    productKind:NEW,
    newProductName:"My New Product",
    networkServer:"DATACAKELNS",
    devices:[
      {
        devEui:"YOUR_DEVEUI", 
        name:"My First Device",
        appeui: "YOUR_APPEUI",
        appkey: "YOUR_APPKEY",
        frequency: "EU_863_870_TTN",
        deviceClass: "A",
      }
    ],
  }) {
    ok
    devices {
      id
      verboseName
      serialNumber
      product {
        id
      }
    }
  }
}

Add Fields to Product

If you want to add new fields in the database to the new product you created using the above query, please use the following query.

mutation {
  addProductMeasurementField(
    productId:"deccd6b9-2a8a-4ee5-89bd-be19cded3b43",
    fieldType:FLOAT,
    verboseFieldName:"My Float Field",
    fieldName:"MY_FLOAT_FIELD",
    role:PRIMARY,
    unit:"Volt"
  ) {
    ok
  }
}

Important Notes

To be able to identify the product in the mutation, you have to pass the product ID (key productId).

You can get this either via a GraphQL query, or you can use the above mutation for the creation of a new device (and subsequent product), which returns the product ID of the created product as a return if successful.

Node-RED Example

Function Node Code

  • The following code can be used as a function node.

  • It creates a new and empty Device using the "light" plan.

  • You will need billing enabled on the workspace and the token you are using for this action needs to have device creation and billing rights.

// Datacake API Token
var token = "yourdatacaketoken";

// Datacake Product UUID
var productUUID = "datacakeproductid";

// Datacake Workspace UUID
var workspaceUUID = "workspaceid";

// GraphQL API URL
msg.url = "https://api.datacake.co/graphql/";

// GraphQL Header
msg.headers = {
    "Authorization": "Token "+token,
    "Content-Type": "application/json"
};

var devEUI = "ABCD01020304DEFG";
var devName = "My LoRaWAN Device";

// Query Insert
var devicesString = '[';
devicesString += '{';
devicesString += 'devEui: "';
devicesString += devEUI
devicesString += '", name: "';
devicesString += devName;
devicesString += '"}';
devicesString += "]";

// GraphQL Query to create a new and empty LoRaWAN Device
var query = `mutation {
  createLoraDevices(input:{
    workspace:"${workspaceUUID}",
    plan:"light",
    planCode:"",
    productKind:NEW,
    newProductName:"My New Product",
    networkServer:"Helium",
    devices:${devicesString},
  }) {
    ok
    devices {
      id
      verboseName
      serialNumber
      }
    }
  }
}`;

msg.payload = {"query": query};
msg.body = {"query": query};

return msg;

Last updated 1 month ago

Was this helpful?