forked from xdrip-js/Lookout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pumpIO.js
31 lines (27 loc) · 846 Bytes
/
pumpIO.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
const chokidar = require('chokidar');
const fs = require('fs');
module.exports = (io) => {
let basalProfile;
const readBasalProfile = (path) => {
console.log(`Reading file ${path}`);
setTimeout(function() {
fs.readFile(path, 'utf8', function (err, data) {
if (err) return; // we'll not consider error handling for now
try {
basalProfile = JSON.parse(data);
io.emit('basalProfile', basalProfile);
} catch (e) {
return;
}
});
}, 1000);
}
chokidar.watch('myopenaps/settings/basal_profile.json')
.on('change', readBasalProfile)
.on('add', readBasalProfile);
io.on('connection', socket => {
socket.emit('basalProfile', basalProfile);
// iob = require('/root/myopenaps/monitor/iob.json');
// socket.emit('iob', iob[0]['iob']);
});
};