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
Martin Manchev
osie
Commits
616e95e1
Commit
616e95e1
authored
Aug 01, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set and get based on HTTP method.
parent
88339454
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
22 deletions
+31
-22
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
...em/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
+31
-22
No files found.
bt5/erp5_opcua/SkinTemplateItem/portal_skins/erp5_opcua/ERP5Site_handleOPCUARequest.py
View file @
616e95e1
"""
"""
Simple script for OPCUA POC
OPCUA to ERP5 OPCUA Document setter / getter glue script.
XXX:
- get rid of Proxy roles on this script when proper authentication is used!!!
- use username / password for opcua-http-gw
"""
"""
import
json
import
json
from
erp5.component.module.Log
import
log
from
erp5.component.module.Log
import
log
# XXX: get rid of Proxy roles on this script when proper authentication is used!!!
def
convertNodeValue
(
node_id
,
node_value
):
def
convertNodeValue
(
node_id
,
node_value
):
"""
"""
Based on node_id convert to proper Python type. Based on this format:
Based on node_id convert to proper Python type. Based on this format:
...
@@ -20,25 +23,31 @@ def convertNodeValue(node_id, node_value):
...
@@ -20,25 +23,31 @@ def convertNodeValue(node_id, node_value):
node_value
=
int
(
node_value
)
node_value
=
int
(
node_value
)
return
node_value
return
node_value
# XXX: what should be the OPCUA container?
# XXX: what should be the OPCUA container?
default_opcua_document
=
context
.
opcua_document_module
[
"1"
]
default_opcua_document
=
context
.
opcua_document_module
[
"1"
]
try
:
# do selection of oepration in a REST fashion based in HTTP method
data
=
context
.
REQUEST
.
data
http_method
=
context
.
REQUEST
.
method
except
AttributeError
:
context
.
log
(
http_method
)
log
(
"Warning: 'data' is missing from request."
)
else
:
if
http_method
==
"GET"
:
data
=
json
.
loads
(
data
)
# assume read request, return what was saved.
if
'node'
in
data
.
keys
():
return
default_opcua_document
.
getNodeDict
()
# log only set requests for now
elif
http_method
==
"POST"
:
node_id
=
data
[
'node'
]
# assume write request
node_value
=
data
[
'val'
]
try
:
log
(
"Set '%s' = '%s' to %s as %s"
%
(
node_id
,
node_value
,
default_opcua_document
,
node_id
))
data
=
context
.
REQUEST
.
data
#log(data)
except
AttributeError
:
# set to "ERP5 OPCUA Document"
log
(
"Warning: 'data' is missing from request."
)
node_dict
=
default_opcua_document
.
getNodeDict
()
else
:
log
(
"Original = %s"
%
node_dict
)
data
=
json
.
loads
(
data
)
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
if
'node'
in
data
.
keys
():
default_opcua_document
.
setNodeDict
(
node_dict
)
# log only set requests for now
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
node_id
=
data
[
'node'
]
node_value
=
data
[
'val'
]
log
(
"Set '%s' = '%s' to %s as %s"
%
(
node_id
,
node_value
,
default_opcua_document
,
node_id
))
# set to "ERP5 OPCUA Document"
node_dict
=
default_opcua_document
.
getNodeDict
()
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
default_opcua_document
.
setNodeDict
(
node_dict
)
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
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