-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsmartmeter-connection.js
31 lines (29 loc) · 1.09 KB
/
smartmeter-connection.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
module.exports = function (RED) {
'use strict';
const serialp = require('serialport');
function SmartmeterConnectionNode(n) {
RED.nodes.createNode(this, n);
this.serialport = n.serialport;
this.serialbaud = parseInt(n.serialbaud) || 57600;
this.databits = parseInt(n.databits) || 8;
this.parity = n.parity || 'none';
this.stopbits = parseInt(n.stopbits) || 1;
this.httphost = n.httphost || 'localhost';
this.httpport = n.httpport || 80;
this.filepath = n.filepath || '';
this.tcphost = n.tcphost || 'localhost';
this.tcpport = n.tcpport || 502;
}
RED.nodes.registerType('smartmeter-connection', SmartmeterConnectionNode);
RED.httpAdmin.get("/smartmeter-serialports", RED.auth.needsPermission('serial.read'), function(req,res) {
serialp.list().then(
ports => {
const a = ports.map(p => p.path);
res.json(a);
},
err => {
res.json([RED._(`serialport.list() error: ${err}`)]);
}
)
});
}