-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclimate.js
More file actions
51 lines (46 loc) · 1.53 KB
/
climate.js
File metadata and controls
51 lines (46 loc) · 1.53 KB
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
//SETUP FIREBASE!!!!!!
var https = require('https');
var tessel = require('tessel');
var climatelib = require('tessel-bme280');
var climate = climatelib.use(tessel.port.A);
// set up a loop when climate module is ready
climate.on('ready', function() {
// loop forever
setImmediate(function loop() {
climate.readTemperature('f', function(err, temp) {
climate.readHumidity(function(err, humid) {
console.log('Degrees:', temp.toFixed(4) + 'F', 'Humidity:', humid.toFixed(4) + '%RH');
postToFireBase(temp.toFixed(4), humid.toFixed(4));
setTimeout(loop, 1000);
});
});
});
});
// climate module threw an error
climate.on('error', function(err) {
console.log('error connecting module', err);
});
// Post the humidity and temperature to my firebase account:
// function postToFireBase(temp, humid) {
// var req = https.request({
// port: 443,
// method: 'POST',
// hostname: 'FIREBASEACCOUNT.firebaseio.com',
// path: '/climate.json',
// headers: {
// "Host": "FIREBASEACCOUNT.firebaseio.com",
// "Accept": "*/*",
// "User-Agent": "tessel"
// }
// }, function(res) {
// console.log('statusCode: ', res.statusCode);
// });
//
// req.write('{"datetime": ' + new Date().getTime() + ', "temp": ' + temp + ', "humid": ' + humid + '}');
// req.write('\r\n');
// req.end();
//
// req.on('error', function(e) {
// console.error(e);
// });
// }