Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-cloning
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yogesh.m
opcua-cloning
Commits
624a3d06
Commit
624a3d06
authored
Mar 14, 2023
by
yogesh.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
7fef5d5a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
31 deletions
+46
-31
hash_sender.py
hash_sender.py
+7
-12
opc_ua_receiver_config.yaml
opc_ua_receiver_config.yaml
+7
-0
opc_ua_transmitter_config.yaml
opc_ua_transmitter_config.yaml
+7
-0
opcua-transmitter.py
opcua-transmitter.py
+16
-12
opcua_receiver.py
opcua_receiver.py
+9
-7
No files found.
hash_sender.py
View file @
624a3d06
...
...
@@ -5,15 +5,6 @@ from time import sleep
import
pickle
import
json
ENDPOINT
=
'opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer'
NAMESPACE
=
'http://www.prosysopc.com/OPCUA/SimulationNodes/'
msgFromClient
=
"Hello UDP Server"
bytesToSend
=
str
.
encode
(
msgFromClient
)
serverAddressPort
=
(
"2.2.2.5"
,
20002
)
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
nm_no
=
None
async
def
create_node_hierarchy
(
client
,
node_objects
):
...
...
@@ -44,8 +35,11 @@ async def create_node_hierarchy(client, node_objects):
node_hierarchy
[
identifier_name
][
"datatype"
]
=
datatype
.
_value_
return
node_hierarchy
async
def
get_send_hash
():
async
def
get_send_hash
(
ENDPOINT
,
NAMESPACE
,
server_hash_udp_ip
,
server_hash_udp_port
):
global
nm_no
serverAddressPort
=
(
server_hash_udp_ip
,
server_hash_udp_port
)
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
async
with
Client
(
url
=
ENDPOINT
)
as
client
:
nm_no
=
await
client
.
get_namespace_index
(
NAMESPACE
)
root_node
=
client
.
get_root_node
()
...
...
@@ -55,9 +49,10 @@ async def get_send_hash():
node_objects_children
=
await
node_objects
.
get_children
()
# replace with your own node id
node_hierarchy
=
await
create_node_hierarchy
(
client
,
node_objects_children
)
node_hierarchy
[
"hash"
]
=
hash
(
str
(
node_hierarchy
))
node_hierarchy
[
"namespace_idx"
]
=
nm_no
json_hierarchy
=
json
.
dumps
(
node_hierarchy
)
hierarchy
=
pickle
.
dumps
(
json_hierarchy
)
UDPClientSocket
.
sendto
(
hierarchy
,
serverAddressPort
)
def
send_hash
():
asyncio
.
run
(
get_send_hash
())
\ No newline at end of file
def
send_hash
(
Endpoint
,
Namespace
,
server_hash_udp_ip
,
server_hash_udp_port
):
asyncio
.
run
(
get_send_hash
(
Endpoint
,
Namespace
,
server_hash_udp_ip
,
server_hash_udp_port
))
\ No newline at end of file
opc_ua_receiver_config.yaml
0 → 100644
View file @
624a3d06
Configuration
:
endpoint_url = "opc.tcp://2.2.2.5:53531/myopc/free"
namespace_server ="http://klopc.com"
udp_hash_receiver_ip="2.2.2.5"
udp_hash_receiver_port=20002
udp_ip = "2.2.2.5"
udp_port = 20001
\ No newline at end of file
opc_ua_transmitter_config.yaml
0 → 100644
View file @
624a3d06
configuration
:
server_hash_udp_ip
:
"
2.2.2.5"
server_hash_udp_port
:
20002
server_udp_ip
:
2.2.2.5
server_udp_port
:
20001
endpoint
:
opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer
namespace
:
http://www.prosysopc.com/OPCUA/SimulationNodes/
\ No newline at end of file
opcua-transmitter.py
View file @
624a3d06
...
...
@@ -4,15 +4,21 @@ import threading
import
hash_sender
from
asyncua
import
Client
,
Node
from
asyncua.common.subscription
import
DataChangeNotif
,
SubHandler
import
yaml
yamlfile
=
open
(
"opc_ua_transmitter_config.yaml"
)
data
=
yaml
.
load
(
yamlfile
,
Loader
=
yaml
.
FullLoader
)
server_hash_udp_ip
=
data
[
"configuration"
][
"server_hash_udp_ip"
]
server_hash_udp_port
=
data
[
"configuration"
][
"server_hash_udp_port"
]
server_udp_ip
=
data
[
"configuration"
][
"server_udp_ip"
]
server_udp_port
=
int
(
data
[
"configuration"
][
"server_udp_port"
])
serverAddressPort
=
(
server_udp_ip
,
server_udp_port
)
ENDPOINT
=
data
[
"configuration"
][
"endpoint"
]
NAMESPACE
=
data
[
"configuration"
][
"namespace"
]
msgFromClient
=
"Hello UDP Server"
bytesToSend
=
str
.
encode
(
msgFromClient
)
serverAddressPort
=
(
"2.2.2.5"
,
20001
)
bufferSize
=
1024
UDPClientSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
ENDPOINT
=
'opc.tcp://2.2.2.7:53530/OPCUA/SimulationServer'
NAMESPACE
=
'http://www.prosysopc.com/OPCUA/SimulationServer/'
nm_no
=
None
class
MyHandler
(
SubHandler
):
def
__init__
(
self
):
...
...
@@ -37,7 +43,7 @@ class MyHandler(SubHandler):
variables
=
[]
async
def
get_nodes
(
client
,
node_objects
):
for
sub_obj
in
node_objects
:
if
(
"ns=
3
;"
in
str
(
sub_obj
)):
if
(
"ns=
"
+
nm_no
+
"
;"
in
str
(
sub_obj
)):
node
=
client
.
get_node
(
sub_obj
)
children_nodes
=
await
node
.
get_children
()
identifier
=
str
(
children_nodes
[
0
]
.
nodeid
.
Identifier
)
if
children_nodes
else
""
...
...
@@ -53,19 +59,17 @@ async def get_nodes(client,node_objects):
async
def
main
()
->
None
:
global
nm_no
async
with
Client
(
url
=
ENDPOINT
)
as
client
:
# Get a variable node.
nm_no
=
str
(
await
client
.
get_namespace_index
(
NAMESPACE
))
object_root_node
=
client
.
get_objects_node
()
objects
=
await
object_root_node
.
get_children
()
node
=
await
get_nodes
(
client
,
objects
)
# Subscribe data change.
t1
=
threading
.
Thread
(
target
=
hash_sender
.
send_hash
)
t1
=
threading
.
Thread
(
target
=
hash_sender
.
send_hash
,
args
=
(
ENDPOINT
,
NAMESPACE
,
server_hash_udp_ip
,
server_hash_udp_port
,))
t1
.
start
()
handler
=
MyHandler
()
subscription
=
await
client
.
create_subscription
(
period
=
0
,
handler
=
handler
)
await
subscription
.
subscribe_data_change
(
node
)
# Process data change every 100ms
while
True
:
await
handler
.
process
()
await
asyncio
.
sleep
(
0.01
)
...
...
opcua_receiver.py
View file @
624a3d06
...
...
@@ -3,16 +3,18 @@ from time import sleep
from
opcua_subscriber.opcua_subscribe
import
opcua_pack
from
asyncua_server
import
st
import
threading
Endpoint_Url
=
"opc.tcp://2.2.2.5:53531/myopc/free"
Namespace_Server
=
"http://klopc.com"
import
yaml
udp_hash_receiver_ip
=
"2.2.2.5"
udp_hash_receiver_port
=
20002
yamlfile
=
open
(
"opc_ua_transmitter_config.yaml"
)
data
=
yaml
.
load
(
yamlfile
,
Loader
=
yaml
.
FullLoader
)
Endpoint_Url
=
data
[
"configuration"
][
"endpoint_url"
]
Namespace_Server
=
data
[
"configuration"
][
"namespace_server"
]
udp_hash_receiver_ip
=
data
[
"configuration"
][
"udp_hash_receiver_ip"
]
udp_hash_receiver_port
=
data
[
"configuration"
][
"udp_hash_receiver_port"
]
localIP
=
data
[
"configuration"
][
"udp_ip"
]
localPort
=
data
[
"configuration"
][
"udp_port"
]
localIP
=
"2.2.2.5"
localPort
=
20001
bufferSize
=
1024
UDPServerSocket
=
socket
.
socket
(
family
=
socket
.
AF_INET
,
type
=
socket
.
SOCK_DGRAM
)
UDPServerSocket
.
bind
((
localIP
,
localPort
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment