Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
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
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
osie
Commits
2d48c8aa
Commit
2d48c8aa
authored
Aug 03, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify.
parent
86a59abf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
25 deletions
+21
-25
opcua-to-http-gw/opcua-to-http-gw.py
opcua-to-http-gw/opcua-to-http-gw.py
+21
-25
No files found.
opcua-to-http-gw/opcua-to-http-gw.py
View file @
2d48c8aa
...
...
@@ -14,9 +14,7 @@ import argparse
import
logging
import
__main__
# #################################
# Configure
# XXX: addn erp5_username and erp5_password!
# command line handling
parser
=
argparse
.
ArgumentParser
(
description
=
'Run OPCUA Server.'
)
a
=
parser
.
add_argument
a
(
'--ip'
,
help
=
'The IP address on which the OPCUA Server runs'
,
default
=
"127.0.0.1"
)
...
...
@@ -34,6 +32,7 @@ erp5_username = args.erp5_username
erp5_password
=
args
.
erp5_password
ERP5_REQUEST_API
=
"ERP5Site_handleOPCUARequest"
# ERP5 backend storage for OPCUA Document
@
dataclass
(
frozen
=
True
)
class
ERP5Handler
(
asyncua
.
common
.
subscription
.
SubHandler
):
url
:
str
...
...
@@ -58,16 +57,15 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
def
event_notification
(
self
,
event
):
self
.
call
(
event
=
event
)
erp5_handler
=
None
if
erp5_url
is
not
None
:
erp5_handler
=
ERP5Handler
(
erp5_url
)
# init main ERP5 storage
erp5_handler
=
ERP5Handler
(
erp5_url
)
class
InternalSession
(
asyncua
.
server
.
internal_session
.
InternalSession
):
class
InternalSession
(
asyncua
.
server
.
internal_session
.
InternalSession
):
async
def
read
(
self
,
params
):
erp5_handler
.
call
(
params
=
params
)
return
await
super
().
read
(
params
)
# #################################
# Start OPCUA Server
async
def
main
():
_logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -80,7 +78,6 @@ async def main():
if
xml
is
not
None
:
await
server
.
import_xml
(
xml
)
# read previous state as saved in ERP5 backend
erp5_json
=
erp5_handler
.
call
(
http_method
=
"GET"
).
json
()
_logger
.
error
(
erp5_json
)
...
...
@@ -91,7 +88,6 @@ async def main():
# XXX: this leads to a change notification which calls ERP5 and endless loop!
#await node.write_value(v)
if
erp5_handler
:
subscription
=
await
server
.
create_subscription
(
1000
,
erp5_handler
)
await
subscription
.
subscribe_events
()
nodes
=
await
asyncua
.
common
.
ua_utils
.
get_nodes_of_namespace
(
server
)
...
...
@@ -104,9 +100,9 @@ async def main():
return
InternalSession
(
self
,
self
.
aspace
,
self
.
subscription_service
,
name
,
user
=
user
,
external
=
external
)
server
.
iserver
.
create_session
=
create_session
_logger
.
info
(
"Added subscription for erp5 handler."
)
_logger
.
info
(
"Starting server!"
)
# start OPCUA server
_logger
.
info
(
"Starting server!"
)
async
with
server
:
while
True
:
await
asyncio
.
sleep
(
1
)
...
...
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