Commit 616e95e1 authored by Ivan Tyagov's avatar Ivan Tyagov

Set and get based on HTTP method.

parent 88339454
"""
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:
# 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:
except AttributeError:
log("Warning: 'data' is missing from request.")
else:
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())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment