Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Basic example of connecting to the Losant platform.
*
* Copyright (c) 2019 Losant IoT, Inc. All rights reserved.
* https://www.losant.com
*
*/
/* eslint no-console: "off"*/
var Device = require('losant-mqtt').Device;
// Construct a device instance.
var device = new Device({
id: 'my-device-id',
key: 'my-access-key',
secret: 'my-access-secret'
});
// Connect device to Losant.
device.connect();
// Attach event listener for commands.
device.on('command', function(command) {
console.log(command.name);
console.log(command.payload);
});
// Once a second, report state to Losant.
*/
/* eslint no-console: "off"*/
var mraa = require('mraa');
var Device = require('losant-mqtt').Device;
// Reading temperature from analog input.
var temp = new mraa.Aio(0);
// Blinking an LED everytime temperature is read.
var led = new mraa.Gpio(7);
led.dir(mraa.DIR_OUT);
// Construct a device instance.
var device = new Device({
id: 'my-device-id',
key: 'my-access-key',
secret: 'my-access-secret'
});
// Connect device to Losant.
device.connect();
// Attach event listener for commands.
device.on('command', function(command) {
console.log(command.name);
console.log(command.payload);
});
// Once a second, read the temp and report to Losant.