How to use losant-mqtt - 2 common examples

To help you get started, we’ve selected a few losant-mqtt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Losant / losant-mqtt-js / examples / basic.js View on Github external
/**
 * 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.
github Losant / losant-mqtt-js / examples / intel-edison.js View on Github external
*/

 /* 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.

losant-mqtt

An MQTT client for Losant

MIT
Latest version published 3 years ago

Package Health Score

40 / 100
Full package analysis

Popular losant-mqtt functions