Device

In order to modify, add, delete or do anything else with the data inside buckets, it is necessary to use the device function.

To setup an device object, you need a token (that you need to get in our website). Be sure to use tokens with the correct write/read previlegies for the current function that you want to use. For example, a token with only read previlegies can’t create, modify or delete anything from a device.

.info

Get all information from the device

Syntax
.info()

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');

mydev.info()
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });

.insert

Insert a new data into a bucket. You can get more information about what information can be passed with insert in our api documentation

Syntax
.insert(/data/)

Arguments
data(object) properties for the new data.
*variable(string): name of the variable. Obrigatory when inserting;
*value(string): a value for the data (optional);
*unit(string): a unit for the data, like ‘km’, or ‘F’. The unit may be showed in some widgets (optional);
*time(string): a time for the data. Default is now;
*serie(string): a serie for the data. Useful for some widgets when grouping with other data;
*location(object/geojson): a location object or geojson containing lat and lang;

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var data = {
    'variable': 'temperature',
    'unit'    : 'F',
    'value'   : 55,
    'time'    : '2015-11-03 13:44:33',
    'location': {'lat': 42.2974279, 'lng': -85.628292}
};

mydev.insert(data)
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });

.find

Get a list of data from bucket respecting the query options passed. You can get more information about what information can be passed with .find in our get documentation

Syntax
.find(/filter/)

Arguments
filter(object) filter options when retrieving data. (optional)
*variable(string/array): Filter by variable. If none is passed, get the last data (optional);
*query(string): Do a specific query. See the query documentation to know what can be passed. (optional)
*end_date(string): Get data older than a specific date. (optional)
*start_date(string): Get data newer than a specific date. (optional)
*qty(number): Number of data to be retrieved. Default is 15. (optional)

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var filter = {
    'variable':   'myvar',
    'query':      'last_value',
    'end_date':   '2014-12-25 23:33:22',
    'start_date': '2014-12-20 23:33:22'
};

mydev.find(filter)
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });

.remove

Remove data from the bucket respecting the query options passed. You can get more information about what information can be passed with .remove in our delete documentation

Syntax
.remove(/filter/)

Arguments
filter(object) filter options when deleting data. (optional)
*variable(string/array): Filter by variable. If none is passed, get the last data (optional);
*query(string): Do a specific query. See the query documentation to know what can be passed. (optional)
*end_date(string): Get data older than a specific date. (optional)
*start_date(string): Get data newer than a specific date. (optional)
*qty(number): Number of data to be deleted. Default is 15. (optional)

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var filter = {
    'variable':   'myvar',
    'query':      'last_value',
    'end_date':   '2014-12-25 23:33:22',
    'start_date': '2014-12-20 23:33:22'
};

mydev.remove(filter)
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });

.getParams

Get all params from the device

Syntax
.getParams()

Arguments
filter(boolean) filter options for retrieving the device parameters. (optional)*
*boolean(false): Retrieves all non-sent device parameter;
*boolean(true): Retrieves all sent device parameter;

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');

mydev.getParams() // you can use getParams(false) or getParams(true)
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });

.markParam

Marks as read a specific not yet read parameter

Syntax
.markParam(/id/)

Arguments
id(string) using a specific ID. (required)

Returns
(Promise)

const Device = require('tago/device');
const mydev  = new Device('0e479db0-tag0-11e6-8888-790d555b633a');

mydev.markParam('59933d82b09301ab13b844ac')
    .then((result) => {
        //You can treat the result here
    })
    .catch((error) => {
        //You can treat errors here
    });