From bdd42c323cafb4ac054ce902c77d4a39bfe5c425 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 19:30:41 +0100 Subject: add icmp timeout support --- htdocs/webiopi.js | 9 +++++---- python/webiopi/devices/sensor/icmp.py | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/htdocs/webiopi.js b/htdocs/webiopi.js index 04029d7..f893618 100644 --- a/htdocs/webiopi.js +++ b/htdocs/webiopi.js @@ -1361,7 +1361,7 @@ Duration.prototype.toString = function() { return this.name + ": Duration"; } -Duration.prototype.getMillimeter = function(callback) { +Duration.prototype.getMilliseconds = function(callback) { $.get(this.url + "/duration/ms", function(data) { callback(this.name, data); }); @@ -1376,11 +1376,12 @@ Duration.prototype.refreshUI = function() { element.append(element.header); } - this.getMillimeter(function(name, data){ + this.getMilliseconds(function(name, data){ if (element != undefined) { - element.header.text(dist + ": " + data + "ms"); + var text = (data > 0) ? data + "ms" : "Timeout"; + element.header.text(dist + ": " + text); } - setTimeout(function(){dist.refreshUI()}, dist.refreshTime); + setTimeout(function() { dist.refreshUI() }, dist.refreshTime); }); } diff --git a/python/webiopi/devices/sensor/icmp.py b/python/webiopi/devices/sensor/icmp.py index 8a4065d..37028fa 100644 --- a/python/webiopi/devices/sensor/icmp.py +++ b/python/webiopi/devices/sensor/icmp.py @@ -36,7 +36,8 @@ class ICMP(Duration): return Duration.__family__(self) def __getMilliseconds__(self): - return self.echo(self.ip, 1) * 1000 + sec = self.echo(self.ip, 1) + return sec * 1000 if sec > 0 else -1 def close(self): pass @@ -79,7 +80,7 @@ class ICMP(Duration): while True: ready = select.select([sock], [], [], timeout) if ready[0] == []: # Timeout - return + return -1 time_received = time() rec_packet, addr = sock.recvfrom(1024) @@ -91,7 +92,7 @@ class ICMP(Duration): timeout -= time_received - time_sent if timeout <= 0: - return + return -1 def echo(self, dest_addr, timeout=1): """ -- cgit v1.2.3