pythonopc-uaconnectivityopc

How to form an OPCUA connection in python from server IP address, port, security policy and credentials?


I have never used OPC-UA before, but now faced with a task where I have to pull data from a OPC-UA machine to push to a SQL database using python. I can handle the database part, but how to basically connect to the OPCUA server when I have only the following fields available?

Some tutorials I saw directly use a url, but is there any way to form the URL from these parameters, or should I ask the machine owners something more specific to be able to connect? I just want to be sure of what I need before I approach him.

Related, how to use the same parameters in the application called UA-Expert to verify the connections as well? Is it possible?

If it is relevant, I am using python 3.10 on Ubuntu 22.04.


Solution

  • You need to know which protocol is used. Then you can create the URLs by using the IP address as domain:

    In your example this could be opc.tcp://192.168.38.94:8080 or https://192.168.38.94:8080

    In most cases, the binary protocol is used. But the port 8080 is a typical http(s) port. The credential and the securityPolice are needed later in the connection process.

    And yes: You can test the URLs with the UaExpert. You can finde a step-by-step tutorial in the documention