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
be6193cf
Commit
be6193cf
authored
Aug 01, 2023
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read previous state from ERP5 backend.
parent
a72e0f59
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
opcua-to-http-gw/opcua-to-http-gw.py
opcua-to-http-gw/opcua-to-http-gw.py
+16
-2
No files found.
opcua-to-http-gw/opcua-to-http-gw.py
View file @
be6193cf
...
@@ -40,9 +40,12 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
...
@@ -40,9 +40,12 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
if
self
.
url
is
not
None
:
if
self
.
url
is
not
None
:
return
f"%s/%s"
%
(
self
.
url
,
ERP5_REQUEST_API
)
return
f"%s/%s"
%
(
self
.
url
,
ERP5_REQUEST_API
)
def
call
(
self
,
**
data
):
def
call
(
self
,
http_method
=
"POST"
,
**
data
):
params
=
urllib
.
parse
.
quote_plus
(
json
.
dumps
({
k
:
str
(
v
)
for
k
,
v
in
data
.
items
()}))
params
=
urllib
.
parse
.
quote_plus
(
json
.
dumps
({
k
:
str
(
v
)
for
k
,
v
in
data
.
items
()}))
self
.
session
.
post
(
f"
{
self
.
uri
}
?data=
{
params
}
"
)
if
http_method
==
"POST"
:
self
.
session
.
post
(
f"
{
self
.
uri
}
?data=
{
params
}
"
)
elif
http_method
==
"GET"
:
return
self
.
session
.
get
(
f"
{
self
.
uri
}
"
)
def
datachange_notification
(
self
,
node
,
val
,
data
):
def
datachange_notification
(
self
,
node
,
val
,
data
):
self
.
call
(
node
=
node
,
val
=
val
,
data
=
data
)
self
.
call
(
node
=
node
,
val
=
val
,
data
=
data
)
...
@@ -72,6 +75,17 @@ async def main():
...
@@ -72,6 +75,17 @@ async def main():
if
xml
is
not
None
:
if
xml
is
not
None
:
await
server
.
import_xml
(
xml
)
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
)
for
k
,
v
in
erp5_json
.
items
():
# set
node
=
server
.
get_node
(
k
)
_logger
.
error
(
"Set %s = %s at %s"
%
(
k
,
v
,
node
))
# XXX: this leads to a change notification which calls ERP5 and endless loop!
#await node.write_value(v)
if
erp5_handler
:
if
erp5_handler
:
subscription
=
await
server
.
create_subscription
(
1000
,
erp5_handler
)
subscription
=
await
server
.
create_subscription
(
1000
,
erp5_handler
)
await
subscription
.
subscribe_events
()
await
subscription
.
subscribe_events
()
...
...
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