-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensortagIRTemperature.js
More file actions
56 lines (47 loc) · 1.62 KB
/
sensortagIRTemperature.js
File metadata and controls
56 lines (47 loc) · 1.62 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
52
53
54
55
56
var SensorTag = require('sensortag');
var mqtt = require('mqtt')
var TempVal = {}
var flag = 0
SensorTag.discover(function(tag) {
tag.on('disconnect', function() {
console.log('disconnected!');
process.exit(0);
});
function connectAndSetUpMe() {
console.log('connectAndSetUp');
client = mqtt.connect('mqtt://192.168.0.4:1883')
client.subscribe('command')
client.on('connect', function() {
console.log("Connected")
// client.subscribe('presence')
})
tag.connectAndSetUp(enableIrTempMe);
}
function enableIrTempMe() {
console.log('enableIRTemperatureSensor');
// when you enable the IR Temperature sensor, start notifications:
tag.enableIrTemperature(notifyMe);
}
function notifyMe() {
tag.notifyIrTemperature(listenForTempReading); // start the temperature listener
}
// When you get an temperature change, print it out:
function listenForTempReading() {
tag.on('irTemperatureChange', function(objectTemp, ambientTemp) {
TempVal.OTemp = objectTemp.toFixed(1);
TempVal.ATemp = ambientTemp.toFixed(1);
console.log(TempVal)
console.log("In Mqtt send")
client.publish('test', JSON.stringify(TempVal))
});
client.on('message', (topic, message) => {
if (message.toString() == 'off') {
console.log("Disconneted")
flag = 1
tag.disconnect();
}
})
}
// run the process from start again:
connectAndSetUpMe();
});