1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Fix ping error response on Pi - Fixes Issue #23

This commit is contained in:
Dave C-J 2014-02-05 18:36:29 +00:00
parent fb78085d4c
commit 2f07bb7d13
2 changed files with 4 additions and 6 deletions

View File

@ -29,14 +29,12 @@
</div>
</script>
<!-- Next, some simple help text is provided for the node. -->
<script type="text/x-red" data-help-name="ping">
<p>Pings a machine and returns the trip time in mS.</p>
<p>Returns <b>false</b> if no response received within 3 seconds, or if the host is unresolveable.</p>
<p>Default ping is every 20 seconds but can be configured.</p>
</script>
<!-- Finally, the node type is registered along with all of its properties -->
<script type="text/javascript">
RED.nodes.registerType('ping',{
category: 'advanced-input',

View File

@ -30,12 +30,12 @@ function PingNode(n) {
else if (plat.match(/^win/)) ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]);
else if (plat == "darwin") ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]);
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
var res = "";
var res = false;
ex.stdout.on('data', function (data) {
//console.log('[ping] stdout: ' + data.toString());
var regex = /time.(.*)ms/;
var m = regex.exec(data.toString())||[""];
res = Number(m[1]);
var regex = /from.*time.(.*)ms/;
var m = regex.exec(data.toString())||"";
if (m != '') { res = Number(m[1]); }
});
ex.stderr.on('data', function (data) {
//console.log('[ping] stderr: ' + data);