forked from chrisb2/battery-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ota-update.js
52 lines (45 loc) · 1.5 KB
/
ota-update.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*jslint node: true */
"use strict";
var auth = require('./auth.js');
var Particle = require('particle-api-js');
var particle = new Particle();
particle.login({
username: auth.username,
password: auth.password
}).then(
function(data) {
console.log('Login success');
particle.getEventStream({
deviceId: auth.device,
auth: auth.token
}).then(function(stream) {
stream.on('event', function(data) {
if (data.name == "spark/status" && data.data == "online") {
var publishEventPr = particle.publishEvent({
name: 'flashRequest',
data: {},
isPrivate: false,
auth: auth.token
});
publishEventPr.then(
function(data) {
if (data.body.ok) {
console.log("Sent flash request event...")
}
},
function(err) {
console.log("Failed to publish flash request event: " + err)
}
);
}
if (data.name == "flashReady") {
console.log("Received flash ready event");
process.exit();
}
});
});
},
function(err) {
console.log('Login failed: ', err);
}
);