Created
December 16, 2016 16:42
-
-
Save anaptfox/708cd010a53d19b7b7dc029a235ca092 to your computer and use it in GitHub Desktop.
Losant support for browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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