Ping and IP by expression

Is there a way to ping an address with an expression? I have a few WAPs that I ould like to ping and get a boolean back.

There are a few ping utilities in the Ignition Exchange. Here's one:

cool ill check it out

So i downloaded the view and it works great. I want to go a tag route and downloaded/imported a udt:

When I try and use it i get an error saying it cannot execute the expression runScript("NetworkAnalysis.ping")

The script exists in the Scripting of the project:

image

I was curious if any suggestions on this?

scripts executed in a Tag Expression runScript() must be located in the Gateway Scripting Project. If you have a Gateway Scripting Project then you should put the script there. If you don't already have one then you should configure one.

1 Like

I see. Yes we do I just found it. That took care of it. thank you sir.

I've just response to your email with the same tips as @lrose give you.

Just as feedback, was it not clear enough in the installation steps on the exchange ressource? How can i made more clear for the next person using it?

Regards

That same email you sent me really cleared things up. The pics were most helpful. It's a great udt!

Oy! Someone share the pics.

I didn't mention the name of the Exchange project. To help with search indexing here it is.

Network Device Status By: Bao Nguyen.

Here they are:

image003.png

I see lots of posts saying "don't use runScript!" from years ago, but this project uses it. Does that rule still apply? Or is there a more preferred way to use ping to monitor device status than in a fixed rate runScript from tags (Perspective)

Don't use runScript() for this kind of task, particularly not in expression tags. If you need to monitor a list of target devices, use a timer event and write the results to memory tag(s).

Consider using java's built-in "ping" support via InetAddress.isReachable(). (On linux, this requires CAP_NET_RAW.)

1 Like

Thanks for confirming. The script does use the Java ping but it’s invoked by runscript. I’ll create a timer script instead so it’s also in one place.
I did notice the runscript will write to the tags even with comms off, convenient but potentially dangerous, but good for testing. Is there a way to have comms off as a global but allow certain tags to be written?

Comms control is a designer-specific function, not available nor meaningful in gateway scope.

Ah, yes, understood, thanks

I have a problem when evaluating an IP address.
I get Error_ExpressionEval in the expression tag of isConnected. Do you have any idea why this error appears?
The IP address I’m pointing to is a valid one.

1 Like

Is your project defined as the gateway scripting project in the gateway settings?

1 Like
  1. move the import outside the def, so it only happens once.
  2. Java's .isReachable() method requires CAP_NET_RAW in Linux, which is normally not available to non-root service users. You get a permissions error if not set as an extra permission in your service (SystemD). I'm not sure about Windows.

You should test your function outside of runScript (but still in gateway scope) to be sure it works that way.