Skip to content

Commit

Permalink
Attempted fix for ping
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Mar 23, 2018
1 parent 08eda11 commit 9af8a79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
20 changes: 11 additions & 9 deletions helpers/getDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ const startPing = (device) => {
device.state = 'unknown';

setInterval(() => {
ping.sys.probe(device.host.address, (active) => {
if (!active && device.state === 'active') {
console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) is no longer reachable.`);
try {
ping.sys.probe(device.host.address, (active) => {
if (!active && device.state === 'active') {
console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) is no longer reachable.`);

device.state = 'inactive';
} else if (active && device.state !== 'active') {
if (device.state === 'inactive') console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) has been re-discovered.`);
device.state = 'inactive';
} else if (active && device.state !== 'active') {
if (device.state === 'inactive') console.log(`Broadlink RM device at ${device.host.address} (${device.host.macAddress || ''}) has been re-discovered.`);

device.state = 'active';
}
})
device.state = 'active';
}
})
} catch (err) {}
}, pingFrequency);
}

Expand Down
10 changes: 7 additions & 3 deletions helpers/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ const ping = require('ping');

const pingIPAddress = (ipAddress, interval, callback) => {
setInterval(() => {
ping.sys.probe(ipAddress, (isActive) => {
callback(isActive)
})
try {
ping.sys.probe(ipAddress, (isActive) => {
callback(isActive)
})
} catch (err) {
callback(false)
}
}, interval * 1000);
}

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1657,9 +1657,9 @@ home-or-tmp@^2.0.0:
os-homedir "^1.0.0"
os-tmpdir "^1.0.1"

homebridge-platform-helper@1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/homebridge-platform-helper/-/homebridge-platform-helper-1.0.7.tgz#014f53984a776573faa8cde6e34374e9ee460e63"
homebridge-platform-helper@1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/homebridge-platform-helper/-/homebridge-platform-helper-1.0.8.tgz#42aa99d1d7a9e613614115a1855fde48ff320dcf"
dependencies:
node-persist "^2.0.10"
semver "^5.3.0"
Expand Down

0 comments on commit 9af8a79

Please sign in to comment.