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:

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.

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