-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththingService.js
executable file
·53 lines (41 loc) · 1.08 KB
/
thingService.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
53
var Sensor = require("sensor-am2302"),
temp_hum = new Sensor({pin:4}),
config = require('./config');
var readTemp = function(callback){
temp_hum.read(function(err, data) {
try{
if (err) {
console.error(err);
} else {
callback(data);
//console.log("Temp: ", data.temp);
//console.log("Hum: ", data.hum);
}
}catch(e){
console.log(e);
}
});
};
var createThing = function(){
var thing = {};
thing.settings = {
"name": 'Temperature & Humidity @ mobenga',
"id": 3942879,
"iconType": "Thermometeer",
"position": config.getPosition(),
"information":[{
"header":"Temperature @ mobenga"
}]};
var timeForUpdate = function() {
var update = function(data){
if(thing.socket){
//console.log(data);
thing.socket.emit('updateInfo', data.temp +" °C, " + data.hum + " %");
}
};
readTemp(update);
};
var intervalId = setInterval(timeForUpdate, 10000);
return thing;
};
module.exports.thing = createThing();