Skip to content

Commit 511fcd9

Browse files
committed
(bluefox) add s7 adapter
(bluefox) calculate mac on linux
1 parent fa843dd commit 511fcd9

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

conf/sources-dist.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
"meta": "https://raw.githubusercontent.com/ioBroker/ioBroker.ping/master/io-package.json",
8686
"icon": "https://raw.githubusercontent.com/ioBroker/ioBroker.ping/master/admin/ping.png"
8787
},
88+
"s7": {
89+
"meta": "https://raw.githubusercontent.com/ioBroker/ioBroker.s7/master/io-package.json",
90+
"icon": "https://raw.githubusercontent.com/ioBroker/ioBroker.s7/master/admin/S7.png"
91+
},
8892
"sayit": {
8993
"meta": "https://raw.githubusercontent.com/ioBroker/ioBroker.sayit/master/io-package.json",
9094
"icon": "https://raw.githubusercontent.com/ioBroker/ioBroker.sayit/master/admin/sayit.png"

lib/setup.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,18 +2790,20 @@ function dbSetup(iopkg, callback) {
27902790
if (!err && res && res.native && res.native.uuid) {
27912791
if (!(--tasks)) setupReady(callback);
27922792
} else {
2793-
objects.setObject('system.meta.uuid', {
2794-
type: 'meta',
2795-
common: {
2796-
name: 'uuid',
2797-
type: 'uuid'
2798-
},
2799-
native: {
2800-
uuid: uuid(true)
2801-
}
2802-
}, function () {
2803-
console.log('object system.meta.uuid created');
2804-
if (!(--tasks)) setupReady(callback);
2793+
uuid(function(res) {
2794+
objects.setObject('system.meta.uuid', {
2795+
type: 'meta',
2796+
common: {
2797+
name: 'uuid',
2798+
type: 'uuid'
2799+
},
2800+
native: {
2801+
uuid: res
2802+
}
2803+
}, function () {
2804+
console.log('object system.meta.uuid created');
2805+
if (!(--tasks)) setupReady(callback);
2806+
});
28052807
});
28062808
}
28072809
});
@@ -2814,11 +2816,45 @@ function dbSetup(iopkg, callback) {
28142816
}
28152817
}
28162818

2819+
function getMac(callback) {
2820+
var exec = require('child_process').exec;
2821+
var macRegex = /(?:[a-z0-9]{2}[:\-]){5}[a-z0-9]{2}/ig;
2822+
var zeroRegex = /(?:[0]{2}[:\-]){5}[0]{2}/;
2823+
var command = (process.platform.indexOf('win') === 0) ? "getmac" : "ifconfig || ip link";
2824+
2825+
require('child_process').exec(command, function(err, stdout, stderr) {
2826+
if (err) {
2827+
callback(err);
2828+
} else {
2829+
var macAddress;
2830+
var match;
2831+
var result = null;
2832+
2833+
while (match = macRegex.exec(stdout)) {
2834+
macAddress = match[0];
2835+
if (!zeroRegex.test(macAddress) && !result) result = macAddress;
2836+
}
2837+
2838+
if (result === null) {
2839+
callback(new Error('could not determine the mac address from:\n' + data));
2840+
} else {
2841+
callback(null, result.replace(/-/g, ':').toLowerCase());
2842+
}
2843+
}
2844+
});
2845+
}
2846+
28172847
// Build unique uuid based on MAC address if possible
2818-
function uuid(isMac) {
2819-
var mac = '';
2848+
function uuid(givenMac, callback) {
2849+
if (typeof givenMac == 'function') {
2850+
callback = givenMac;
2851+
givenMac = '';
2852+
}
2853+
2854+
var mac = (givenMac !== null) ? (givenMac || '') : null;
28202855
var u;
2821-
if (isMac) {
2856+
2857+
if (mac === '') {
28222858
var ifaces = require('os').networkInterfaces();
28232859

28242860
// Find first not empty MAC
@@ -2832,6 +2868,14 @@ function uuid(isMac) {
28322868
if (mac) break;
28332869
}
28342870
}
2871+
2872+
if (mac === '') {
2873+
getMac(function(err, mac) {
2874+
uuid(mac || null, callback);
2875+
});
2876+
return;
2877+
}
2878+
28352879
if (mac) {
28362880
var md5sum = require('crypto').createHash('md5');
28372881
md5sum.update(mac);
@@ -2848,5 +2892,5 @@ function uuid(isMac) {
28482892
u = b;
28492893
}
28502894

2851-
return u;
2852-
}
2895+
callback(u);
2896+
}

0 commit comments

Comments
 (0)