Send tags to Agent Gateway from script

Hello,

I want to send tags from my controller to Agent when after a button clique.

I am trying to use the SDK, but i got an error.

Here is my code:

def runAction(self, event):
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.gateway.tasks import ScheduleMode
	from com.inductiveautomation.ignition.gateway.tasks import TaskSettings
	from com.inductiveautomation.ignition.gateway.tasks import GatewayTaskRecord

	gatewayContext = IgnitionGateway.get()
	taskManager = gatewayContext.getTaskManager()
	
	settings = taskManager.createNewTask("eam", "sendTags")

	record = settings.getTaskRecord()
	record.setName("Send KPI To Agent")
	record.setOwnerId("eam")
	record.setMode(ScheduleMode.OnDemand) 
	record.setTaskId("sendTags")
	record.setSchedule("ondemand")
	record.setFailData("overwrite")

	settingsRecord = settings.getTaskSettingsRecord()

	meta = settingsRecord.getMeta()

	settingsRecord.setString(meta.getField("targetGateways"), "Ignition-VM")
	settingsRecord.setString(meta.getField("targetTagProvider"), "edge")
	settingsRecord.setString(meta.getField("tagPaths"), "[default]test,")
	settingsRecord.setBoolean(meta.getField("controllerIsTarget"), False)
	settingsRecord.setString(meta.getField("collisionPolicy"), "overwrite")

	settings.save()

And the error i got is:

	Error running action 'component.onActionPerformed' on Pages/machine/settings/KPIs/addKPIForm@P-KEOuB09/root/submitRow/submit: Traceback (most recent call last): File "<function:runAction>", line 51, in runAction at simpleorm.sessionjdbc.SSessionJdbcHelper.flushExecuteUpdate(SSessionJdbcHelper.java:422) at simpleorm.sessionjdbc.SSessionJdbcHelper.flush(SSessionJdbcHelper.java:389) at simpleorm.sessionjdbc.SSessionJdbc.flush(SSessionJdbc.java:459) at simpleorm.sessionjdbc.SSessionJdbc.flush(SSessionJdbc.java:443) at simpleorm.sessionjdbc.SSessionJdbc.commitAndDetachDataSet(SSessionJdbc.java:382) at com.inductiveautomation.ignition.gateway.localdb.PersistenceInterfaceImpl.save(PersistenceInterfaceImpl.java:107) at com.inductiveautomation.ignition.gateway.tasks.TaskSettings.save(TaskSettings.java:69) at jdk.internal.reflect.GeneratedMethodAccessor391.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$Jdbc: simpleorm.utils.SException$Jdbc: Executing INSERT INTO gatewaytaskrecord (gatewaytaskrecord_ID, name, ownerid, taskid, mode, schedule, faildata) VALUES (?, ?, ?, ?, ?, ?, ?) for [GatewayTaskRecord 34 NewRecord Dirty0]

Can anyone help me ?

@PGriffith Do you have any idea ?

Nope. You're doing something totally unsupported.

Why don't you just use system.util.sendMessage across the gateway network and call system.tag.configure locally on the receiver gateway message handler?

2 Likes

Here is a slightly simpler approach.
The code below retrieves the EAMGatewayHook from the gateway context (IgnitionGateway).
Once the hook is available, we get the RPC that handles the tag transmission for us.

You just need to fill in the fields of the initSendTags method with appropriate values of the correct data type.

I didn't go all the way through, but it should work quite easily.

def sendTags():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	context = IgnitionGateway.get()
	moduleManager = context.getModuleManager()
	EAMGatewayHook = moduleManager.getModule("com.inductiveautomation.eam").getHook()
	rpc = EAMGatewayHook.getRPCHandler(None, None)
	
	rpc.initSendTags(targetProvider, agentServerIds, tags, saveTask, targetController)

Thank you @e.sagnelonge.

Yes, this method is working, i added two lines of code:

def sendTags():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

	context = IgnitionGateway.get()
	moduleManager = context.getModuleManager()
	EAMGatewayHook = moduleManager.getModule("com.inductiveautomation.eam").getHook()
	rpc = EAMGatewayHook.getRPCHandler(None, None)

	path = TagPathParser.parse("[default]test")

	rpc.initSendTags("edge", ["edge-HOST-NAME"], [path], True, False, "Overwrite") # After version 8.1.39 it is mandatory to add a sixth argument "Overwrite, Abort..."
1 Like

@PGriffith, yes this solution also works.