Example Scripts
To help you getting started, here are some simple scripts you can use.
Device Types
function consume(event) {
var sample = {data: event};
// Your custom logic here
emit('sample', sample);
}
Domains
function consume(event) {
var id = event.parameter.id;
var data = JSON.parse(event.content);
emit('uplink', {id: id, event: data});
}
Rule Types
function consume(event){
var temperature = event.sample.data.temperature;
var downlink_event = {cold: 0};
if(compare(temperature, properties.value, properties.op))
downlink_event.cold = 1;
else
downlink_event.cold = 0;
emit('output_device', downlink_event);
}
function compare(val1, val2, op){
if(op == 'gt')
return (val1 > val2);
else if(op == 'lt')
return (val1 < val2);
else if(op == 'ge')
return (val1 >= val2);
else if(op == 'le')
return (val1 <= val2);
else if(op == 'eq')
return (val1 == val2);
else if(op == 'ne')
return (val1 != val2);
}