forked from xtrinch/sx127x-node-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temperature-reader.js
45 lines (39 loc) · 991 Bytes
/
temperature-reader.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
const express = require('express');
const app = express();
const util = require('util');
const {
exec
} = require('child_process');
var SX127x = require('../lib/sx127x');
var sx127x = new SX127x({
frequency: 434e6,
dio0Pin: 6, // BCM numbering (run `gpio readall` for info)
resetPin: 13, // BCM numbering (run `gpio readall` for info)
syncWord: 0x12,
debug: true,
tempCompensationFactor: 10,
});
async function readTemperature() {
try {
await sx127x.open();
} catch(err) {
console.log(err)
}
while(true) {
let temperature = await sx127x.readTemperature();
console.log('Temperature is: ' + temperature + ' degrees celsius');
await util.promisify(setTimeout)(1000);
}
}
readTemperature();
process.on('SIGINT', async function() {
// close the device
try {
await sx127x.close();
} catch (err) {
console.log('close failure: ' + err);
process.exit();
}
console.log("success");
process.exit();
});