-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutility.js
49 lines (40 loc) · 1.43 KB
/
utility.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
let opcua = require("node-opcua");
let os = require("os");
let exec = require("child_process").exec;
module.exports.getAvailableMemory = function() {
let percentageMemUsed = (os.freemem() / os.totalmem()) * 100.0;
return percentageMemUsed;
}
module.exports.getTemperatureAsync = function(callback) {
//get the temp asynchronously
let child = exec("/opt/vc/bin/vcgencmd measure_temp", function(err, stdout, stderr) {
if(err !== null){ callback(err, null); }
else {
let val = /^temp=(\d*\.\d*).*/.exec(stdout)[1];
let temp = parseFloat(val);
let dataValue = new opcua.DataValue({
value: new opcua.Variant({ dataType: opcua.DataType.Double, value: temp }),
statusCode: opcua.StatusCodes.Good,
sourceTimestamp: new Date()
});
callback(null, dataValue);
}
});
}
if (process.platform === "linux") {
var Gpio = require('onoff').Gpio; //include onoff to interact with the GPIO
var LED = new Gpio(4, 'out');
module.exports.getLedValue = function() {
return new opcua.Variant({
dataType: opcua.DataType.Boolean,
value: LED.readSync() === 1
});
}
module.exports.setLedValue = function(variant) {
LED.writeSync(+variant.value);
return opcua.StatusCodes.Good;
}
}
module.exports.freeResources = function() {
LED.unexport();
}