OPC UA (OPC Unified Architecture) is a platform-independent, service-oriented architecture that integrates the functionality of the legacy OPC Classic together with a reliable and secure data exchange and operations across a range of operating systems, networks, and devices. It is based on the latest web service security standards and allows for seamless communication and interoperability between different IT systems and applications.
OPC UA is used in many industries and other domains to enable data exchange and operations, e.g. in industrial automation, manufacturing, healthcare, energy, transportation, and logistics applications. There, it is used e.g. to enable real-time monitoring and control of industrial processes, to facilitate communication with sensors and devices, and to enable batch and process optimization.
This repository contains sample programs for the realization of OPC UA clients and servers in the Python programming language. The programs were not designed with the goal of professional software development. Rather, they are intended to serve as extensible learning examples.
Using a Python virtual environment helps keep your Python projects organized and helps ensure that the right versions of packages are being used for the right projects. It also helps prevent conflicts between different versions of packages, as different projects as well as the system-wide Python installation can use different versions of a package without issue.
Thus, you should install a virtual environment in the repository folder, e.g. by using following command:
python -m venv venvYou need to activate the virtual environment before installing packages or running the code. In a UNIX-like system as Linux you need to call the following command:
./venv/bin/activateOn a Microsoft Windows system you probably use a Batch console window and there you would need to call the following command:
.\venv\Scripts\activate.batWe prepared a setup.py file, which contains dependencies from third-party libraries. They can be installed with the following command:
pip install .
If you want to extend the software, you should install the developer dependencies too:
pip install .[dev]
Click here for a list of dependencies.
A simple server/client data transmission example is provided. The client receives data generated by a server and thus, it uses the computing power of the server for generating the data. For running the two applications, please navigate to "./src/DAServerSimple/" and there run the commands python data_server.py and python data_client.py.
A further example describes the client access to server method. As an example a numeric multiply mthod is implemented. In order to run the two applications please navigate to "./src/MethodsServerSimple/" and there run the commands python method_server.py and python method_client.py.
Another example combines the functionalities of OPC UA and data visualization with Python and Jupyter Notebook. The example demonstrates how to provide the CPU, RAM and battery usage over OPC UA and how to gather and visualize the data in a Jupyter Notebook. The data is finally displayed in a chart using Matplotlib.
We integrated an example, which is running only on Microsoft Windows operating systems with an installed Microsoft Excel application. An OPC UA server provides data. The client application demonstrates, how Python is used to access the data from the server and to put it into an Excel spreadsheet. For running the two applications, please navigate to "./src/DAServerExcel/" and there run the commands python excel_server.py and python excel_client.py. The cells of the table are updated cyclically.
In order to establish basic security, we designed an example of communication using self-signed certificates. Therein, the client verifies the data received by the server by using a signature sent by the server along with the data. The self-signed certificate has been generated by using OpenSSL. For verification of certificates, we use the PyOpenSSL library.
- In the security example, we currently use a self-made approach for doing the work. We will provide an update soon, which secures the connection by use of the FreeOpcUa framework technology (see FreeOpcUa example).
- We want to integrate a launch.json file for those users who use Visual Studio Code. There we will configure start scripts for running the clients and servers. This may also simplify debugging of the software.