How to access the getAvailableConnections() method from com.inductiveautomation.ignition.gateway.gan using the script console ?
When I try this
“from com.inductiveautomation.ignition.gateway import gan” I get the following error
Traceback (most recent call last):
File “”, line 1, in
ImportError: cannot import name gan
Also if I manually import the Java classes with a custom module,
I get “getAvailableConnections(): expected 1 args; got 0” when I run
[print GatewayNetworkManager.getAvailableConnections()] from the script console.
If you want to accept all incoming connections automatically it would be easier to just set the Connection Policy setting for the gateway network to “Unrestricted” instead of “ApprovedOnly”.
Kevin,
I have created a module based on the ignition-scripting-function sdk where I am trying to read the Incoming connection Id and output it to the logger but I am not sure how or from where I can call this method? What’s the correct way to read the output of a method that is available only in the gateway scope?
GatewayScriptModule
package com.inductiveautomation.ignition.examples.scripting;
import com.inductiveautomation.ignition.gateway.gan.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GatewayScriptModule extends AbstractScriptModule {
private final Logger logger = LoggerFactory.getLogger("GAN");
@Override
protected int multiplyImpl(int arg0, int arg1) {
return arg0 * arg1;
}
public long connId(){
long conn = new IncomingConnection().getId();
if ((System.currentTimeMillis() / 1000)%10 == 0){
String s =String.valueOf(conn);
logger.info(s);}
return conn;
}
}
GatewayModuleHook
package com.inductiveautomation.ignition.examples.scripting;
import com.inductiveautomation.ignition.common.licensing.LicenseState;
import com.inductiveautomation.ignition.common.script.ScriptManager;
import com.inductiveautomation.ignition.common.script.hints.PropertiesFileDocProvider;
import com.inductiveautomation.ignition.gateway.clientcomm.ClientReqSession;
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GatewayHook extends AbstractGatewayModuleHook {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final GatewayScriptModule scriptModule = new GatewayScriptModule();
@Override
public void setup(GatewayContext gatewayContext) {
logger.info("setup()");
}
@Override
public void startup(LicenseState licenseState) {
logger.info("startup()");
}
@Override
public void shutdown() {
logger.info("shutdown()");
}
@Override
public void initializeScriptManager(ScriptManager manager) {
super.initializeScriptManager(manager);
manager.addScriptModule(
"system.example",
scriptModule,
new PropertiesFileDocProvider());
}
@Override
public Object getRPCHandler(ClientReqSession session, String projectName) {
return scriptModule;
}
}
@pturmel Thank you for your response. I am still new to Ignition’s SDK development and Java and I can’t seem to figure out why you redirected me to that post. Please correct me if I am wrong but my understanding of the RPC is to serve as a connection between the Designer/Client and the Gateway but since I am running only in the Gateway scope, I am not sure if the RPC is the problem in my instance.
Also when I try to call the connId() method and output it’s contents to the logger, I get the following error
Error running action 'dom.onClick' on yt@D/root/Button: Traceback (most recent call last): File "<function:runAction>", line 2, in runAction at simpleorm.dataset.SFieldScalar.getRawFieldValue(SFieldScalar.java:132) at simpleorm.dataset.SRecordInstance.getObject(SRecordInstance.java:228) at simpleorm.dataset.SRecordInstance.getLong(SRecordInstance.java:456) at com.inductiveautomation.ignition.gateway.gan.IncomingConnection.getId(IncomingConnection.java:35) at com.inductiveautomation.ignition.examples.scripting.GatewayScriptModule.connId(GatewayScriptModule.java:16) 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) simpleorm.utils.SException$Error: simpleorm.utils.SException$Error: Cannot get unretrieved/unset field [IncomingConnection ].[F IncomingConnection.wsincomingconnection_ID]
Aside from any other issues, what you’re ultimately trying to do won’t work as-is. You can’t just create a new instance of com.inductiveautomation.ignition.gateway.gan.IncomingConnection and expect things to work.
You need to ask the PersistenceInterface (available from the GatewayContext you get in setup) for existing IncomingConnection records. But even if you get them, I’m not sure just blindly setting the security status (if that’s what you’re ultimately trying to do) will actually do anything.
The incoming connection is the session, which is available in the gateway hook when the RPC subsystem looks up your script module. But the sample code doesn’t make unique RPC handlers per session, so that information is lost. You are creating a new connection object in your code, but that would have no bearing on the caller of your script.
Oh, and the script console is not in gateway scope. It is in designer scope, which is much like vision client scope.
@pturmel and @PGriffith , thank you for your response, My ultimate goal is to have the remote certificates for Incoming GAN connection be approved without manual intervention. What’s your recommendation on trying to implement this? Can you point me in the right direction.
Also, I don’t see the Incoming Remote certificates for GAN in the internal db?
@pturmel is calling the method via button in perspective session considered a gateway scope?