OPC-UA Tutorial
You want to exchange data using the OPC-UA protocol and wonder if this is possible and how?
Well, you are right here!
This protocol is based on the client/server principle. An OPC server is a piece of software that is tailored to one or more PLC/machine manufacturers. For example, you have a server running on your Revolution Pi (PLC) to collect and send Data to a client. For this simple example, we have a server and a client. Our server is a Python program that generates data from a pressure and temperature sensor and the time of each change in value.
Instructions
Install OPC-UA
install UaExpert client
copy server.py into a directory on the target device and adapt it
Implementation
Install OPC-UA and some dependencies on your RevPi
#install library for OPC UA
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev libffi-dev
# install python package manager
sudo apt install python3-pip
#install cryptography
sudo pip3 install cryptography
#install free opc ua
sudo pip3 install freeopcua
#show if package is installed
pip3 show cryptography
pip3 show freeopcua
“sudo pip3 install freeopcua” : run this command to install OPC UA python package. This command can take a lot of time to install, like 20–30 minutes. After installation, you can verify it by running the “python3” command and by importing the module. If this gives an error, that means it has not been installed.
2. Download and install UaExpert client and configure it.
Here you must enter the Endpoint URL as shown in the video below.
Enter opc.tcp://<your revpi-Ipaddress>. For example, enter opc.tcp://192.168.1.xxx when your RevPi address is 192.168.1.xxx and select the authentication Settings (Username, Password) for security reasons.
3. copy server.py into a directory on the target device and adapt it
Here is the server.py file:
You can copy it to your RevPi device like soRevolution Pi Copy Files i.e., to /home/pi/
You must adapt the Endpoint URL on your Server running on your RevPi.
Application
run the server server.py
python3 server.py
connect the client to the server in UaExpert client. The Username and the Password of your Revolution Pi will be asked for security reason. You can also disable this setting in the properties of your server by choosing “the authentication settings” anonymous
You can monitor your sensor value coming from your server per drag and drop. Please watch the following video