Force redundancy Failover via scripting

Hello,

I am trying to create a button in Vision to force a redundancy fail over. I intend it to work like the button in the gateway webpage.

I have found this post:

and also I have found this on Ignition Exchange which use the same lines of code:

But the code doesn't work for me. when I launch the function via script console, I receive an error.
Either this one:

Traceback (most recent call last):
File "<input>", line 1, in
File "<module:diagnostics>", line 33, in requestFailover
ImportError: cannot import name IgnitionGateway

Or this one:

Traceback (most recent call last):
File "<input>", line 1, in
File "<module:diagnostics>", line 33, in requestFailover
ImportError: No module named redundancy

Depending on which import come first.

Any idea why?

Best regards

Those names are only available in gateway scope. You cannot run them from the designer or from a vision client. Use a gateway message handler.

Ok, I understand why it doesn't work from console.

In the Ignition Exchange project. The function is called like that:

def runAction(self, event):
import diagnostics
diagnostics.requestFailover()

In my case, this seems to do nothing...
Any idea why?

Look for errors in your gateway log relating to that diagnostics script.

I see nothing in the Gateway Logs.
Btw, I don't know how to filter/search for script error in the logs.

I would like to add, that if I add a print() in the function, it is not displayed in the log... my guess is the log may not be configured correctly.

I don't know why, Everything about logs is default configuration, I have changed nothing voluntarily.

Print would never show in the gateway web interface's logs. If executed in gateway scope, a print may show up in the wrapper log. But Vision client scripts would print to the vision client's diagnostic console, not the gateway, because they aren't gateway scope. These scripts will never work directly in a Vision button. You need to send a message to a gateway message handler and have that handler execute these operations.

OK, thank you.

Now, my button send a message to the gateway who execute the script and it works.

Now, I am wondering, how and if the Exchange project works...

Does it offer this function in Vision? It is marked as Maker-compatible, so it must use Perspective. Perspective scripts run in gateway scope.

It does use Perspective. So that's why.

Thanks a lot for all !