• Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
Brighter Side Tech
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming
No Result
View All Result
Brighter Side Tech
No Result
View All Result
Home Python

OPC UA Sever in Python

Mwesigwa Peter by Mwesigwa Peter
May 23, 2023
in Python
0
OPC UA Sever in Python

OPC UA Sever in Python

0
SHARES
603
VIEWS
Share on FacebookShare on Twitter

The OPC UA protocol is a widely used protocol in Industrial Applications. Lately, many devices vendors have started including the protocol suite an support in their devices due to its popularity. Many PLC’s today are OPC UA enabled and it takes just a few steps to configure a server on a device.

However, sometimes you need to build your own custom OPC UA Server, say on an embedded board or on a system that does not have the protocol suite already enabled. In this demonstration therefore, we are going to see how to create an OPC UA server in python.

Step 1: Set up your OPC UA Client

OPC UA protocol is a Server – Client communication protocol. The Server hosts the nodes or some times known as tag variables and the client can access and manipulate the nodes depending on the read-write permillages set for each node. So to test our OPC UA server, we will need to have an OPC UA Client Ready. You can use a simulation OPC UA client or opt for a client implemented in python. Instructions on how to set up the two options can be seen here below.

Step 1.1: Simulation OPC UA Client

Step1.2: OPC UA Client implemented in Python

Step 2: Implementing the OPC UA Server

In this demonstration, the OPC UA server is implemented as a single python script and follows the following steps

Import the required packages

from time import sleep
import random
from opcua import Server

Create the server object and set the server endpoint

# create server
server = Server()

# create server endpoint
url = "opc.tcp://0.0.0.0:4840/opcua/server"
server.set_endpoint(url)

Register the server namespace

# create namespace
name = "OPCUA_SERVER"
idx = server.register_namespace(name)

Get the Objects Node, add an object to the Node and add a variable to the object

# get server objects node
objects = server.get_objects_node()

# add objects {namespace, object name}
param = objects.add_object(idx, "Parameters")

# add and initialise a variable to a specific object
temp = param.add_variable(idx, "Temperature", 0)

set read write privileges

# set read write privileges for a variable
temp.set_writable()

Start your server

# start server
server.start()

Update your variable however and whenever you want


temp.set_value(new_value)

Full Code

You can get the full code from github: brightersidetech/opcua_server_python

Tags: opcuapython
Previous Post

OPC UA Client In Python

Next Post

OPC UA Client Implementation In Python Using Server Subscription

Mwesigwa Peter

Mwesigwa Peter

Related Posts

Modbus TCP Master Simulator
Automation

Modbus TCP Master Simulator Tool – Free Download

The Modbus TCP Master Simulator Tool has been implemented in using QT for python and can be used to Simulate...

by Mwesigwa Peter
October 14, 2023
OPC UA Implementation In Python Using Server Subscription
Automation

OPC UA Client Implementation In Python Using Server Subscription

The OPC UA client Subscription method allow the client to subscribe to nodes of interest on the server and receives...

by Mwesigwa Peter
August 15, 2023
Next Post
OPC UA Implementation In Python Using Server Subscription

OPC UA Client Implementation In Python Using Server Subscription

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Parsing JSON Data in Codesys
Automation

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Read moreDetails
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

January 11, 2024
Modbus TCP Master Simulator

Modbus TCP Master Simulator Tool – Free Download

October 14, 2023
Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

by Mwesigwa Peter
January 25, 2025
0

Parsing JSON Data in Codesys is quite an important operation especially when exchanging data over the REST API. The data...

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

by Mwesigwa Peter
October 7, 2024
0

Introduction Codesys Runtime for Linux ARM SL allows you to program your Raspberry Pi according t the IEC 61131-6 standard...

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

by Mwesigwa Peter
July 18, 2024
0

This is how to solve the error: no member named 'IP' in 'NVIC_Type' Open the misc.c file : AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.4.1\Device\StdPeriph_Driver\src\misc.c, if you are...

TCP Socket Client Implementation in Codesys

TCP Socket Client Implementation in Codesys

by Mwesigwa Peter
January 11, 2024
0

This is a TCP socket client implementation in codesys to run on your PLC and connect to any TCP Socket...

About Brighterside Tech

Brighter Side Tech

As a hobbyist Engineer and Programmer , i love to share my learnings and solutions to technical challenges that i face during work and studying. My website gives me the ability to express my ideas and such solutions to the wider audience

Contact: admin@brightersidetech.com

Browse by Category

  • Automation
  • Codesys eCockpit
  • Docker
  • Embedded Programming
  • Python
  • Raspberry Pi
https://youtu.be/Lkrma5f60rs

Recent News

Parsing JSON Data in Codesys

Parsing JSON Data in Codesys

January 25, 2025
Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

Configure Raspberry Pi Serial ports as COM ports for Codesys Runtime

October 7, 2024
ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

ARM error: no member named ‘IP’ in ‘NVIC_Type’ Solved

July 18, 2024
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.

No Result
View All Result
  • Home
  • Raspberry Pi
  • Codesys eCockpit
  • Python
  • Docker
  • Embedded Programming

© 2024 Brighterside Tech.