Skip to content

Instantly share code, notes, and snippets.

@anaptfox
Created December 16, 2016 16:42
Show Gist options
  • Save anaptfox/708cd010a53d19b7b7dc029a235ca092 to your computer and use it in GitHub Desktop.
Save anaptfox/708cd010a53d19b7b7dc029a235ca092 to your computer and use it in GitHub Desktop.
Losant support for browser
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var Device = require('losant-mqtt').Device;
// Construct device.
var device = new Device({
id: 'device-id',
key: 'access-key',
secret: 'access-secret',
transport: 'ws'
});
// Connect to Losant.
device.connect();
// Listen for commands.
device.on('command', function(command) {
console.log('Command received.');
console.log(command.name);
console.log(command.payload);
});
// Send temperature once every second.
setInterval(function() {
device.sendState({ lightLevel: 4 });
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment