Skip to content

Commit

Permalink
Merge pull request #289 from pdbjjens/master
Browse files Browse the repository at this point in the history
Add: myvbus.js detector & vbus.js method
  • Loading branch information
GermanBluefox authored Sep 25, 2023
2 parents 243abc5 + 46bc425 commit 74be51c
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ For more details and for information how to disable the error reporting see [Sen
- FireTV
- Fritzdect
- Fronius
- Frontier_silicon
- G-Homa plugs
- Harmony
- Heos
Expand Down Expand Up @@ -72,6 +73,7 @@ For more details and for information how to disable the error reporting see [Sen
- Musiccast
- myDlink
- Mysensors USB/Serial (9600, 38400, 57600, 115200)
- myvbus
- nanoleaf Light Panels / Canvas
- Net Tools
- Nuki2
Expand All @@ -84,6 +86,7 @@ For more details and for information how to disable the error reporting see [Sen
- Proxmox
- RFLink (Serial 57600baud)
- SamsungTV
- Sma-em
- Smappee
- Solarlog
- Sonnen
Expand All @@ -103,6 +106,7 @@ For more details and for information how to disable the error reporting see [Sen
- Z-wave USB (Tested with Aeon Labs)

### Offered as additional adapters

- Cloud
- History (if no SQL or InfluxDB found)
- IoT
Expand All @@ -114,12 +118,13 @@ For more details and for information how to disable the error reporting see [Sen
- Web

## If the adapter can not find IPs ...
The adapter pings the network of the IP of the current host (x.y.z.1..255). Additionally, UPnP and mDNS are used to detect IPs.

The adapter pings the network of the IP of the current host (x.y.z.1..255). Additionally, UPnP and mDNS are used to detect IPs.
If not all IPs are found then please check that the iobroker user can execute `/bin/ping`.
You can execute `sudo setcap cap_net_raw+p /bin/ping` to add missing capabilities/permissions.

## Todo

- artnet? (Bluefox)
- B-Control-Em? (Bluefox)
- cul / maxcul (Bluefox)
Expand Down
77 changes: 77 additions & 0 deletions lib/adapters/myvbus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

const tools = require('../tools.js');


//const port80 = ':80';
const port3000 = ':3000';

const debug = false;

function parseDeviceInformation(string) {
const result = {};

const re = /([\w]+)[\s]*=[\s]*"([^"\r\n]*)"/g;

let md;
while ((md = re.exec(string)) !== null) {
result [md [1]] = md [2];
}

return result;
}


function detect(ip, device, options, callback) {
if (device._source !== 'RESOL VBus') return callback(null, false, ip);
if (debug) options.log.debug(`Start detecting VBus device information on ${ip}...`);

const port = port3000;

const devInfoURL = 'http://' + ip + port + '/cgi-bin/get_resol_device_information';

if (debug) options.log.debug(`Device Information URL ${devInfoURL}`);

tools.httpGet(devInfoURL, 2000, (err, data) => {
//if (debug) options.log.debug(`Device Information of ${ip} ` + data);
const devInfo = parseDeviceInformation(data);
if (debug) options.log.debug(`Parsed Device Information of ${ip} ` + JSON.stringify(devInfo));
if (!err && data && devInfo) {

let instance = tools.findInstance (options, 'myvbus', obj => obj.native.connectionIdentifier === ip);
if (!instance) {
const name = device._name ? devInfo.name ? devInfo.name : device._name : '';
device._name = name;
let deviceType = 'lan';
if (devInfo.product === 'DL2' || devInfo.product === 'KM2') {
deviceType = 'dl2';
} else if (devInfo.product === 'DL3') {
deviceType = 'dl3';
}
//if (debug) options.log.debug(`Device ` + name + ' ' + JSON.stringify(device));

instance = {
_id: tools.getNextInstanceID ('myvbus', options),
common: {
name: 'myvbus',
title: 'RESOL Device (' + ip + (name ? (' - ' + name) : '') + ')'
},
native: {
connectionIdentifier: ip,
connectionDevice: deviceType,
vbusPassword: 'vbus'
},
comment: {
add: [`${devInfo.vendor} ${name} (${ip})`]
}
};
options.newInstances.push (instance);
return callback (null, true, ip);
}
}
callback(null, false, ip);
});
}

exports.detect = detect;
exports.type = ['vbus'];
77 changes: 77 additions & 0 deletions lib/adapters/resol.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

const tools = require('../tools.js');


//const port80 = ':80';
const port3000 = ':3000';

const debug = false;

function parseDeviceInformation(string) {
const result = {};

const re = /([\w]+)[\s]*=[\s]*"([^"\r\n]*)"/g;

let md;
while ((md = re.exec(string)) !== null) {
result [md [1]] = md [2];
}

return result;
}


function detect(ip, device, options, callback) {
if (device._source !== 'RESOL VBus') return callback(null, false, ip);
if (debug) options.log.debug(`Start detecting VBus device information on ${ip}...`);

const port = port3000;

const devInfoURL = 'http://' + ip + port + '/cgi-bin/get_resol_device_information';

if (debug) options.log.debug(`Device Information URL ${devInfoURL}`);

tools.httpGet(devInfoURL, 2000, (err, data) => {
//if (debug) options.log.debug(`Device Information of ${ip} ` + data);
const devInfo = parseDeviceInformation(data);
if (debug) options.log.debug(`Parsed Device Information of ${ip} ` + JSON.stringify(devInfo));
if (!err && data && devInfo) {

let instance = tools.findInstance (options, 'resol', obj => obj.native.connectionIdentifier === ip);
if (!instance) {
const name = device._name ? devInfo.name ? devInfo.name : device._name : '';
device._name = name;
let deviceType = 'lan';
if (devInfo.product === 'DL2' || devInfo.product === 'KM2') {
deviceType = 'dl2';
} else if (devInfo.product === 'DL3') {
deviceType = 'dl3';
}
//if (debug) options.log.debug(`Device ` + name + ' ' + JSON.stringify(device));

instance = {
_id: tools.getNextInstanceID ('resol', options),
common: {
name: 'resol',
title: 'RESOL Device (' + ip + (name ? (' - ' + name) : '') + ')'
},
native: {
connectionIdentifier: ip,
connectionDevice: deviceType,
vbusPassword: 'vbus'
},
comment: {
add: [`${devInfo.vendor} ${name} (${ip})`]
}
};
options.newInstances.push (instance);
return callback (null, true, ip);
}
}
callback(null, false, ip);
});
}

exports.detect = detect;
exports.type = ['vbus'];
74 changes: 74 additions & 0 deletions lib/methods/vbus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Detects RESOL devices which support the VBus discovery protocol
* e.g. DL2, DL3, KM2, VBus/LAN
*/

// The results are devices of the form
// {
// _addr: device_ip
// _name: 'RESOL VBus'
// }
// }
//
// the type of this discovery module is
// type: 'vbus'
// To identify the adapter which handles the device, dedicated detector modules are required.
//

'use strict';

//const tools = require('../tools.js');
const dgram = require('dgram');

const bcastAddress = '255.255.255.255';
const bcastPort = 7053;
const queryString = '---RESOL-BROADCAST-QUERY---';
const replyString = '---RESOL-BROADCAST-REPLY---';
const debug = false;

function discover(self) {

debug && self.adapter.log.debug('Discovering VBus devices...');

const socket = dgram.createSocket({type: 'udp4', reuseAddr: true});

const addressList = [];

socket.on('message', (msg, rinfo) => {
if ((rinfo.family === 'IPv4') && (rinfo.port === 7053) && (msg.length >= replyString.length)) {
const msgString = msg.slice(0, replyString.length).toString();
if (msgString === replyString) {
const { address } = rinfo;
if (addressList.indexOf(address) < 0) {
addressList.push(address);
debug && self.adapter.log.debug(`VBus Device with IP ${rinfo.address} discovered...`);
}
}
}
});

socket.bind(0, () => {
socket.setBroadcast(true);
const queryBuffer = Buffer.from(queryString);
socket.send(queryBuffer, 0, queryBuffer.length, bcastPort, bcastAddress);
debug && self.adapter.log.debug(`Send discovery request: ${queryString}`);
});

setTimeout(() => {
socket.close();
for (const address of addressList) {
self.addDevice({
_addr: address,
_name: 'RESOL VBus Device',
});
}
self.done();
}, self.timeout);
}

module.exports = {
browse: discover,
type: 'vbus',
source: 'RESOL VBus',
timeout: 1500
};

0 comments on commit 74be51c

Please sign in to comment.