summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--htdocs/webiopi.js9
-rw-r--r--python/webiopi/devices/sensor/icmp.py7
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() {
1361 return this.name + ": Duration"; 1361 return this.name + ": Duration";
1362} 1362}
1363 1363
1364Duration.prototype.getMillimeter = function(callback) { 1364Duration.prototype.getMilliseconds = function(callback) {
1365 $.get(this.url + "/duration/ms", function(data) { 1365 $.get(this.url + "/duration/ms", function(data) {
1366 callback(this.name, data); 1366 callback(this.name, data);
1367 }); 1367 });
@@ -1376,11 +1376,12 @@ Duration.prototype.refreshUI = function() {
1376 element.append(element.header); 1376 element.append(element.header);
1377 } 1377 }
1378 1378
1379 this.getMillimeter(function(name, data){ 1379 this.getMilliseconds(function(name, data){
1380 if (element != undefined) { 1380 if (element != undefined) {
1381 element.header.text(dist + ": " + data + "ms"); 1381 var text = (data > 0) ? data + "ms" : "Timeout";
1382 element.header.text(dist + ": " + text);
1382 } 1383 }
1383 setTimeout(function(){dist.refreshUI()}, dist.refreshTime); 1384 setTimeout(function() { dist.refreshUI() }, dist.refreshTime);
1384 }); 1385 });
1385} 1386}
1386 1387
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):
36 return Duration.__family__(self) 36 return Duration.__family__(self)
37 37
38 def __getMilliseconds__(self): 38 def __getMilliseconds__(self):
39 return self.echo(self.ip, 1) * 1000 39 sec = self.echo(self.ip, 1)
40 return sec * 1000 if sec > 0 else -1
40 41
41 def close(self): 42 def close(self):
42 pass 43 pass
@@ -79,7 +80,7 @@ class ICMP(Duration):
79 while True: 80 while True:
80 ready = select.select([sock], [], [], timeout) 81 ready = select.select([sock], [], [], timeout)
81 if ready[0] == []: # Timeout 82 if ready[0] == []: # Timeout
82 return 83 return -1
83 84
84 time_received = time() 85 time_received = time()
85 rec_packet, addr = sock.recvfrom(1024) 86 rec_packet, addr = sock.recvfrom(1024)
@@ -91,7 +92,7 @@ class ICMP(Duration):
91 92
92 timeout -= time_received - time_sent 93 timeout -= time_received - time_sent
93 if timeout <= 0: 94 if timeout <= 0:
94 return 95 return -1
95 96
96 def echo(self, dest_addr, timeout=1): 97 def echo(self, dest_addr, timeout=1):
97 """ 98 """