I've got a UDT set up to store the value and 2 timestamps from an HTTP JSON. They're all in the same JSON so I was thinking I could set up a fixed rate script on the value tag and use runScript() to read the HTTP one time and write to the 2 timestamps using the relative tag paths before returning the value. This script would live in the project library.
2 questions:
Will the runScript() have access to the relative tag paths or will I need to pass the tag path to the script?
Is there a better way to do this? (My goal is to define a UDT that uses a single script to fill in these values at a fixed rate so that another instance could be created and not require any further scripting - the url and update rate are parameters to the UDT).
Well, first things first I can't even get runScript to work - I haven't added the relative tag path writes yet. Why won't runScript work? I've tried string concat and separate args.
both throw the same "error running script" with no information why. This call works just fine from the script console. The string I'm passing for "url" is the same.
HTTP.getAzureTagPropsHTTP("url")
Is it possible that the gateway can't get out on the HTTP read since the expression tag will be in gateway scope and script console is client scope?
Yes, runScript will work with relative tag paths in an expression tag. The lexer and tag system take care of resolving the reference, and from that perspective a runScript() is no different than any other expression.
It is possible depending on your network architecture, however, I would verify that the script your executing is located in the project library of the Gateway Scripting Project, and not just the local project (If they're different). Run script will fail otherwise as you'll be making a call to a script that is unavailable in it's scope.
I have verified that it is in the gateway scripting project. I also added the function call as an every-minute scheduled task so I could see any errors in the logs. Not sure what this error means.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 2, in onScheduledEvent File "", line 19, in getAzureTagPropsHTTP at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source) at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source) at com.inductiveautomation.ignition.common.script.builtin.http.Promise.get(Promise.java:48) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.net.ConnectException
at org.python.core.Py.JavaError(Py.java:545)
at org.python.core.Py.JavaError(Py.java:536)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
at org.python.core.PyObject.__call__(PyObject.java:461)
at org.python.core.PyObject.__call__(PyObject.java:465)
at org.python.core.PyMethod.__call__(PyMethod.java:126)
at org.python.pycode._pyx2897.getAzureTagPropsHTTP$1(:35)
at org.python.pycode._pyx2897.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:134)
at org.python.core.PyFunction.__call__(PyFunction.java:416)
at org.python.pycode._pyx2896.onScheduledEvent$1(:2)
at org.python.pycode._pyx2896.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function___call__(PyFunction.java:474)
at org.python.core.PyFunction.__call__(PyFunction.java:469)
at org.python.core.PyFunction.__call__(PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:868)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:950)
at com.inductiveautomation.ignition.common.script.ScheduledScriptManager$ScheduledScriptTask.run(ScheduledScriptManager.java:184)
at com.inductiveautomation.ignition.common.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:239)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: java.net.ConnectException
... 29 common frames omitted
Caused by: java.util.concurrent.ExecutionException: java.net.ConnectException
at java.base/java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.get(Unknown Source)
at com.inductiveautomation.ignition.common.script.builtin.http.Promise.get(Promise.java:48)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
... 26 common frames omitted
Caused by: java.net.ConnectException: null
at java.net.http/jdk.internal.net.http.common.Utils.toConnectException(Unknown Source)
at java.net.http/jdk.internal.net.http.PlainHttpConnection.connectAsync(Unknown Source)
at java.net.http/jdk.internal.net.http.AsyncSSLConnection.connectAsync(Unknown Source)
at java.net.http/jdk.internal.net.http.Http2Connection.createAsync(Unknown Source)
at java.net.http/jdk.internal.net.http.Http2ClientImpl.getConnectionFor(Unknown Source)
at java.net.http/jdk.internal.net.http.ExchangeImpl.get(Unknown Source)
at java.net.http/jdk.internal.net.http.Exchange.establishExchange(Unknown Source)
at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl0(Unknown Source)
at java.net.http/jdk.internal.net.http.Exchange.responseAsyncImpl(Unknown Source)
at java.net.http/jdk.internal.net.http.Exchange.responseAsync(Unknown Source)
at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(Unknown Source)
at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsyncImpl$7(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.uniHandle(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.uniHandleStage(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.handle(Unknown Source)
at java.net.http/jdk.internal.net.http.MultiExchange.responseAsyncImpl(Unknown Source)
at java.net.http/jdk.internal.net.http.MultiExchange.lambda$responseAsync0$2(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)
at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
... 3 common frames omitted
Caused by: java.nio.channels.UnresolvedAddressException: null
at java.base/sun.nio.ch.Net.checkAddress(Unknown Source)
at java.base/sun.nio.ch.Net.checkAddress(Unknown Source)
at java.base/sun.nio.ch.SocketChannelImpl.checkRemote(Unknown Source)
at java.base/sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at java.net.http/jdk.internal.net.http.PlainHttpConnection.lambda$connectAsync$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
... 22 common frames omitted