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?

  1. Setup an OPC UA server on a Raspberry Pi
  2. Setup an OPC UA client on a Linux PC
  3. 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.

OPC UA on RPI  

What will you learn?

  1. How to install the dependencies in Linux
  2. How to build an OPC UA server using open62541
  3. How to build an OPC UA client using FreeOpcUa
 

What will you need?

  1. One Raspberry Pi V3 or above running Raspbian Buster OS
  2. 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

  1. Download Raspbian Buster Desktop OS from this link
  2. Download and install the Etcher SD card burner utility following this link
  3. 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
cd open62541
mkdir build
cd build
cmake ..
ccmake ..
 

In the cmake configuration step, enable the UA_BUILD_EXAMPLES option, then configure(c) and generate(g) the makefile

make
cd bin/examples
./tutorial_server_firststeps
 

Your server is now running on the Raspberry Pi and will be listening in the 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.

opcua-client
 

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).

OPC UA Client Server Communication

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.

 

Interested to know more about OPC UA on different platforms?