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:
parent
fb78085d4c
commit
2f07bb7d13
@ -29,14 +29,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
|
||||||
<script type="text/x-red" data-help-name="ping">
|
<script type="text/x-red" data-help-name="ping">
|
||||||
<p>Pings a machine and returns the trip time in mS.</p>
|
<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>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>
|
<p>Default ping is every 20 seconds but can be configured.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('ping',{
|
RED.nodes.registerType('ping',{
|
||||||
category: 'advanced-input',
|
category: 'advanced-input',
|
||||||
|
@ -30,12 +30,12 @@ function PingNode(n) {
|
|||||||
else if (plat.match(/^win/)) ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]);
|
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 if (plat == "darwin") ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]);
|
||||||
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
|
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
|
||||||
var res = "";
|
var res = false;
|
||||||
ex.stdout.on('data', function (data) {
|
ex.stdout.on('data', function (data) {
|
||||||
//console.log('[ping] stdout: ' + data.toString());
|
//console.log('[ping] stdout: ' + data.toString());
|
||||||
var regex = /time.(.*)ms/;
|
var regex = /from.*time.(.*)ms/;
|
||||||
var m = regex.exec(data.toString())||[""];
|
var m = regex.exec(data.toString())||"";
|
||||||
res = Number(m[1]);
|
if (m != '') { res = Number(m[1]); }
|
||||||
});
|
});
|
||||||
ex.stderr.on('data', function (data) {
|
ex.stderr.on('data', function (data) {
|
||||||
//console.log('[ping] stderr: ' + data);
|
//console.log('[ping] stderr: ' + data);
|
||||||
|
Loading…
Reference in New Issue
Block a user