-
Notifications
You must be signed in to change notification settings - Fork 2
/
temperature.js
29 lines (26 loc) · 958 Bytes
/
temperature.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
require('dotenv').load();
var spark = require('spark');
var Pusher = require('pusher');
var pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET
});
spark.on('login', function() {
spark.getEventStream('Temp', process.env.SPARK, function(data) {
var temp = JSON.parse(data.data);
var time = data.published_at;
console.log('Temp: ' + temp.temperature);
console.log('Humidity: ' + temp.humidity);
if(temp.temperature){
pusher.trigger('temp', 'temp', { temperature: temp.temperature, timestamp: time });
}
if(temp.humidity){
pusher.trigger('temp', 'humidity', { humidity: temp.humidity, timestamp: time });
}
if(temp.temperature && temp.humidity){
pusher.trigger('temp', 'all', { humidity: temp.humidity, temperature: temp.temperature, timestamp: time });
}
});
});
spark.login({ accessToken: process.env.SPARK_TOKEN });