-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
30 lines (26 loc) · 855 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Particle = require('particle-api-js');
const Winston = require('winston');
const Config = require('./config');
Winston.add(Winston.transports.File, { filename: 'events.log' });
const particle = new Particle();
let token = null;
particle.login({username: Config.get('USERNAME'), password: Config.get('PASSWORD')}).then(
(data) => {
console.log('API call completed on promise resolve: ', data.body.access_token);
token = data.body.access_token;
listen();
},
(err) => {
console.log('API call completed on promise fail: ', err);
}
);
function listen() {
particle.getEventStream({ deviceId: 'mine', auth: token }).then((stream) => {
console.log('Started listening');
stream.on('event', (data) => {
Winston.log('info', data);
});
}, (err) => {
console.log('Failed to start listening: ', err);
});
}