How to run OPC UA server on RaspberryPi
New to OPC UA and Industry 4.0? Are you looking for a simple way to setup and play with an OPC UA demo to help you learn practically before diving deeper into the OPC UA specifications? All you need is a Raspberry Pi and a Linux PC to get started.
What will you do?
- Setup an OPC UA server on a Raspberry Pi
- Setup an OPC UA client on a Linux PC
- Use the client to connect and browse the information model of the server
The Raspberry Pi is to be used in place of an industrial PLC running an OPC UA server. The Linux PC is to be used in place of an industrial HMI running an OPC UA client and will be used to connect to the OPC UA server and browse its information model. In this example, the Linux PC will be connected to the Raspberry Pi through an Ethernet connection.
What will you learn?
- How to install the dependencies in Linux
- How to build an OPC UA server using open62541
- How to build an OPC UA client using FreeOpcUa
What will you need?
- One Raspberry Pi V3 or above running Raspbian Buster OS
- One Linux PC running Ubuntu 18.04 OS
Having only a Raspberry Pi or a Linux PC but not both? No problem, this demo can also be setup entirely using either just a Raspberry Pi or a Linux PC to run both the OPC UA server and client.
Set up the Raspberry Pi to run Raspbian Buster OS
- Download Raspbian Buster Desktop OS from this link
- Download and install the Etcher SD card burner utility following this link
- Follow the steps in this link to install the OS to the microSD card
Install the dependencies in Linux
Install the dependencies in Raspberry Pi and Linux PC
sudo apt-get install git cmake cmake-curses-gui build-essential gcc python3-pip qttools5-dev python3-pyqt5
libmbedtls-dev check libsubunit-dev python-sphinx graphviz python-sphinx-rtd-theme
sudo pip3 install opcua-client
Build and run OPC UA server using open62541
Run the following commands in Raspberry Pi
git clone https://github.com/open62541/open62541.git
In the cmake configuration step, enable the UA_BUILD_EXAMPLES option, then configure(c) and generate(g) the makefile
Your server is now running on the Raspberry Pi and will be listening in port 4840
Connect using FreeOpcUa client to OPC UA server
Whether you want to run the FreeOpcUa OPC UA client application on the Raspberry Pi or on the Linux PC, in both cases, you can use the same command to start it up from the terminal window.
If you are running the OPC UA client on the Raspberry Pi itself (instead of the Linux PC), then you should use the URL ‘opc.tcp://localhost:4840’ in the URL field (as shown in this screenshot) of the FreeOpcUa application and click on the ‘Connect’ button to connect to the open62541 OPC UA server (which is also running on the same Raspberry Pi).
Alternatively, if you are running the OPC UA client on the Linux PC, then you should use the URL ‘opc.tcp://IP-ADDRESS-OF-RASPBERRY-PI:4840’ in the URL field of the FreeOpcUa application to connect to the open62541 OPC UA server (which is running on the Raspberry Pi).
If the connection is established successfully, the highlighted display section in the FreeOpcUa client application lists the information model view of the OPC UA server that you can browse through.