3

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?

  • IP address 192.168.38.94
  • Port 8080
  • Security policy: Basic256
  • Username: della_client
  • Password: amorphous@#

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.

Della
  • 1,264
  • 2
  • 15
  • 32

1 Answers1

1

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

  • OPC UA binary: opc.tcp://ip:port
  • https https://ip:port
  • OPC UA WebSockets opc.wss://ip:port
  • http http://ip:port (Deprecated in Version 1.03)

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

SFriedl
  • 195
  • 10
  • 1
    Thanks a lot. I found out the machine uses OPC UA binary and the port number is actually 4840. So protocol wise, the first option is correct. But how to connect to the machine using opcua python library, particularly, which methods to call to supply the user id and password for basic256 authentication? Any code snippet available? The documentation does not seem helpful in this. – Della Feb 17 '23 at 08:22
  • 1
    Yes here is an example: https://github.com/FreeOpcUa/opcua-asyncio/blob/master/examples/client-minimal-auth.py – SFriedl Feb 17 '23 at 08:45