Device Context

  • When an IoT sensor reports to the platform, a new Device data structure is created, which will hold all the meta information like, created time, last reported time, last protocol channel it reported etc. And also a separate key-value storage space is created for each and every device where you can store device related information of any datatype
  • Context Variable: device
  • Only Applicable To: Message Rules, Binary Rules & Domain Rules
    • Even though an instance of the device is available in the message and binary rules, devices can also be fetched from other types of rules using Domain Context.

API Interface

// Retrieve the Device model object
public Device get();

// Creates a Device Group and returns the context
public DeviceGroupContext createGroup(long groupId, String name);

// Retrieves a DeviceGroup with specified id
public DeviceGroupContext  group(long groupId);

APIs Inherited From

Example

def inited = device.get("inited", false)

if(!inited){
  device.property("statistics", ['counter':0]);
}

def stats = device.property("statistics");

stats.counter = ++stats.counter;

long diff = (utils.millis() - device.get().getReportedStamp().getTime())/1000;
stats['connected'] = (diff <= 180) ? true : false;

//update the property
device.property("statistics", stats); //Property storage
device.put('inited', true); //Lookup variable

See Also

Related REST APIs

Register New Device
Create / Update Device
Retreive Device
Delete Device
List Devices
Count All Devices
Search Devics