Code Monkey home page Code Monkey logo

Comments (18)

dceejay avatar dceejay commented on May 29, 2024

That is the return code from calling ping... 0 = success.
The result is passed in the message as msg.payload which should be visible if you connect a debug node directly to the ping node.

Example flow..
[{"id":"415d9e6a.6894","type":"debug","name":"","active":true,"complete":false,"x":296.16667556762695,"y":102.1666841506958,"z":"f8cf4ab6.9daa1","wires":[]},{"id":"ac259a1.ab60968","type":"ping","name":"","host":"github.com","timer":"20","x":131.16667938232422,"y":101.16668510437012,"z":"f8cf4ab6.9daa1","wires":[["415d9e6a.6894"]]}]

If that still fails can you post your flow please.
(If you want to see the actual result in the console instead add a line in 88-ping.js
before line 47
console.log(msg);
node.send(msg);

for example I get - { payload: 117, topic: 'github.com' }
where 117 = 117mS

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

I believe I was also seeing msg.payload set to zero as well. I'll check and post debug flows when I can get back to my setup.

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

I have pasted in the flow you recommended, and added the debug output to the js file. I am still seeing zeroes:

[ping] stdout: PING github.com (192.30.252.129) 56(84) bytes of data.
64 bytes from 192.30.252.129: icmp_req=1 ttl=50 time=105 ms

[ping] stdout:
--- github.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 105.634/105.634/105.634/0.000 ms

[ping] result: 0
{ payload: 0, topic: 'github.com' }

I notice there is text saying "time 0ms", above the line that lists the rtt statistics. Could that be the source of the confusion?

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

I left it running, and noticed one non-zero value in a load of zeroes. Flow and debug is as before.

[ping] stdout: PING github.com (192.30.252.129) 56(84) bytes of data.
64 bytes from 192.30.252.129: icmp_req=1 ttl=50 time=95.4 ms

--- github.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 95.432/95.432/95.432/0.000 ms

[ping] result: 0
{ payload: 95.4, topic: 'github.com' }

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

Aha - yes - the "easy" fix should be to change line 36 to be
var regex = /from.time.(.)ms/;
Can you try that and report back ? Thanks

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

I tried the proposed regex line, but got NaN this time:

[ping] stdout: PING github.com (192.30.252.130) 56(84) bytes of data.
64 bytes from 192.30.252.130: icmp_req=1 ttl=51 time=98.9 ms

[ping] stdout:
--- github.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 98.974/98.974/98.974/0.000 ms

[ping] result: 0
{ payload: NaN, topic: 'github.com' }

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

Is there a way to see GitHub raw text rather than the formatted version? Has the mark-down hidden some of the regex line - it looks oddly formatted? I may have used the wrong regex in that case...!

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

DOH...... yes is has... sorry - was typing on a train... should have spotted that as it wasn't going anywhere fast....

 var regex = /from.*time.(.*)ms/; 

we are adding in from.* to the front of the existing regex.

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

Still NaN, even with the corrected regex.

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

OK - final piece of remote debug...
can you add a line after line 37 - var m = ...
console.log(m);

and paste the resulting output. Thanks.
(I won't have access to my Pi until later tomorrow so apologies for using you as a guinea pig)

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

OK, done that.

[ping] stdout: PING github.com (192.30.252.131) 56(84) bytes of data.
64 bytes from 192.30.252.131: icmp_req=1 ttl=49 time=104 ms

[ 'from 192.30.252.131: icmp_req=1 ttl=49 time=104 ms',
  '104 ',
  index: 64,
  input: 'PING github.com (192.30.252.131) 56(84) bytes of data.\n64 bytes from 192.30.252.131: icmp_req=1 ttl=49 time=104 ms\n' ]
[ping] stdout:
--- github.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 104.830/104.830/104.830/0.000 ms

[ '' ]
[ping] result: 0
{ payload: NaN, topic: 'github.com' }

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

Correct - am having a bad day... commuting to London...
how about lines 37 38..... :-)

 var m = regex.exec(data.toString())||"";
 if (m != '') { res = Number(m[1]); } 

so it only sets it if a valid parse.

from node-red-nodes.

alanbowman avatar alanbowman commented on May 29, 2024

That looks like it's doing the right thing now. I'm consistently getting the ping times in the msg.payload.

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

OK great - I'll push the fix - but please let us know if it misbehaves.
Many thanks for your help and patience.

from node-red-nodes.

andypiper avatar andypiper commented on May 29, 2024

Hmm... and there was me patching something similar a few weeks ago :-)

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

Now he tells us :-)
share and share again.

from node-red-nodes.

andypiper avatar andypiper commented on May 29, 2024

cough #18 - admittedly this might not have closed this too, but it was based on the same symptom originally.

from node-red-nodes.

dceejay avatar dceejay commented on May 29, 2024

Hello old friend ! so it is/was.... hopefully nailed this time.

from node-red-nodes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.