# Help with TCP-Ping

**URL:** https://discourse.nodered.org/t/help-with-tcp-ping/54389
**Category:** General
**Created:** [28 November 2021 05:50 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389 "2021-11-28T05:50:04Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![gregoinc](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gregoinc](https://discourse.nodered.org/u/gregoinc)
#### Post date: [28 November 2021 05:50 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/1 "2021-11-28T05:50:04Z")

</div>

Been a while since OI have posted. Have hit a bit of snag in relation to pinging a node on my network.

Originally was using the 'ping' node but couldn't workout how to ping an IP address with a non-standard port. So I have implemented tcp-ping and everything is great, except I am unsure how to use the output of tcp-ping to trigger an email.

Here's the output I receive from tcp-ping...

![tcp-ping-output](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fee39214baa1c046ebde3a8ba18048a69af8e2f.jpeg)

Previoulsy when using the 'ping' node if the ping failed it would send a 'failed' status in the msg.payload which would then trigger an email. But as you can see tcp-ping sends a number of parameters, but all I want to know is when the ping fails.

Here's the flow...

 ![tcp-ping-flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e585722c80a3fc53a3c4b2727b6e5d0cdcbaabb.jpeg)

I am thinking I need to add something to the Ping Check node, but having tried a few things, and being hopeless in json coding, here I am.

Any tips/hints greatly appreciated.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 November 2021 07:22 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/2 "2021-11-28T07:22:46Z")

</div>

From the data you show, what would you define as success and what as failure? It might be simpler if you told it to only do one ping request rather than three

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 November 2021 07:36 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/3 "2021-11-28T07:36:56Z")

</div>

Have you tried changing your Ping Check node to check if msg.payload.success == 0 ?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [28 November 2021 10:03 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/4 "2021-11-28T10:03:41Z")

</div>

Why not add a `switch` node set to check if msg.failed \> 0

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 November 2021 14:33 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/5 "2021-11-28T14:33:34Z")

</div>

> [@gregoinc](#):
>
> Originally was using the 'ping' node but couldn't workout how to ping an IP address with a non-standard port.

Of course, you cannot do a standard ICMP ping to a port since ping only hits the lowest level of the network stack - effectively the network card itself. That is why occasionally, you can get a return from a ping when the rest of the device isn't working correctly.

---

<div class="post-metadata">

### Author: ![gregoinc](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gregoinc](https://discourse.nodered.org/u/gregoinc)
#### Post date: [28 November 2021 22:43 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/6 "2021-11-28T22:43:36Z")

</div>

I tried what you suggested, and tried this config... here's the debug ping message.

![pingfailmsg](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b38838c55ce7b74f2ab4ac17f3b46dfef59969bf.jpeg)

And here's the code I placed in the switch node...

![SwitchNodePing](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/2/82c1f4509fd8895a2b90b2198c87d9a2ca2c9074.jpeg)

But it didn't appear to have any output in the debug?

---

<div class="post-metadata">

### Author: ![gregoinc](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gregoinc](https://discourse.nodered.org/u/gregoinc)
#### Post date: [28 November 2021 22:50 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/7 "2021-11-28T22:50:04Z")

</div>

Yes, that is what has been happening. The system had stopped working, but was still responding to the ping node. So that is why I wanted to ping a specific port.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [28 November 2021 23:02 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/8 "2021-11-28T23:02:55Z")

</div>

> [@jbudd](#):
>
> Have you tried changing your Ping Check node to check if msg.payload.success == 0 ?

Or if you prefer, msg.payload.failed \> 0  
(Though I think zero success is better than a non zero failure to indicate a communication problem .)

---

<div class="post-metadata">

### Author: ![gregoinc](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@gregoinc](https://discourse.nodered.org/u/gregoinc)
#### Post date: [28 November 2021 23:30 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/9 "2021-11-28T23:30:29Z")

</div>

Seems the msg.payload.success == 0 is working, so perhaps I go with that. Thank you for the advice.

The ping node is able to auto trigger every 60 seconds, but I am not sure if tcp-ping does the same? Or do I need to add an inject node to trigger the tcp-ping every 60 seconds?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [29 November 2021 00:29 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/10 "2021-11-29T00:29:44Z")

</div>

Oops, sorry about that I didn’t look closely enough at the first debug to see it was in msg.payload. Glad it is working but now you have to determine why one ping worked and the other did not.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 January 2022 00:30 UTC](https://discourse.nodered.org/t/help-with-tcp-ping/54389/11 "2022-01-28T00:30:11Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
