Last active
December 31, 2015 07:08
-
-
Save c4milo/7951682 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var Swarm = require('bugswarm-prt').Swarm; | |
| var options = { | |
| apikey: '4d9b162a7f1b5122e551b427a3fb26d49df85f37', | |
| resource: 'aaeee512fda0a6dbb20d0baa5a05d85f35968777', | |
| swarms: ['9e4a8e85f12da09a3ed1cd0f3942f570ee12baa3'] | |
| }; | |
| var prosumer = new Swarm(options); | |
| prosumer.on('message', function(message) { | |
| console.log('message: ' + JSON.stringify(message)); | |
| }); | |
| prosumer.on('error', function(err) { | |
| console.log(err); | |
| }); | |
| prosumer.on('connect', function(err) { | |
| console.log('Connected!'); | |
| //Let's start sending random temperatures | |
| //from Central Park! | |
| setInterval(function() { | |
| prosumer.send(JSON.stringify({ | |
| 'temperature': Math.floor((Math.random() * 100) + 1) | |
| })); | |
| }, 2000); | |
| }); | |
| prosumer.on('presence', function(presence) { | |
| console.log('presence: ' + JSON.stringify(presence)); | |
| }); | |
| prosumer.on('disconnect', function() { | |
| console.log('disconnected'); | |
| }); | |
| //here is where the execution flow starts | |
| prosumer.connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment