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
1
Merge Requests
1
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
nexedi
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
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
):
"""
Based on node_id convert to proper Python type. Based on this format:
...
...
@@ -20,25 +23,31 @@ def convertNodeValue(node_id, node_value):
node_value
=
int
(
node_value
)
return
node_value
# XXX: what should be the OPCUA container?
default_opcua_document
=
context
.
opcua_document_module
[
"1"
]
try
:
data
=
context
.
REQUEST
.
data
except
AttributeError
:
log
(
"Warning: 'data' is missing from request."
)
else
:
data
=
json
.
loads
(
data
)
if
'node'
in
data
.
keys
():
# log only set requests for now
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
))
#log(data)
# set to "ERP5 OPCUA Document"
node_dict
=
default_opcua_document
.
getNodeDict
()
log
(
"Original = %s"
%
node_dict
)
node_dict
[
node_id
]
=
convertNodeValue
(
node_id
,
node_value
)
default_opcua_document
.
setNodeDict
(
node_dict
)
log
(
"Changed = %s"
%
default_opcua_document
.
getNodeDict
())
# do selection of oepration in a REST fashion based in HTTP method
http_method
=
context
.
REQUEST
.
method
context
.
log
(
http_method
)
if
http_method
==
"GET"
:
# assume read request, return what was saved.
return
default_opcua_document
.
getNodeDict
()
elif
http_method
==
"POST"
:
# assume write request
try
:
data
=
context
.
REQUEST
.
data
except
AttributeError
:
log
(
"Warning: 'data' is missing from request."
)
else
:
data
=
json
.
loads
(
data
)
if
'node'
in
data
.
keys
():
# log only set requests for now
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